samiaraboglu / fb-messenger-bot-php
Installs: 25 214
Dependents: 1
Suggesters: 0
Security: 0
Stars: 10
Watchers: 3
Forks: 6
Open Issues: 0
Requires
- php: >=5.5
This package is auto-updated.
Last update: 2024-12-29 05:21:49 UTC
README
Installing
Via composer
$ composer require samiaraboglu/fb-messenger-bot-php
Config
$messenger = new \FbMessengerBot\Messenger('<YOUR_ACCESS_TOKEN>');
Conversation Components
Use the message class
$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' ], [ ... ], [...] ]);
// simple $message->email('<MESSAGE_TEXT>');
// multiple $message->quickReplies('<MESSAGE_TEXT>', [ [ 'type' => 'user_email' ], [ ... ], [...] ]);
Send Message
Require page-scoped ID (PSID)
$response = $messenger->send(<PSID>, $message);
Example response
// 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
$message->image('<URL.jpg>', true);
Example response
// response print Array ( [recipient_id] => <PSID> [message_id] => mid.$cAAcZdzlzwkxoQ6ss8ViEmxxxxxx [attachment_id] => 1200933831599999 )
Send message with attachment_id
$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
$response = $messenger->senderAction(<PSID>, '<ACTION_TYPE>');
Webhooks
This for require verify_token
Config
$messenger = new \FbMessengerBot\Messenger('<YOUR_ACCESS_TOKEN>', '<YOUR_VERIFY_TOKEN>');
Listen to user messages.
$response = $messenger->listen();