Mazen Abu Taweelih
Mazen Abu Taweelih

Reputation: 647

"Get Started" button on facebook bot with bot framework

How can I put the get started button as the sameone in facebook bots ? I checked facebook documentation and it's saying I have to make a call to facebook service but I didnt get that well. This is the documentation URL.

https://developers.facebook.com/docs/messenger-platform/thread-settings

Upvotes: 0

Views: 1161

Answers (1)

Ezequiel Jadib
Ezequiel Jadib

Reputation: 14787

Take a look to this issue in the BotBuilder GitHub where this was discussed. The following is code from that thread:

app.js

var request = require('request');

//=========================================================
// Facebook setup // Run only when need updating.
//=========================================================

// Set FB bot greeting text
facebookThreadAPI('./fb-greeting-text.json', 'Greating Text');
// Set FB bot get started button
facebookThreadAPI('./fb-get-started-button.json', 'Get Started Button');
// Set FB bot persistent menu
facebookThreadAPI('./fb-persistent-menu.json', 'Persistent Menu');

// Calls the Facebook graph api to change various bot settings
function facebookThreadAPI(jsonFile, cmd){
    // Start the request
    request({
        url: 'https://graph.facebook.com/v2.6/me/thread_settings?access_token='+process.env.FB_PAGE_ACCESS_TOKEN,
        method: 'POST',
        headers: {'Content-Type': 'application/json'},
        form: require(jsonFile)
    },
    function (error, response, body) {
        if (!error && response.statusCode == 200) {
            // Print out the response body
            console.log(cmd+": Updated.");
            console.log(body);
        } else { 
            // TODO: Handle errors
            console.log(cmd+": Failed. Need to handle errors.");
            console.log(body);
        }
    });
}

fb-greeting-text.json

{
  "setting_type":"greeting",
  "greeting":{  
    "text":"Your greeting text here."
  }
}

fb-get-started-button.json

{
  "setting_type":"call_to_actions",
  "thread_state":"new_thread",
  "call_to_actions":[
    {
      "payload":"action?POSTBACKHERE"
    }
  ]
}

fb-persistent-menu.json

// Just using the menu to do a single button admin reset
{
  "setting_type" : "call_to_actions",
  "thread_state" : "existing_thread",
  "call_to_actions":[
    {
      "type":"postback",
      "title":"Admin Reset",
      "payload":"action?POSTBACKHERE"
    }
  ]
}

Upvotes: 1

Related Questions