PHP code example of yamakadi / laravel-line-webhooks
1. Go to this page and download the library: Download yamakadi/laravel-line-webhooks 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/ */
yamakadi / laravel-line-webhooks example snippets
return [
/*
* You need to define your channel secret and access token in your environment variables
*/
'channel_id' => env('LINEBOT_CHANNEL_ID'),
'channel_secret' => env('LINEBOT_CHANNEL_SECRET'),
'channel_access_token' => env('LINEBOT_CHANNEL_ACCESS_TOKEN'),
/*
* You can define the job that should be run when a certain webhook hits your application
* here. The key is the name of the Line event in snake_case.
*
* You can find a list of Line webhook types here:
* https://developers.line.me/en/docs/messaging-api/reference/#webhook-event-objects
*/
'jobs' => [
// 'message' => \App\Jobs\LineWebhooks\HandleIncomingMessage::class,
// 'beacon' => \App\Jobs\LineWebhooks\HandleBeaconSignal::class,
],
/*
* The classname of the model to be used. The class should equal or extend
* Yamakadi\LineWebhooks\LineWebhookCall.
*/
'model' => Yamakadi\LineWebhooks\LineWebhookCall::class,
];
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Yamakadi\LineBot\Events\Event;
use Yamakadi\LineWebhooks\LineWebhookCall;
class HandleIncomingText implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/** @var \Yamakadi\LineBot\Events\Event */
public $event;
/** @var \Yamakadi\LineWebhooks\LineWebhookCall */
public $webhookCall;
public function __construct(Event $event, LineWebhookCall $webhookCall)
{
$this->event = $event;
$this->webhookCall = $webhookCall;
}
public function handle()
{
// do your work here
// you can access the payload of the webhook call with `$this->webhookCall->payload`
}
}
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'line-webhooks::message' => [
App\Jobs\LineWebhooks\HandleIncomingMessage::class,
],
];
namespace App\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Yamakadi\LineBot\Events\Event;
use Yamakadi\LineWebhooks\LineWebhookCall;
class ReplyWithQuote implements ShouldQueue
{
public function handle(Event $event, LineWebhookCall $webhookCall)
{
// do your work here
// you can access the payload of the webhook call with `$webhookCall->payload`
}
}