Beispiel #1
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_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
         })
 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)
Beispiel #4
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