def processChatbase(req, res): result = req.get("queryResult") intentname = result.get("intent") #message de base ##à modifier: 'api_key = ''' changer l'API key set = MessageSet(api_key='56bd0b2b-4b67-4522-8933-1ff443a8a922', platform='Dialogflow', version="0.1", user_id=req.get("session")) #not_handled integration if result.get("action") == "input.unknown": msg = set.new_message(intent=intentname.get("displayName"), message=result.get("queryText"), not_handled=True) #handled else: msg = set.new_message(intent=intentname.get("displayName"), message=result.get("queryText")) msg2 = Message( api_key='56bd0b2b-4b67-4522-8933-1ff443a8a922', platform='Dialogflow', version="0.1", user_id=req.get("session"), #message intent=intentname.get("displayName"), type=MessageTypes.AGENT) set.append_message(msg2) # #message envoyé a chatbase resp = set.send() return None
def publish(self,userQuery,botResponse,not_handled,userId,intent): time_stamp = int(round(time.time() * 1e3)) # Mandatory # Create an instance of MessageSet to collect all the messages message_set = MessageSet(api_key=str(self.api_key), platform=self.platform, version=self.version, user_id=userId) # Create an instance of Message for the user message and set values in the constructor msg1 = Message(api_key=self.api_key, platform=self.platform, message=userQuery, intent=intent, version=self.version, user_id=userId, type=MessageTypes.USER, not_handled=not_handled, time_stamp=time_stamp) # msg1.set_as_feedback() # Create an instance of Message for the bot response message and set values in the constructor msg2 = Message(api_key=self.api_key, platform=self.platform, message=botResponse, version=self.version, user_id=userId, type=MessageTypes.AGENT) # Push messages into the collection (MessageSet) message_set.append_message(msg1) message_set.append_message(msg2) # Send the messages response = message_set.send() print('Response code for sending Chatbase Message', response.content) # response.status_code will be 200 if sending worked
def test_live_set_send(self): test_api_key = os.environ.get('CB_TEST_API_KEY') if test_api_key is None: print( "Warning: Skipping live integration test without test API key." ) return s = MessageSet(api_key=test_api_key, platform="python-lib-test", version="0.1", user_id="12345") i = s.new_message() i.message = "msg-1" i.intent = "int-1" i = s.new_message() i.message = "msg-2" i.intent = "int-2" resp = s.send() self.assertEqual(resp.status_code, 200)
def processChatbase(req, res): result = req.get("result") metadata = result.get("metadata") fulfillment = result.get("fulfillment") status = req.get("status") #message de base set = MessageSet(api_key='56bd0b2b-4b67-4522-8933-1ff443a8a922', platform='Dialogflow', version="0.1", user_id=req.get("sessionId")) #not_handled integration if result.get( "action") == "input.unknown" or fulfillment.get("speech") != "": msg = set.new_message(intent=metadata.get("intentName"), message=result.get("resolvedQuery"), not_handled=True) #handled else: msg = set.new_message(intent=metadata.get("intentName"), message=result.get("resolvedQuery")) msg2 = Message( api_key='56bd0b2b-4b67-4522-8933-1ff443a8a922', platform='Dialogflow', version="0.1", user_id=req.get("sessionId"), #message intent=metadata.get("intentName"), type=MessageTypes.AGENT) set.append_message(msg2) #message envoyé a chatbase resp = set.send() return None