【问题标题】:how to setup "Get started" button in facebook messenger bot and when to send welcome message如何在 facebook messenger bot 中设置“开始”按钮以及何时发送欢迎消息
【发布时间】:2016-10-29 03:05:50
【问题描述】:

【问题讨论】:

  • 提供有关您所做工作的更多信息。并首先在网上搜索教程。有一种叫做“如何开始使用 Facebook Messenger Bots”。
  • 我遵循了接受的答案,但仍然无法在欢迎屏幕中显示“开始”按钮。谁能帮忙?

标签: facebook facebook-messenger facebook-chatbot


【解决方案1】:

使用您的页面访问令牌发送发布请求

https://graph.facebook.com/v2.6/me/messenger_profile?access_token=YOUR-TOKEN

有以下数据

{ 
  "get_started":{
     "payload":"<GET_STARTED_PAYLOAD>"
   }
}

Facebook 文档: Get Started Button

希望这种新方法能解决您的问题。不要忘记先使用 Facebook Web 删除已发送的消息,以查看按钮的作用。

【讨论】:

    【解决方案2】:

    目前的格式是, https://graph.facebook.com/v2.6/me/messenger_profile?access_token=PAGE_ACCESS_TOKEN

    { 
      "get_started":{
        "payload":"GET_STARTED_PAYLOAD"
      }
    }
    

    【讨论】:

      【解决方案3】:

      非常简单的解决方案,只需在终端中打开并转到您的主机文件夹位置(在我的 /var/www/html/booking/public/facebookbot 中)并粘贴以下代码:

      curl -X POST -H "Content-type: application/json" -d '{ 
          "setting-type":"call_to_actions",
          "thread_state":"new_thread",
        "get_started":{
           "payload":"GET_STARTED_PAYLOAD"
         }
      }' "https://graph.facebook.com/v2.6/me/messenger_profile?access_token=YOUR_ACCESS_TOKEN"
      

      然后按回车键,确保输入正确的访问令牌,您还可以识别何时从有效负载(即上述代码示例中的 GET_STARTED_PAYLOAD)按下开始按钮。

      【讨论】:

        【解决方案4】:

        在我们的例子中,以下方法有效:

        • 点击thread_settings API

          https://graph.facebook.com/v2.6/me/thread_settings?access_token=&lt;YOU FACEBOOK PAGE'S PAGE ACCESS TOKEN&gt;

        • 通过了以下示例 JSON

        { "setting_type": "call_to_actions", "thread_state": "new_thread", “call_to_actions”:[ { “有效载荷”:“开始” } ] }
        • API 应给出以下结果:
        { "result": "成功添加 new_thread 的 CTA" }

        【讨论】:

          【解决方案5】:

          npm 中有一个库,在这里封装了 POST/DELETE 操作的功能:https://www.npmjs.com/package/fb-get-started-button

          $ npm install -g fb-get-started-button
          
          $ fb-get-started-button add <YOUR PAGE ACCESS TOKEN>
          Adding "Get Started" button with the payload "GET_STARTED"
          Successfully added new_thread's CTAs
          
          $ fb-get-started-button remove <YOUR PAGE ACCESS TOKEN>
          Removing "Get Started" button
          Successfully deleted all new_thread's CTAs
          

          【讨论】:

            【解决方案6】:

            您可能已成功设置它,但没有看到它,因为您已经与 facebook 页面进行了现有对话。

            成功设置“开始”话题后,只有在删除现有对话话题并开始新话题时才能看到它。

            仅当您第一次与 Facebook 页面交互时才会显示“开始”按钮,因此如果您之前曾向该页面发送过消息,除非您从 Facebook 中删除线程,否则您将无法看到“开始” Messenger 客户端(移动或桌面)。

            来自FB Messenger Docs:

            看到欢迎屏幕和开始按钮需要满足某些条件:

            • 它们仅在用户第一次与 Messenger 上的页面交互时呈现
            • 当应用处于开发模式时,只有应用的管理员/开发人员/测试人员可以看到它
            • 您的应用必须订阅 webhook 上的回发

            【讨论】:

              【解决方案7】:

              我认为更好的解决方案是使用 Microsoft Bot Framework 并使用它的 /firstRun 发送信使开始按钮

              function firstRun(session) {
                console.log('This user is running our bot the first time')
                createUser(session)
                platforms.firstRun(session.message.user.id, session.message.address.channelId)
                  .then((values) => {
                    for (let value of values) {
                      if (value.data.firstName && value.data.lastName) {
                        session.userData.user.profile = value.data
                      }
                    }
                  })
                  .catch((errors => {
                    console.log(errors);
                  }))
                reply(session)
                session.endDialog()
              }
              

              platforms.firstRun 如下图所示

              platforms.firstRun = function (userId, channel) {
                  switch (channel) {
                      case platforms.channels.emulator:
                          return Promise.reject('none')
                      case platforms.channels.facebook:
                          return platforms.facebook.firstRun(userId)
                      case platforms.channels.skype:
                          return Promise.reject('none')
                      default:
                          return Promise.reject('none')
                  }
              }
              

              这又会调用pl​​atforms.facebook.firstRun

              platforms.facebook.firstRun = function (userId) {
                  return Promise.all([
                      platforms.facebook.sendThread(facebookTemplates.greet(), 'Greeting'),
                      platforms.facebook.sendThread(facebookTemplates.getStarted(), 'Get Started'),
                      platforms.facebook.sendThread(facebookTemplates.getPersistentMenu(), 'Persistent Menu'),
                      platforms.facebook.sendThread(facebookTemplates.getDomainWhitelisting(), 'Domain Whitelisting'),
                      platforms.facebook.getProfile(userId)
                  ])
              }
              

              platforms.facebook.sendThread 如下所示 // 调用 Facebook graph api 来改变 bot 设置

              platforms.facebook.sendThread = function (template, cmd) {
              
                  return new Promise((resolve, reject) => {
                      // Start the request
                      request({
                          url: platforms.facebook.GRAPH_BASE_URI + '/me/thread_settings?access_token=' + endpoints.FACEBOOK_PAGE_ACCESS_TOKEN,
                          method: 'POST',
                          headers: { 'Content-Type': 'application/json' },
                          form: template
                      },
                          function (error, response, body) {
                              if (!error && response.statusCode == 200) {
                                  // Print out the response body
                                  resolve({ status: response.statusCode, data: body })
                              } else {
                                  // TODO: Handle errors
                                  reject({ status: response.statusCode, data: error })
                              }
                          });
                  })
              }
              

              请注意 facebookTemplates.getStarted(),它实际上具有用于入门的 json,如下所示

              templates.getStarted = function () {
                  return {
                      setting_type: "call_to_actions",
                      thread_state: "new_thread",
                      call_to_actions: [
                          {
                              payload: payloads.FACEBOOK_GET_STARTED
                          }
                      ]
                  }
              }
              

              完全可插入的代码架构,用于在所有聊天机器人平台上执行首次运行操作。在我的机器人上完美运行 HERE

              【讨论】:

                【解决方案8】:

                对 API JSON 正文进行 POST 调用,如下所示。

                curl -X POST -H "Content-Type: application/json" -d '{
                "setting_type":"call_to_actions",
                "thread_state":"new_thread",
                "call_to_actions":[
                 {
                  "payload":"USER_DEFINED_PAYLOAD"
                 }
                ]
                }' "https://graph.facebook.com/v2.6/me/thread_settings?access_token=PAGE_ACCESS_TOKEN"
                

                参考:Facebook messenger get started button

                Postman screentshot

                【讨论】:

                • 这行得通。您是否已将访问令牌更改为您的。
                • 我无法在 Facebook Messenger 安卓应用上查看。
                【解决方案9】:

                感谢宝贵的 cmets,根据 facebook 指南,经过一些变通方法发现此解决方案有效

                只需向该 URL 发送一次独立的 POST 请求

                https://graph.facebook.com/v2.6/PAGE_ID/thread_settings?access_token=PAGE_ACCESS_TOKEN

                使用邮递员发送这样的请求 here

                如果Get Started按钮设置成功,你会得到如下响应

                {
                  "result": "Successfully added new_thread's CTAs"
                }
                

                【讨论】:

                • 返回 "(#100) Invalid keys \"message\" were found in param \"call_to_actions[0]\"
                • 那是因为它的“消息”不是“call_to_actions”的属性。删除属性“消息”
                【解决方案10】:

                您必须运行适当的 curl 命令来设置它。检查此链接并查看他们的示例。 https://developers.facebook.com/docs/messenger-platform/implementation#send_api

                【讨论】:

                  猜你喜欢
                  • 2016-10-20
                  • 2020-06-03
                  • 1970-01-01
                  • 1970-01-01
                  • 2017-06-07
                  • 2016-09-06
                  • 1970-01-01
                  • 1970-01-01
                  • 2017-01-05
                  相关资源
                  最近更新 更多