10

“开始”

尝试向此 url 发送请求

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

但是没有用。

4

10 回答 10

17

对 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 开始按钮

邮递员截图

于 2016-07-01T20:22:08.623 回答
6

当前格式为 https://graph.facebook.com/v2.6/me/messenger_profile?access_token=PAGE_ACCESS_TOKEN

{ 
  "get_started":{
    "payload":"GET_STARTED_PAYLOAD"
  }
}
于 2017-09-07T12:23:25.783 回答
5

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

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

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

来自FB Messenger 文档:

看到欢迎屏幕和开始按钮有一定的条件:

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

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

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

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

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

如果 Get Started 按钮设置成功,您将收到以下响应

{
  "result": "Successfully added new_thread's CTAs"
}
于 2016-06-30T07:26:34.193 回答
2

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

于 2016-06-28T14:27:10.580 回答
2

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
于 2017-04-23T06:24:23.100 回答
2

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

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

有以下数据

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

Facebook 文档: 开始按钮

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

于 2018-01-12T20:56:03.333 回答
0

我认为更好的解决方案是使用 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()
}

platform.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')
    }
}

这反过来又调用了platforms.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)
    ])
}

platform.facebook.sendThread 如下所示 // 调用 Facebook 图形 api 来更改机器人设置

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

于 2016-11-17T16:24:00.110 回答
0

非常简单的解决方案,只需在终端中打开并转到您的主机文件夹位置(在我/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)按下开始按钮。

于 2019-02-01T17:41:59.900 回答
0

在我们的例子中,以下工作:

  • 点击thread_settingsAPI

    https://graph.facebook.com/v2.6/me/thread_settings?access_token=<YOU FACEBOOK PAGE'S PAGE ACCESS TOKEN>

  • 传递了以下示例 JSON

    {
      "setting_type": "call_to_actions",
      "thread_state": "new_thread",
      “call_to_actions”:[
        {
          “有效载荷”:“开始”
        }
      ]
    }
  • API 应给出以下结果:
    {
        "result": "成功添加 new_thread 的 CTA"
    }
于 2017-12-03T07:30:40.137 回答