how to setup “Get started” button in facebook mess

2019-04-06 09:35发布

10条回答
倾城 Initia
2楼-- · 2019-04-06 09:42

Very simple solution, just open in terminal and go to your host folder location,( in mine /var/www/html/booking/public/facebookbot ) and paste the following code:

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"

and press enter, make sure to put your correct access token, also you may recognize when your getting started button pressed from payload which is GET_STARTED_PAYLOAD in above code sample.

查看更多
Bombasti
3楼-- · 2019-04-06 09:45

The current format is, https://graph.facebook.com/v2.6/me/messenger_profile?access_token=PAGE_ACCESS_TOKEN

{ 
  "get_started":{
    "payload":"GET_STARTED_PAYLOAD"
  }
}
查看更多
爷的心禁止访问
4楼-- · 2019-04-06 09:58

Send a post request using your page access token

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

with following data

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

Facebok Docs: Get Started Button

Hope this new method solve your problem. Don't forget to delete sent messages first using Facebook Web to see button in action.

查看更多
对你真心纯属浪费
5楼-- · 2019-04-06 10:00

There is a library in npm that wraps the functionality of the POST/DELETE actions here: 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楼-- · 2019-04-06 10:00

A better solution in my opinion is to use the Microsoft Bot Framework and use its /firstRun to send the messenger get started button

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

The platforms.firstRun looks as shown below

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

This in turn calls 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)
    ])
}

The platforms.facebook.sendThread looks as shown below // Calls the Facebook graph api to change bot settings

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

Notice the facebookTemplates.getStarted(), that actually has the json for get started which looks as shown below

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

Fully pluggable code architecture for performing a first run operation across all chatbot platforms. Works perfectly on my bot HERE

查看更多
仙女界的扛把子
7楼-- · 2019-04-06 10:01

you have to run an appropriate curl command to set it up. check this link out and look at their example. https://developers.facebook.com/docs/messenger-platform/implementation#send_api

查看更多
登录 后发表回答