Package Data | |
---|---|
Maintainer Username: | casperlaitw |
Maintainer Contact: | casper.lai@sleepingdesign.com (Casper Lai) |
Package Create Date: | 2017-01-24 |
Package Last Update: | 2017-01-26 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-14 15:07:45 |
Package Statistics | |
---|---|
Total Downloads: | 23 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A Botanalytics Wrapper for Laravel
Botanalytics is a bot analytics service, improves Human-to-Bot interaction.
To get the latest version
composer require vohinc/laravel-botanalytics
Include the provider within config/app.php
'providers' => [
...
Vohinc\LaravelBotanalytics\BotanalyticsServiceProvider::class,
...
]
php artisan vendor:publish --provider=Vohinc\LaravelBotanalytics\BotanalyticsServiceProvider --tag=config
Add your botanalytics token to .env
BOTANALYTICS_TOKEN=botanalytics-token
<?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);
}
}
<?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'),
]);
}
}
This package is licensed under the MIT license.