2017 © Pedro Peláez
 

library fb-messenger-bot-php

image

samiaraboglu/fb-messenger-bot-php

  • Sunday, March 11, 2018
  • by samiaraboglu
  • Repository
  • 2 Watchers
  • 2 Stars
  • 2,540 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 45 % Grown

The README.md

fb-messenger-bot-php

Latest Stable Version Total Downloads License, (*1)

Installing

Via composer, (*2)

$ composer require samiaraboglu/fb-messenger-bot-php

Config, (*3)

$messenger = new \FbMessengerBot\Messenger('<YOUR_ACCESS_TOKEN>');

Conversation Components

Use the message class, (*4)

$message = new \FbMessengerBot\Message();

Text Message

$message->text('<MESSAGE_TEXT>');

Assets & Attachments

Audio
$message->audio('<URL.mp3>');
Video
$message->video('<URL.mp4>');
Image
$message->image('<URL.jpg>');
File
$message->file('<URL.pdf>');

Message Templates

Button Template

URL Button
// simple
$message->url('<MESSAGE_TEXT>', '<BUTTON_TITLE>', '<BUTTON_URL>');
// multiple
$message->button('<MESSAGE_TEXT>', [
    [
        'title' => '<BUTTON_TITLE>',
        'url' => '<BUTTON_URL>'
    ],
    [
        'title' => '<BUTTON_TITLE>',
        'url' => '<BUTTON_URL>'
    ],
    [
        ...
    ],
    [...]
]);
Postback Button
// simple
$message->postback('<MESSAGE_TEXT>', '<BUTTON_TITLE>', '<POSTBACK_PAYLOAD>');
// multiple
$message->button('<MESSAGE_TEXT>', [
    [
        'type' => 'postback',
        'title' => '<BUTTON_TITLE>',
        'payload' => '<POSTBACK_PAYLOAD>'
    ],
    [
        ...
    ],
    [...]
]);
Share Button
// TO DO
Buy Button
// TO DO
Call Button
// simple
$message->call('<MESSAGE_TEXT>', '<BUTTON_TITLE>', '+<COUNTRY_CODE><PHONE_NUMBER>');
// multiple
$message->button('<MESSAGE_TEXT>', [
    [
        'type' => 'phone_number',
        'title' => '<BUTTON_TEXT>',
        'payload' => '<PHONE_NUMBER>'
    ],
    [
        ...
    ],
    [...]
]);
Log In Button
$message->login('<MESSAGE_TEXT>', '<YOUR_LOGIN_URL>');
Log Out Button
$message->logout('<MESSAGE_TEXT>');
Game Play Button
// TO DO

Quick Replies

Text
// simple
$message->quickReplie('<MESSAGE_TEXT>', '<BUTTON_TITLE>', '<POSTBACK_PAYLOAD>');
// multiple
$message->quickReplies('<MESSAGE_TEXT>', [
    [
        'title' => '<BUTTON_TITLE>',
        'payload' => '<POSTBACK_PAYLOAD>'
    ],
    [
        ...
    ],
    [...]
]);
Text With Image
// simple
$message->quickReplie('<MESSAGE_TEXT>', '<BUTTON_TITLE>', '<POSTBACK_PAYLOAD>', '<URL.jpg>');
// multiple
$message->quickReplies('<MESSAGE_TEXT>', [
    [
        'title' => '<BUTTON_TITLE>',
        'payload' => '<POSTBACK_PAYLOAD>',
        'image' => '<URL.jpg>'
    ],
    [
        ...
    ],
    [...]
]);
Location
// simple
$message->location('<MESSAGE_TEXT>');
// multiple
$message->quickReplies('<MESSAGE_TEXT>', [
    [
        'type' => 'location'
    ],
    [
        ...
    ],
    [...]
]);
Phone Number
// simple
$message->phoneNumber('<MESSAGE_TEXT>');
// multiple
$message->quickReplies('<MESSAGE_TEXT>', [
    [
        'type' => 'user_phone_number'
    ],
    [
        ...
    ],
    [...]
]);
Email
// simple
$message->email('<MESSAGE_TEXT>');
// multiple
$message->quickReplies('<MESSAGE_TEXT>', [
    [
        'type' => 'user_email'
    ],
    [
        ...
    ],
    [...]
]);

