dev-master
9999999-devLumen/Laravel package for developing facebook messenger chat bot
MIT
The Requires
The Development Requires
by Hung Neo
bot facebook messenger laravel-package lumen-package
Lumen/Laravel package for developing facebook messenger chat bot
A Laravel/Lumen package for developing facebook messenger chat bot, (*2)
Run the following command to install the package through Composer:, (*3)
composer require composer require hungneox/ramen-messenger
Add these environment variables to your .env, (*4)
FACEBOOK_PAGE_ID=<YOUR_FACEBOOK_PAGE_ID> FACEBOOK_VERIFY_TOKEN=<TOKEN_FOR_VERIFY_YOUR_BOT> FACEBOOK_ACCESS_TOKEN=<YOUR_FACEBOOK_PAGE_ACCESS_TOKEN>
Copy the configuration template in config/facebook.php to your application's config directory and modify it to suit your needs., (*5)
Add the following line to bootstrap/app.php:, (*6)
$app->register(\Neox\Ramen\Messenger\MessengerServiceProvider::class);
To configure the webhook for your app, adding a route for facebook verification, (*7)
$router->get('/webhook', [ 'as' => 'webhook.index', 'uses' => 'WebHookController@index' ]);
/** * For facebook verification * * @param Request $request */ public function index(Request $request) { if ($request->get('hub_verify_token') === config('facebook.verify_token')) { return $request->get('hub_challenge'); } return 'Wrong verification token!'; }
/** @var RamenBot $bot */ $bot = app(RamenBot::class); $bot->hears('hello', function(RamenBot $bot) { $bot->replies('greeting from the bot!'); });
, (*8)
$template = (new TextTemplate($sender, 'Please share your location')) ->addQuickReply( (new QuickReply())->setContentType('location') );
, (*9)
$template = (new ButtonTemplate()) ->setRecipientId($sender) ->setText('What do you want to do next?') ->addButton( (new UrlButton()) ->setUrl('https://www.messenger.com') ->setTitle('Get Order Status') )->addButton( (new UrlButton()) ->setUrl('https://www.messenger.com') ->setTitle('Call Me') );
// Reply the button template when the bot hears `help` /** @var RamenBot $bot */ $bot = app(RamenBot::class); $bot->hears('help', function(RamenBot $bot) use ($template) { $bot->sends($template); });
, (*10)
$tempalte = (new OpenGraphTemplate()) ->addElement( (new OpenGraphElement()) ->setUrl('https://open.spotify.com/track/7GhIk7Il098yCjg4BQjzvb') ->addButton( (new UrlButton()) ->setUrl('https://en.wikipedia.org/wiki/Rickrolling') ->setTitle('View More') ) )->setRecipientId($sender);
, (*11)
// Implements the getMenu() method from SetPersistentMenuCommand abstract class public function getMenu() { return (new PersistentMenu()) ->addMenu( (new Menu())->addItem( (new Menu()) ->setType('nested') ->setTitle('My Account') ->addItem( (new PostBackButton()) ->setTitle('Pay Bill') ->setPayload('PAYBILL_PAYLOAD') )->addItem( (new PostBackButton()) ->setTitle('History') ->setPayload('HISTORY_PAYLOAD') )->addItem( (new PostBackButton()) ->setTitle('Contact Info') ->setPayload('CONTACT_INFO_PAYLOAD') ) )->addItem( (new UrlButton()) ->setTitle('Latest News') ->setUrl('https://yle.fi/uutiset/osasto/news/') ) )->addMenu( (new Menu())->addItem( (new UrlButton()) ->setTitle('Latest News FI') ->setUrl('https://yle.fi/uutiset') )->setLocale('fi_FI') ); }
See LICENSE, (*12)
Lumen/Laravel package for developing facebook messenger chat bot
MIT
bot facebook messenger laravel-package lumen-package