PHP code example of casperlaitw / laravel-fb-messenger
1. Go to this page and download the library: Download casperlaitw/laravel-fb-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/ */
casperlaitw / laravel-fb-messenger example snippets
namespace App;
use Casperlaitw\LaravelFbMessenger\Contracts\BaseHandler;
use Casperlaitw\LaravelFbMessenger\Messages\ReceiveMessage;
use Casperlaitw\LaravelFbMessenger\Messages\Text;
class DefaultHandler extends BaseHandler
{
/**
* handle method is
namespace App;
use Casperlaitw\LaravelFbMessenger\Contracts\PostbackHandler;
use Casperlaitw\LaravelFbMessenger\Messages\ReceiveMessage;
use Casperlaitw\LaravelFbMessenger\Messages\Text;
class StartupPostback extends PostbackHandler
{
// If webhook get the $payload is `USER_DEFINED_PAYLOAD` will run this postback handler
protected $payload = 'USER_DEFINED_PAYLOAD'; // You also can use regex!
/**
* Handle the chatbot message
*
* @param ReceiveMessage $message
*
* @return mixed
*/
public function handle(ReceiveMessage $message)
{
$this->send(new Text($message->getSender(), "I got your payload"));
}
}