我试图记录用户发送到Webhook上的Messenger bot的所有用户。通过对Facebook开发者页面的一些研究,我发现我们需要为此使用handle_echo。
但是问题是它只返回某些输入的响应,这些输入是像Hi,Bye,Ok这样的小话题。
我如何记录所有内容,而不论有意义的单词或含糊不清的句子?
这是我的烧瓶代码:
import urllib
import json
import os
import dialogflow
import pandas as pd
from flask import Flask
from flask import request
from flask import make_response
import json
import requests
import re
from fbmq import Page
from pymessenger.bot import Bot
page = Page("pagecredentials")
app = Flask(__name__)
app.config["DEBUG"] = True
@app.route('/webhook', methods=['POST'])
def webhook():
page.handle_echo(request.get_data(as_text=True))
print('this is it,.{}',request.get_json(silent=True, force=True))
return "200 ok"
# @page.handle_message
# def message_handler(event):
# """:type event: fbmq.Event"""
# sender_id = event.sender_id
# message = event.is_echo
# print(message)
@page.handle_echo
def message_handler(event):
""":type event: fbmq.Event"""
sender_id = event.sender_id
message = event.message_text
print(message)
return json.dumps(message)
@page.after_send
def after_send(payload, response):
""":type payload: fbmq.Payload"""
print("complete")
if __name__ == '__main__':
os.putenv('FLASK_ENV', 'development')
port = int(os.getenv('PORT', 5000))
app.run()