Search code examples
facebookmessagebotsmessenger

How to set a welcome message for my Messenger Bot


I am trying to create a simple answer bot fo my facebook page but am kind of lost as it it my first try.

I have integrated the webhook on my website and this is the file at the end of my Callback URL:

<?php 
$challenge = $_REQUEST['hub_challenge'];
$verify_token = $_REQUEST['hub_verify_token'];

if ($verify_token === 'YOURVERIFYTOKEN'){
echo $challenge;
}
?>

The webhook is set up but I have no clue what should be my next step ? How could I set up a welcome message ?


Solution

  • You're meant to be able to do it by posting to this API:

    https://developers.facebook.com/docs/messenger-platform/send-api-reference#welcome_message_configuration

    https://graph.facebook.com/v2.6/<PAGE_ID>/thread_settings?access_token=<PAGE_ACCESS_TOKEN>
    

    with a payload like this:

    {
      "setting_type":"call_to_actions",
      "thread_state":"new_thread",
      "call_to_actions":[
        {
          "message":{
            "text":"Welcome to My Company!"
          }
        }
      ]
    }
    

    This has worked for me in the past but I'm currently getting validation errors when I try. I've opened a bug with the facebook platform team.

    Update

    To set a welcome message you send the following payload to the above URL:

    {
      "setting_type":"greeting",
      "greeting":{
        "text":"Timeless apparel for the masses."
      }
    }
    

    as per:

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