Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Facebook Messenger send API

You started to write your but there is a problem - how to send back messages? You heads to the Messenger platform send API and start to read the documentation.

As you progress with the reading, you'll understand that if you want to send a text or an image required from to create and array with some confusing structure. But, that is not your worst problem - if you want to send generic template you need to send an enormous and confusing array.

This is where this library come in hand. The Facebook Messenger send API contains an object for each type of section in the send api for the Messenger platform. Combine that with the autocomplete feature that exists in any modern IDE and you'll get an easy way to construct the array.

Sending will be easy as well since there is a dedicated API for that. Let's dive in!

What are the principles and how they can assist you

If you'll have a look in the send api documentation you can see a specific structure:

  • Content types
    • Text
    • Audio
    • Image
    • ...
  • Templates
    • Button
    • Generic
    • List
    • ...
  • Buttons
  • Quick replies
  • Sender
  • ..

And inside, there are more fields and object. Let's have a look on how to start the object:


$facebook = new FacebookMessengerSendApi\SendAPI();

// The app access token.
$access_token = '';

// The user recipient ID.
$recipient = 0;


After that, we need to start and build our payload object for a text(and sending it as well):


$message = $facebook->contentType->text->text('This is a message.');


What we can see here? Since the text in under the content type section, and the text section have only text the code is very easy to understand: $facebook->contentType->text->text('This is a message.')

What about an image? Very easy:


Templates and button

Button have their own section, and templates have their own section. How this will work:


$message = $facebook->templates->generic
      ->title('This is a title')
          ->title('This is a button')
          ->title('This is another button')

Sending an action

Action are a bit different that that. Since it's not a crazy payload we have a very simple task for that:

$message = $facebook->senderActions('TYPING_ON');
$message = $facebook->senderActions('TYPING_OFF');

This will give the affect off typing bubbles and after 3 seconds they will disappear. Try it, it's cool :)

Adding tag

You can add a tag to your message:


$message = $facebook->contentType->text->text('message');


Test it your self

After you'll get an access token and you find out the recipient user ID you can try your code by writing in the testing.php and run it.

If you don't know what is the user recipient ID(of your self in this case) you can get that by setting up the bot and start a conversation. Your recipient ID will be in the payload of the request.

Don't forget to populate variables!


Documentation and unit testing will be more than welcome.


No description, website, or topics provided.



No packages published


You can’t perform that action at this time.