示例#1
0
 def parse_message(msg, num_tries=1):
     # intent = msg['inputs']['intent']
     # if intent == "assistant.intent.action.MAIN":
     #     intent = 'default'
     text = msg['inputs'][0]['rawInputs'][0]['query']
     parsed = parse_text_message(text)
     return parsed
示例#2
0
    def parse_message(raw_message, num_tries=1):
        print(raw_message)
        db = get_redis()
        if 'callback_query' in raw_message:
            key = json.loads(raw_message['callback_query']['data'],
                             object_hook=json_deserialize)
            if not db.exists(key):
                return {'entities': None, 'type': 'postback'}
            payload = json.loads(db.get(key).decode(encoding='UTF-8'))
            print("PAYLOAD", payload)
            payload['_message_text'] = [{'value': None}]
            return {'entities': payload, 'type': 'postback'}
        elif 'message' in raw_message:
            if 'sticker_id' in raw_message['message']:
                return TelegramInterface.parse_sticker(
                    raw_message['message']['sticker_id'])
            if 'attachments' in raw_message['message']:
                attachments = raw_message['message']['attachments']
                return TelegramInterface.parse_attachments(attachments)
            if 'quick_reply' in raw_message['message']:
                payload = json.loads(
                    raw_message['message']['quick_reply'].get('payload'),
                    object_hook=json_deserialize)
                if payload:
                    payload['_message_text'] = [{
                        'value':
                        raw_message['message']['text']
                    }]
                    return {'entities': payload, 'type': 'postback'}
            if 'text' in raw_message['message']:
                return parse_text_message(raw_message['message']['text'])

        return {'type': 'undefined'}
示例#3
0
 def parse_message(raw_message, num_tries=1):
     if 'postback' in raw_message:
         payload = json.loads(raw_message['postback']['payload'],
                              object_hook=json_deserialize)
         payload['_message_text'] = [{'value': None}]
         return {'entities': payload, 'type': 'postback'}
     elif 'message' in raw_message:
         if 'sticker_id' in raw_message['message']:
             return FacebookInterface.parse_sticker(
                 raw_message['message']['sticker_id'])
         if 'attachments' in raw_message['message']:
             attachments = raw_message['message']['attachments']
             return FacebookInterface.parse_attachments(attachments)
         if 'quick_reply' in raw_message['message']:
             payload = json.loads(
                 raw_message['message']['quick_reply'].get('payload'),
                 object_hook=json_deserialize)
             if payload:
                 payload['_message_text'] = [{
                     'value':
                     raw_message['message']['text']
                 }]
                 return {'entities': payload, 'type': 'postback'}
         if 'text' in raw_message['message']:
             return parse_text_message(raw_message['message']['text'])
     return {'type': 'undefined'}
示例#4
0
 def parse_message(raw, num_tries=1):
     if 'text' in raw:
         return parse_text_message(raw['text'])
     elif 'value' in raw:
         payload = raw['value']
         payload['_message_text'] = [{'value': None}]
         return {'entities': payload, 'type': 'postback'}
     return {'type': 'undefined'}
示例#5
0
 def parse_message(raw, num_tries=1):
     if 'message' in raw and 'text' in raw['message']:
         return parse_text_message(raw['message']['text'])
     elif 'callback_query' in raw:
         callback_query = raw['callback_query']
         data = TelegramInterface.retrieve_callback(callback_query.get('data'))
         if data:
             payload = json.loads(data)
             payload['_message_text'] = [{'value': None}]
             return {'entities': payload, 'type': 'postback'}
     return {'type': 'undefined'}
示例#6
0
 def parse_message(user_message, num_tries=1):
     logging.info('[WEBGUI] @ parse_message')
     if user_message.get('text'):
         return parse_text_message(user_message.get('text'))
     elif user_message.get("payload"):
         # data = json.loads(user_message["payload"])
         data = user_message['payload']
         # data = json.loads(b64decode(user_message["payload"]).decode())
         logging.info("Payload is: {}".format(data))
         if isinstance(data, dict):
             return {'entities': data, 'type': 'postback'}
         else:
             from golem.core.serialize import json_deserialize
             payload = json.loads(data, object_hook=json_deserialize)
             payload['_message_text'] = [{'value': None}]
             return {'entities': payload, 'type': 'postback'}