2017 © Pedro Peláez
 

library facebook-messenger-bundle

A Symfony bundle for Facebook Messenger

image

pouler/facebook-messenger-bundle

A Symfony bundle for Facebook Messenger

  • Tuesday, March 13, 2018
  • by PouleR
  • Repository
  • 1 Watchers
  • 4 Stars
  • 4,271 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 12 Versions
  • 10 % Grown

The README.md

Facebook Messenger Bundle

Build Status SensioLabsInsight, (*1)

Latest Stable Version Total Downloads Latest Unstable Version, (*2)

A PHP Facebook Messenger API for the Symfony framework., (*3)

Installation

Step 1: Download Bundle

$ composer require pouler/facebook-messenger-bundle

Step 2: Enable the bundle (Symfony 2/3)

Next, enable the bundle in the kernel:, (*4)

``` php <?php // app/AppKernel.php, (*5)

public function registerBundles() { $bundles = array( // ... new PouleR\FacebookMessengerBundle\FacebookMessengerBundle(), ); }, (*6)


## Configuration Edit your `config.yml` with the following configuration: pouler_facebook_messenger: app_id: 'YourFBMessengerAppId' app_secret: 'YourFBMessengerAppSecret' ## Examples ### Set your default greeting text ``` php $service = new FacebookMessengerService('...', '...', new NullLogger()); $service->setAccessToken('PAGE_ACCESS_TOKEN'); $config = new GreetingTextConfiguration(); $config->setText('Hello and welcome!'); $service->setGreetingText($config);

Send a text message to a user (by PSID)

``` php $service = new FacebookMessengerService('...', '...', new NullLogger()); $service->setAccessToken('PAGE_ACCESS_TOKEN');, (*7)

$recipient = new Recipient('PSID'); $message = new Message('Hi there, this is a test');, (*8)

$service->postMessage($recipient, $message);, (*9)


### Use batch requests to send a text message to different users (by PSID) ``` php $service = new FacebookMessengerService('...', '...', new NullLogger()); $service->setAccessToken('PAGE_ACCESS_TOKEN'); $message = new Message('Hi there, this is a batch message'); $service->addMessageToBatch(new Recipient('PSID1'), $message); $service->addMessageToBatch(new Recipient('PSID2'), $message); $service->addMessageToBatch(new Recipient('PSID3'), $message); $response = $service->sendBatchRequests(); // The response variable contains an array with FailedMessageRequest objects

Create a generic template message

``` php $message = new Message(); $templateAttachment = new TemplateAttachment(); $genericTemplatePayload = new GenericTemplatePayload();, (*10)

$pbButton = new PostbackButton(); $pbButton->setTitle('Button Title Goes Here'); $pbButton->setPayload('payload_data');, (*11)

$wuButton = new WebUrlButton(); $wuButton->setTitle('Button Title Goes Here'); $wuButton->setUrl('https://www.google.com');, (*12)

$buttons = [$pbButton, $wuButton];, (*13)

// Create some elements $genericElementOne = new GenericElement(); $genericElementOne->setTitle('Element Title Goes Here'); $genericElementOne->setImageUrl('https://placekitten.com/200/300'); $genericElementOne->setSubtitle('Subtitle Goes Here'); $genericElementOne->setButtons($buttons);, (*14)

$genericElementTwo = new GenericElement(); $genericElementTwo->setTitle('Element Title Goes Here'); $genericElementTwo->setImageUrl('https://placekitten.com/200/300'); $genericElementTwo->setSubtitle('Subtitle Goes Here'); $genericElementTwo->setButtons($buttons);, (*15)

// Add them to the payload $genericTemplatePayload->setElements([$genericElementOne, $genericElementTwo]);, (*16)

// Set the payload on the attachment $templateAttachment->setPayload($genericTemplatePayload);, (*17)

// Set the Attachment on the message $message->setAttachment($templateAttachment); ```, (*18)

Original project by John Kosmetos (https://github.com/jkosmetos/facebook-messenger-api), (*19)

The Versions

16/08 2016

v0.1.1

0.1.1.0

A Symfony bundle for Facebook Messenger

  Sources   Download

MIT

The Requires

 

by Paul Radt

12/08 2016

v0.1

0.1.0.0

A PHP wrapper for the Facebook Messenger API

  Sources   Download

MIT

The Requires

 

by John Kosmetos