PHP code example of whchi / laravel-linebot-wrapper

1. Go to this page and download the library: Download whchi/laravel-linebot-wrapper 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/ */

    

whchi / laravel-linebot-wrapper example snippets


return [
    'channel_access_token' => 'find it in your LINE console'
    'channel_secret' => 'find it in your LINE console'
];

$this->context->sdk('replyText', [$event['replyToken'], 'hello']);

public function __construct()
{
    $context = app('LINEBotContext');
}
...
public function entryPoint(Request $request)
{
    $lineMsg = $request->all();
    $events = collect($lineMsg['events']);
    $events->map(function($event) {
        $this->context->setContext($event);

        ... do whatever you want...
    });
}

// after setContext
event(new SaveLineBotSessionEvent($event));

$this->context->initState([
    'status' => 1,
    'isAuth' => ['departA' => true, 'departB' => false]
    ]);
// must execute after setContext
$this->context->buildState();

$this->context->setState(['status' => 2]);

$this->context->getState('isAuth.departA');

$this->context->resetState();

$this->context->setPushTo(string $userId|$groupId|$roomId);

$this->context->pushButtonTemplate(string $altText,array $template)

$this->context->pushConfirmTemplate(string $altText,array $template)

$this->context->pushCarouselTemplate(string $altText,array $template)

$this->context->pushImageCarouselTemplate(string $altText, array $template)

$this->context->pushAudio(array $template)

$this->context->pushVideo(array $template)

$this->context->pushImage(array $template)

$this->context->pushSticker(array $template)

$this->context->pushLocation(array $template)

$this->context->pushText(array $template)

$this->context->push(string $altText,array $templateList)

// max 150 user id
// @see https://developers.line.biz/en/reference/messaging-api/#send-multicast-message
$this->context->pushMulticast(array $memberIdList, string $altText, array $templateList)

$this->context->pushFlex(string $altText, array $flexTemplate)

$this->context->pushButtonTemplate(string $altText, $template + $quickReply);

$this->context->leave();

$this->context->isXXXXEvent();
// example
$this->context->isMessageEvent();
$this->context->isPostbackEvent();
...

$this->context->isXXXXMessage();
// example
$this->context->isTextMessage();
$this->context->isImageMessage();
...

$this->content->getMessagePayload();

$this->context->getPostbackPayload();
/**
 * $key = 'datetime' | 'date' | 'time'
 */
$this->context->getDateTimePostbackPayload(string $key);

$this->context->getUserProfile();

$this->context->getMessageStreamData();

$this->context->rawEvent;
$this->context->eventType;
$this->context->messageEventType;
$this->context->useId;
$this->context->botSessionId;
bash
php artisan vendor:publish --provider="Whchi\LaravelLineBotWrapper\LINEBotServiceProvider"