我在Python和API方面都是初学者,我试图使用简单的文本响应创建一个使用Python的聊天机器人,问题是我试图使用FB文档,但它使用cURL和PHP"我认为"
所以如何使用文档代码为例: https://developers.facebook.com/docs/messenger-platform/reference/template/button
此链接中的代码适合我在Python中的代码
这是我已经运作的简单回复的一个例子
if data['object'] == 'page':
for entry in data['entry']:
for messaging_event in entry['messaging']:
# IDs
sender_id = messaging_event['sender']['id']
recipient_id = messaging_event['recipient']['id']
if messaging_event.get('message'):
# Extracting text message
if 'text' in messaging_event['message']:
messaging_text = messaging_event['message']['text']
else:
messaging_text = 'no text'
# Echo
response = None
entity, value = wit_reponse(messaging_text)
if entity == 'schedule':
response = "Ok I will send you {} news".format(str(value))
elif entity == "location":
response = "Ok so you live in {0}. I will send you top headlines from {0}".format(str(value))
if response == None:
response = "You know that I'm a bot at the end,I didn't understand :("
bot.send_text_message(sender_id, response)