Smartly.AI

Facebook Messenger

Facebook Messenger Integration

Messenger integration allow you to add your bot to Facebook Messenger.
To do that you have to follow these steps :

1- Click on messenger, this window will appear:

In this step you have to fill the Token verify
The token verify can be anything, but we recommend you use your bot/app name

2- Create your facebook page

If you already have a Facebook Page, skip this step

3- Go to Developers Facebook

4- Add a new App

5- After creating the new app you will be redirected to Product Setup, in this state you have to get Messenger started

6- Once the messenger has started you have to generate Page Access Token and copy it

7- Paste the Page Access Token in your messenger integration like that

8- Hit Deploy my App

9- Now in developers facebook go to set up webhook

  • Paste webhook url (get it from smartly messenger integration) into Callback URL
  • Paste token verify (get it from smartly messenger integration) into Verify Token
  • In Subscription Fields choose messages and messaging postpacks

10- To activate the bot you have to subscribe your webhook to the page events

Finally you can start talking to the Bot on Messenger

NodeJs : user_data

To Customize our Messages according to the attributes of messenger users (first name, last name etc…), for example if we want to say hello username how are you ? You have to go to the builder and add a NodeJs node then add these line of code:

output.answer = "hello "+messenger_user.first_name + " " +messenger_user.last_name + " How are you ?";
{
    "first_name":"Smartly",
    "last_name":"AI",
    "profile_pic":"https://scontent.ftun3-1.fna.fbcdn.net/v/t1.0-9/18057955_1697168273645572_7528083323191086401_n.png?oh=ca6b53926e08b23c590bea756405b1fe&oe=598B4F5C",
    "locale":"fr_FR",
    "timezone":1,
    "gender":"male",
    "sender":"1310677675254316"
}

NodeJs : messenger_request

The same for messenger requests, if we want to get for example the facebook page of the sender we can add this line of code:

output.answer = "sender is : www.facebook.com/"+messenger_request.recipient.id;
{
  "recipient":{"id":"1696999743662425"},
  "timestamp":1493138028508,
  "sender":{"id":"1285562291541696"},
  "postback":{"payload":"GET_STARTED_PAYLOAD"}
}

NodeJs : messenger_answer

If we want to add many elements like images, buttons, carousels etc… to the bot’s messages, we have to prepare our json containing all elements we need it, and push it in the messenger_answer table messenger_answer.push()

{
   "attachment":{
     "type":"template",
     "payload":{
       "template_type":"generic",
       "elements":[
          {
           "title":"Welcome to Smartly",
           "image_url":"https://bots.smartly.ai",
           "subtitle":"We've got the bot for everyone.",
           "default_action": {
             "type": "web_url",
             "url": "https://bots.smartly.ai",
             "messenger_extensions": true,
             "webview_height_ratio": "tall",
             "fallback_url": "https://bots.smartly.ai"
           },
           "buttons":[
             {
               "type":"web_url",
               "url":"https://bots.smartly.ai",
               "title":"View Website"
             },{
               "type":"postback",
               "title":"Start Chatting",
               "payload":"DEVELOPER_DEFINED_PAYLOAD"
             }              
           ]      
         }
       ]
     }
   }
 }

Facebook Messenger


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.