PHP code example of roysegall / facebook-messenger-send-api

1. Go to this page and download the library: Download roysegall/facebook-messenger-send-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

roysegall / facebook-messenger-send-api example snippets




$facebook = new FacebookMessengerSendApi\SendAPI();

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

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

$facebook
  ->setAccessToken($access_token)
  ->setRecipientId($recipient);



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

$facebook->sendMessage($message);



$message = $facebook->templates->generic
  ->addElement(
    $facebook->templates->element
      ->title('This is a title')
      ->addButton(
        $facebook->buttons->postBack
          ->title('This is a button')
          ->payload('button')
      )
      ->addButton(
        $facebook->buttons->postBack
          ->title('This is another button')
          ->payload('button2')
      )
  );



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



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

$facebook
  ->setTag('A_TAG')
  ->sendMessage($message);