liberalu / facebookbot
Facebook bot. Auto reply message, show products, show menu, send message
dev-master
2016-08-23 15:33 UTC
Requires
- php: >=5.6.0
- guzzlehttp/guzzle: *
- guzzlehttp/psr7: *
This package is not auto-updated.
Last update: 2024-12-30 14:09:29 UTC
README
#Facebook Messenger Bot library for PHP
PHP client for Facebook Messenger Bot API.
You can read more official documentation about API.
##Install
composer require "liberalu/facebookbot" "dev-master"
##Example
Answer to message
<?php
use FacebookBot\FacebookBot;
use FacebookBot\Webhook\Request;
use FacebookBot\Send\TextMessage;
$secretKey = 'YOUR_SECRET_KEY';
$apiSecret = 'YOUR_API_SECRET';
$data = json_decode(file_get_contents("php://input"), true);
$request = new Request($data, $apiSecret);
if ($request->getMessage()->getType() === Request::TEXT
&& substr($request->getMessage()->getTextMessage(), 0, 4) === 'echo'
) {
$fbBot = new FacebookBot($secretKey);
$sendMessage = new TextMessage();
$sendMessage->setText($request->getMessage()->getTextMessage());
$sendMessage->setRecipientId($request->getMessage()->getSenderId());
$fbBot->sendMessage($sendMessage);
}