コード例 #1
0
ファイル: jarvis.py プロジェクト: grishabh96/Minorproject
def webhook():
    if request.method == 'POST':
        data = request.get_json(force=True)
        messaging_events = data['entry'][0]['messaging']
        for event in messaging_events:
            sender = event['sender']['id']
            message = None
            if 'message' in event and 'text' in event['message']:
                if 'quick_reply' in event['message'] and 'payload' in event[
                        'message']['quick_reply']:
                    quick_reply_payload = event['message']['quick_reply'][
                        'payload']
                    message = modules.ans(quick_reply_payload)

                else:
                    text = event['message']['text']
                    message = modules.ans(text, sender=sender)

            if 'postback' in event and 'payload' in event['postback']:
                postback = event['postback']['payload']
                id = event['postback']['payload'].split('!')[1]
                if postback == "Get Reviews":
                    review_list = modules.get_reviews(id)
                    for review in review_list:
                        message = review
                elif postback == "Get Directions":
                    message = modules.get_directions(id)

                elif postback == "visit":
                    message = modules.ans(id)

            if message is not None:
                payload = {'recipient': {'id': sender}, 'message': message}
                r = requests.post(
                    'https://graph.facebook.com/v2.6/me/messages',
                    params={'access_token': ACCESS_TOKEN},
                    json=payload)
            return '200 OK'  # 200 OK
    elif request.method == 'GET':  # Verification
        if request.args.get('hub.verify_token') == VERIFY_TOKEN:
            return request.args.get('hub.challenge'), 200
        else:
            return 'Error, wrong validation token', 200
コード例 #2
0
def search():
    inp = request.args.get('q')
    x = inp.split(' ')
    if x[0] == 'mail':
        sys.modules['modules.src.' + 'mail'].process(x[1], inp)
        return json.dumps(TextTemplate('SENT MAIL').get_message())
    elif x[0] == 'solve':
        k = sys.modules['modules.src.' + 'solve'].process(x[1])
        return json.dumps(TextTemplate(k).get_message())
    else:
        return json.dumps(modules.ans(request.args.get('q')))
コード例 #3
0
def search():
    return json.dumps(modules.ans(request.args.get('q')))
コード例 #4
0
def process():
    return json.dumps(modules.ans(request.args.get('q')))
コード例 #5
0
def webhook():
    if request.method == 'POST':
        data = request.get_json(force=True)
        messaging_events = data['entry'][0]['messaging']
        for event in messaging_events:
            sender = event['sender']['id']
            message = None
            if 'message' in event and 'text' in event['message']:
                if 'quick_reply' in event['message'] and 'payload' in event[
                        'message']['quick_reply']:
                    quick_reply_payload = event['message']['quick_reply'][
                        'payload']
                    x = quick_reply_payload.split(' ')
                    if x[0] == 'mail':
                        sys.modules['modules.src.' + 'mail'].process(x[1], inp)
                        message = TextTemplate('SENT MAIL').get_message()
                    elif x[0] == 'solve':
                        k = sys.modules['modules.src.' + 'solve'].process(x[1])
                        message = TextTemplate(k).get_message()
                    else:
                        message = modules.ans(quick_reply_payload)

                else:
                    text = event['message']['text']
                    x = text.split(' ')
                    if x[0] == 'mail':
                        sys.modules['modules.src.' + 'mail'].process(x[1], inp)
                        message = TextTemplate('SENT MAIL').get_message()
                    elif x[0] == 'solve':
                        k = sys.modules['modules.src.' + 'solve'].process(x[1])
                        message = TextTemplate(k).get_message()
                    else:
                        message = modules.ans(quick_reply_payload,
                                              sender=sender)

            if 'postback' in event and 'payload' in event['postback']:
                postback_payload = event['postback']['payload']
                x = postback_payload.split(' ')
                if x[0] == 'mail':
                    sys.modules['modules.src.' + 'mail'].process(x[1], inp)
                    message = TextTemplate('SENT MAIL').get_message()
                elif x[0] == 'solve':
                    k = sys.modules['modules.src.' + 'solve'].process(x[1])
                    message = TextTemplate(k).get_message()
                else:
                    message = modules.ans(postback_payload,
                                          sender=sender,
                                          postback=True)

            if message is not None:
                payload = {'recipient': {'id': sender}, 'message': message}
                r = requests.post(
                    'https://graph.facebook.com/v2.6/me/messages',
                    params={'access_token': ACCESS_TOKEN},
                    json=payload)
            return '200 OK'  # 200 OK
    elif request.method == 'GET':  # Verification
        if request.args.get('hub.verify_token') == VERIFY_TOKEN:
            return request.args.get('hub.challenge')
        else:
            return 'Error, wrong validation token'