vohinc / laravel-botanalytics
A Botanalytics Wrapper for Laravel
v1.0.0
2017-01-26 02:48 UTC
Requires
- illuminate/support: ~5.1
- vohinc/botanalytics-php: ^0.1
Requires (Dev)
- nesbot/carbon: ^1.22
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2024-10-26 03:55:49 UTC
README
A Botanalytics Wrapper for Laravel
Botanalytics is a bot analytics service, improves Human-to-Bot interaction.
Install
Composer
To get the latest version
composer require vohinc/laravel-botanalytics
Add Provider
Include the provider within config/app.php
'providers' => [ ... Vohinc\LaravelBotanalytics\BotanalyticsServiceProvider::class, ... ]
Publish Configuration
php artisan vendor:publish --provider=Vohinc\LaravelBotanalytics\BotanalyticsServiceProvider --tag=config
Config
Set Botanalytics Token
Add your botanalytics token to .env
BOTANALYTICS_TOKEN=botanalytics-token
Usage
Incoming Message
<?php namespace App; use Vohinc\LaravelBotanalytics\BotanalyticsFacade; use Closure; class BotAnalyticsMiddleware { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $body = $request->all(); if (array_get($body, 'object') === 'page') { BotanalyticsFacade::facebook()->request([ 'recipient' => null, 'message' => $body, ]); } return $next($request); } }
Out-going Message
<?php namespace App; use Vohinc\LaravelBotanalytics\BotanalyticsFacade; use Illuminate\Http\Request; class WebhookController extends Controller { public function request(Request $request) { $message = [ 'recipient' => [ 'id' => 'Sender ID', ], 'message' => [ 'text' => 'hello, world!', ], ]; // response $message to Facebook // Send to botanalytics BotanalyticsFacade::facebook()->request([ 'recipient' => array_get($message, 'recipient.id'), 'message' => array_get($message, 'message'), ]); } }
License
This package is licensed under the MIT license.