Python 如何发送JSON负载以使用pymessenger Facebook聊天机器人创建按钮
我正在用Python 如何发送JSON负载以使用pymessenger Facebook聊天机器人创建按钮,python,json,python-3.x,chatbot,facebook-messenger-bot,Python,Json,Python 3.x,Chatbot,Facebook Messenger Bot,我正在用pymessenger、flask和wit.at创建一个Facebook messenger聊天机器人。我想在聊天机器人对话中添加按钮作为选项 比如说 "I think instead of bot.send_text_message, the correct way to send the JSON payload is via bot.send_raw. So using the example from your link you can test if it's working
pymessenger
、flask
和wit.at
创建一个Facebook messenger聊天机器人。我想在聊天机器人对话中添加按钮作为选项
比如说
"I think instead of bot.send_text_message
, the correct way to send the JSON payload is via bot.send_raw
. So using the example from your link you can test if it's working with something similar to:
payload = """{
"recipient":{
"id":"<PSID>"
},
"message":{
"attachment":{
"type":"template",
"payload":{
"template_type":"button",
"text":"What do you want to do next?",
"buttons":[
{
"type":"web_url",
"url":"https://www.example1.com",
"title":"Visit Example 1"
},
{
"type":"web_url",
"url":"https://www.example2.com",
"title":"Visit Example 2"
}
]
}
}
}
}"""
bot.send_raw(payload)
“我认为发送JSON有效负载的正确方法不是bot.send_text_message
,而是通过。因此,使用来自的示例可以测试它是否与以下类似的东西一起工作:
payload=”“”{
“收件人”:{
“id”:”
},
“信息”:{
“附件”:{
“类型”:“模板”,
“有效载荷”:{
“模板类型”:“按钮”,
“文本”:“下一步要做什么?”,
“按钮”:[
{
“类型”:“web_url”,
“url”:”https://www.example1.com",
“标题”:“访问示例1”
},
{
“类型”:“web_url”,
“url”:”https://www.example2.com",
“标题”:“访问示例2”
}
]
}
}
}
}"""
bot.send_raw(有效负载)
不要忘记替换
@Jayjayyy:例如:“Hey@Jayjayyy:added.)@Jayjayyy:您能帮忙吗。但是我需要添加什么来传递代码中带有有效负载的条目:if messaging\u event.get('message'):if messaging\u event['message']:messaging\u text=messaging\u event['message']['text']其他:消息传递\文本=‘无文本’响应=无