如何让 Facebook Messenger Bot 在按钮单击时发送消息
How to have Facebook Messenger Bot send a message on button click
"type": "postback",
"title": "What can Chatbots do",
"payload": "One day Chatbots will control the Internet of Things! You will be able to control your homes temperature with a text",
}, {
"type": "postback",
"title": "The Future",
"payload": "Chatbots are fun! One day your BFF might be a Chatbot",
}],
例如,当用户点击 'The Future' 时,应用会以
的形式向用户发送消息
Postback received: {"payload":"Chatbots are fun! One day your BFF might be a Chatbot"}
我怎样才能改变它,让它以消息的形式发送?
Payload 仅供您参考,当用户单击按钮时,您会在 webhook 中收到有效负载。然后你可以发回你想要的任何消息。
例如,您可以将按钮设置为:
[{"type": "postback",
"title": "What can Chatbots do",
"payload": "payload_1",
},
{
"type": "postback",
"title": "The Future",
"payload": "payload_2",
}]
并且在您的 webhook 中,您可以使用以下方式发回消息:
if (event.postback) {
var text = JSON.stringify(event.postback.payload)
if(text === "\"payload_1\""){
sendTextMessage(sender, "One day Chatbots will control the Internet of Things! You will be able to control your homes temperature with a text")
}
else if (text === "\"payload_2\""){
sendTextMessage(sender, "Chatbots are fun! One day your BFF might be a Chatbot")
}
}
"type": "postback",
"title": "What can Chatbots do",
"payload": "One day Chatbots will control the Internet of Things! You will be able to control your homes temperature with a text",
}, {
"type": "postback",
"title": "The Future",
"payload": "Chatbots are fun! One day your BFF might be a Chatbot",
}],
例如,当用户点击 'The Future' 时,应用会以
的形式向用户发送消息Postback received: {"payload":"Chatbots are fun! One day your BFF might be a Chatbot"}
我怎样才能改变它,让它以消息的形式发送?
Payload 仅供您参考,当用户单击按钮时,您会在 webhook 中收到有效负载。然后你可以发回你想要的任何消息。 例如,您可以将按钮设置为:
[{"type": "postback",
"title": "What can Chatbots do",
"payload": "payload_1",
},
{
"type": "postback",
"title": "The Future",
"payload": "payload_2",
}]
并且在您的 webhook 中,您可以使用以下方式发回消息:
if (event.postback) {
var text = JSON.stringify(event.postback.payload)
if(text === "\"payload_1\""){
sendTextMessage(sender, "One day Chatbots will control the Internet of Things! You will be able to control your homes temperature with a text")
}
else if (text === "\"payload_2\""){
sendTextMessage(sender, "Chatbots are fun! One day your BFF might be a Chatbot")
}
}