Send Message

Require page-scoped ID (PSID), (*5)

$response = $messenger->send(<PSID>, $message);

Example response, (*6)

// response print
Array
(
    [recipient_id] => <PSID>
    [message_id] => mid.$cAAoZdzlbwyxoOR257liB9xxxxxx
)

Saving Assets for Attachments

Send second parameter true. Supported asset types: image audio video file, (*7)

$message->image('<URL.jpg>', true);

Example response, (*8)

// response print
Array
(
    [recipient_id] => <PSID>
    [message_id] => mid.$cAAcZdzlzwkxoQ6ss8ViEmxxxxxx
    [attachment_id] => 1200933831599999
)

Send message with attachment_id, (*9)

$message->image(<ATTACHMENT_ID>);

Get Body

$body = $messenger->getBody();

// body print
Array
(
    [recipient] => Array
        (
            [id] => ...
        )

    [message] => Array
        (
            [attachment] => Array
                (
                    [type] => image
                    [payload] => Array
                        (
                            [url] => https://...
                        )

                )

        )

    [access_token] => ...
)

Sender Actions

Action types: mark_seen typing_on typing_off, (*10)

$response = $messenger->senderAction(<PSID>, '<ACTION_TYPE>');

Webhooks

This for require verify_token, (*11)

Config, (*12)

$messenger = new \FbMessengerBot\Messenger('<YOUR_ACCESS_TOKEN>', '<YOUR_VERIFY_TOKEN>');

Listen to user messages., (*13)

$response = $messenger->listen();

The Versions

11/03 2018

dev-master

9999999-dev https://github.com/samiaraboglu/fb-messenger-bot-php

  Sources   Download

MIT

The Requires

  • php >=5.5

 

php facebook messenger facebook-messenger facebook-messenger-bot

11/03 2018

1.6.5

1.6.5.0 https://github.com/samiaraboglu/fb-messenger-bot-php

  Sources   Download

MIT

The Requires

  • php >=5.5

 

php facebook messenger facebook-messenger facebook-messenger-bot

31/01 2018

1.5.0

1.5.0.0 https://github.com/samiaraboglu/fb-messenger-bot-php

  Sources   Download

MIT

The Requires

  • php >=5.5

 

php facebook messenger facebook-messenger facebook-messenger-bot

30/01 2018

1.4.0

1.4.0.0 https://github.com/samiaraboglu/fb-messenger-bot-php

  Sources   Download

MIT

The Requires

  • php >=5.5

 

php facebook messenger facebook-messenger facebook-messenger-bot

29/01 2018

1.3.0

1.3.0.0 https://github.com/samiaraboglu/fb-messenger-bot-php

  Sources   Download

MIT

The Requires

  • php >=5.5

 

php facebook messenger facebook-messenger facebook-messenger-bot

28/01 2018

1.2.0

1.2.0.0 https://github.com/samiaraboglu/fb-messenger-bot-php

  Sources   Download

MIT

The Requires

  • php >=5.5

 

php facebook messenger facebook-messenger facebook-messenger-bot

26/01 2018

1.1.0

1.1.0.0 https://github.com/samiaraboglu/fb-messenger-bot-php

  Sources   Download

MIT

The Requires

  • php >=5.5

 

php facebook messenger facebook-messenger facebook-messenger-bot

25/01 2018

1.0.0

1.0.0.0 https://github.com/samiaraboglu/fb-messenger-bot-php

  Sources   Download

MIT

The Requires

  • php >=5.5

 

php facebook messenger facebook-messenger facebook-messenger-bot

13/04 2017

0.1.0

0.1.0.0 https://github.com/samiaraboglu/fb-messenger-bot-php

  Sources   Download

MIT

The Requires

  • php >=5.5

 

php facebook messenger facebook-messenger facebook-messenger-bot