PHP code example of vohinc / laravel-botanalytics
1. Go to this page and download the library: Download vohinc/laravel-botanalytics 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/ */
vohinc / laravel-botanalytics example snippets
'providers' => [
...
Vohinc\LaravelBotanalytics\BotanalyticsServiceProvider::class,
...
]
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);
}
}
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'),
]);
}
}
shell
php artisan vendor:publish --provider=Vohinc\LaravelBotanalytics\BotanalyticsServiceProvider --tag=config