Exemplo n.º 1
0
    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_message_set_new_message(self):
     api_key = '1234'
     platform = '1'
     message = '2'
     intent = '3'
     version = '4'
     user_id = '5'
     time_stamp = int(round(time.time() * 1e3))
     message_set = MessageSet(api_key=api_key,
                              platform=platform,
                              version=version,
                              user_id=user_id)
     msg1 = message_set.new_message(intent=intent,
                                    message=message,
                                    type=MessageTypes.USER,
                                    not_handled=True,
                                    time_stamp=time_stamp)
     msg1.set_as_feedback()
     msg2 = message_set.new_message(message=message,
                                    type=MessageTypes.AGENT)
     self.assertEqual(
         json.loads(msg1.to_json()),
         {
             'api_key': api_key,
             'platform': platform,
             'message': message,
             'intent': intent,
             'version': version,
             'user_id': user_id,
             'time_stamp': time_stamp,
             'type':
             MessageTypes.USER,  # since we did not set as type agent
             'not_handled': True,
             'feedback': True
         })
     self.assertEqual(
         json.loads(msg2.to_json()),
         {
             'api_key': api_key,
             'platform': platform,
             'message': message,
             'intent': msg2.intent,
             'version': version,
             'user_id': user_id,
             'time_stamp': msg2.time_stamp,
             'type':
             MessageTypes.AGENT,  # since we did not set as type agent
             'not_handled': False,
             'feedback': False
         })
Exemplo n.º 3
0
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 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)
Exemplo n.º 5
0
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