"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",
}],
例如,用户点击“未来”'该应用程序以
的形式向用户发送消息Postback received: {"payload":"Chatbots are fun! One day your BFF might be a Chatbot"}
如何更改它以便它只是以消息形式发送它?
答案 0 :(得分:0)
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")
}
}