-1

When I create a facebook messenger bot with node.js API, I need to connect it to my Facebook Page (not a personal profile), so users can click 'message' (by default this allows to write a message to the page) button to start working with the bot.

So, how can I save both functions: to write a message to the page and to start working with the bot?

1 Answers1

0

So, how can I save both functions: to write a message to the page and to start working with the bot?

I'm going to interpret this as "How do I set up the Messenger Greeting and Get Started button".

Here's an example on how to do these in node.js:

//this sets the messenger greeting
function setMessengerGreeting(){
  var messageData = {
    setting_type: "greeting",
    greeting: {
      text: "Hi mom"
    }
  }
  callSendAPISetup(messageData);
}

//this sets the Get Started button and welcome message
function setWelcomeMessage(){
  var messageData = {
    setting_type: "call_to_actions",
    thread_state: "new_thread",
    call_to_actions: [
      {payload: "hi"}
    ]
  }
  callSendAPISetup(messageData);
}

//Sends the messageData for setup
function callSendAPISetup(messageData) {
  request({
    uri: 'https://graph.facebook.com/v2.6/me/thread_settings',
    qs: { access_token: PAGE_ACCESS_TOKEN },
    method: 'POST',
    json: messageData

  }, function (error, response, body) {
    if (!error && response.statusCode == 200) {
      console.log('response: ' + response.body.result);
    } else {
      console.log('error sending curl');
      console.error(response);
      console.error(error);
    }
  });  
}

Documentation:

Messenger Greeting: https://developers.facebook.com/docs/messenger-platform/thread-settings/greeting-text

Get Started Button: https://developers.facebook.com/docs/messenger-platform/thread-settings/get-started-button

user2322082
  • 658
  • 1
  • 6
  • 18