PHP code example of gomoob / php-facebook-messenger

1. Go to this page and download the library: Download gomoob/php-facebook-messenger 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/ */

    

gomoob / php-facebook-messenger example snippets


// Create a Facebook Messenger client
$client = Client::create()->setPageAccessToken('XXXX-XXX');

// Create a request to send a simple Text Message
$request = TextMessageRequest::create()
    ->setRecipient(Recipient::create()->setId('USER_ID'))
    ->setMessage(TextMessage::create()->setText('hello, world !'));

// Call the REST Web Service
$response = $client->sendMessage($textMessageRequest);

// Check if its ok
if($response->isOk()) {
    print 'Great, the message has been sent !';
} else {
    print 'Oups, the sent failed :-('; 
    print 'Status code : ' . $response->getStatusCode();
    print 'Status message : ' . $response->getStatusMessage();
}