Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This document briefs you on how to connect Orbita to the FaceBook messenger bot.

Table of Contents

Setting

...

up Facebook

In order to set up the Facebook integration for your agent, you'll need the following:

...

  1. Click on Products from the side menu, select Messenger, and Click click on the Set Up button from Messenger.Click

    Image Added
  2. In the Products > Messenger > Settings page, click on “Add or Remove Pages” to add your Facebook page to the App.

  3. Connect the Generate Page Access Token.

For Facebook to verify our callback URL

  1. Add “http in” node with URL as bot/messenger and the Method: GET

  2. Add a function node (Verification node in the sample flow screenshot) with the following code
    msg.payload = msg.payload['hub.challenge'];
    return msg;

  3. Add “http out” node.

Facebook Webhook Configuration

...

Access Tokens

  1. In the Access tokens section of the settings page, click on the Generate token against the page you added.

    Image Added
  2. Check the I Understand checkbox, click on Copy,and select Done.

    Image Added

The access token should be kept safe for later use.

Webhooks

  1. In the Webhooks section, click on Add Callback URL.

  2. Copy your web chatbot URL and paste it here and a valid text in the verification token.
    For example,https://aurora<yourdomain>.orbita.cloud:8443/oeapi/bot/messenger

    Image Added
  3. Click on the Add Subscriptions” button and check the messages and messaging_postbacks options. Click on Save.

    Image Added
  4. The Webhooks should have a "Complete" status with a green tick (tick) as shown in the screenshot below.

...

  1. .

    Image Added

Ensure you have the following checked.

  1. App icon

  2. Valid privacy policy url

  3. Business use

  4. App category

Make the app public

Please ensure to toggle on the Live status to make the app public.

...

For Business users, you need to do Business Verification to make the app public.
Click on the Get started and submit the verification to Facebook.

...

Setting up the Experience Designer

Connect two function nodes before and after Bot provider V2 node. One for getting the input from Facebook and the other to Process the output sent to Facebook.

For Facebook to verify our callback URL

  1. Add “http in” node with URL as bot/messenger and the Method: GET

  2. Add a function node (Verification node in the sample flow screenshot) with the following code
    msg.payload = msg.payload['hub.challenge'];
    return msg;

  3. Add “http out” node.

FB input

Place the below code in this function node.

Code Block
if(msg.payload.entry[0].messaging[0].message)

...


    msg.payload.text = msg.payload.entry[0].messaging[0].message.text

...

else

 
else
    msg.payload.text="Launch"

...


    msg.payload.fbSenderId = msg.payload.entry[0].messaging[0].sender.id;

...


return msg;

Process FB output

Place the below code in this function node. Replace the XXXXXXX in the code with Facebook’s page access tokenAccess token you copied when the page is connected to the Facebook App.

Code Block
var stripTags = msg.payload.orbitaPayload.payload.multiagent.chat.chatText.replace(/<[^>]+>/g, '')

...


msg.payload=

...

{

...


{
  "messaging_type": "RESPONSE",

...


  "recipient":

...

 {
    "id": msg.orginalPayload.fbSenderId

...


  },

...


  "message":

...

 {
    "text":

...

  }

}

stripTags    
  }
}


msg.url = "https://graph.facebook.com/v4.0/me/messages?access_token=

...

XXXXXX"

...


msg.method = 'POST';

...


msg.headers = {};

...


msg.headers['Content-Type'] = 'application/json';

...


return msg;

http request

Configure this node as shown in the below screenshot before connecting it to “http out”.

...

Sample flow

...