【问题标题】:How to have Facebook Messenger Bot send a message on button click如何让 Facebook Messenger Bot 在按钮单击时发送消息
【发布时间】:2018-04-07 10:23:10
【问题描述】:
"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"}

我怎样才能改变它,使它只是以消息形式发送?

【问题讨论】:

    标签: bots facebook-messenger


    【解决方案1】:

    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")
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-09-06
      • 1970-01-01
      • 2016-10-29
      • 2017-12-22
      • 2017-06-04
      • 2018-12-17
      • 1970-01-01
      • 2016-10-05
      • 2016-10-20
      相关资源
      最近更新 更多