如何在facebook messenger bot中设置“开始使用”按钮以及何时发送欢迎信息

问题描述 投票:9回答:10

"Get Started"

尝试向此网址发送请求

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

但没有奏效。

facebook facebook-messenger facebook-chatbot
10个回答
15
投票

对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


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"

并按Enter键,确保放置正确的访问令牌,您也可以识别从上面的代码示例中的GET_STARTED_PAYLOAD有效负载按下开始按钮的时间。


4
投票

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

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

只有在您第一次与Facebook页面交互时才会显示“开始”按钮,因此,如果您之前已向该页面发送消息,除非您从Facebook Messenger客户端删除该主题,否则您将无法看到“开始使用”(无论是移动还是桌面)。

来自FB Messenger Docs:

在某些条件下可以看到欢迎屏幕和“开始使用”按钮:

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

4
投票

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

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

3
投票

感谢有价值的评论,经过一些解决方法发现此解决方案正常工作,根据Facebook指南

需要仅向ONCE发送一个独立的POST请求到此URL

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

用邮递员发送像here这样的要求

如果成功设置了“入门”按钮,您将收到以下响应

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

2
投票

你必须运行一个适当的curl命令来设置它。检查这个链接,看看他们的例子。 https://developers.facebook.com/docs/messenger-platform/implementation#send_api


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

2
投票

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

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

以下数据

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

Facebook Docs:Get Started Button

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


0
投票

在我看来,更好的解决方案是使用Microsoft Bot Framework并使用其/ firstRun发送messenger get started按钮

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

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

platforms.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 for get started,如下所示

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

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


0
投票

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

  • 点击thread_settings API 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": [
        {
          "payload": "Start"
        }
      ]
    }
  • API应给出以下结果:
    {
        "result": "Successfully added new_thread's CTAs"
    }
© www.soinside.com 2019 - 2024. All rights reserved.