PHPackages                             whchi/laravel-linebot-wrapper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. whchi/laravel-linebot-wrapper

ActiveLibrary[API Development](/categories/api)

whchi/laravel-linebot-wrapper
=============================

A simple laravel wrapper for linecorp/line-bot-sdk

3.0.0(4y ago)1157MITPHPPHP &gt;=7

Since Apr 21Pushed 4y ago1 watchersCompare

[ Source](https://github.com/whchi/laravel-linebot-wrapper)[ Packagist](https://packagist.org/packages/whchi/laravel-linebot-wrapper)[ RSS](/packages/whchi-laravel-linebot-wrapper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (10)Used By (0)

[![](https://camo.githubusercontent.com/87b440a82d0208dde337826292b567b193853e3fa7ce78099a408200a5712c07/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77686368692f6c61726176656c2d6c696e65626f742d777261707065723f7374796c653d666c61742d73717561726526636f6c6f723d6e617679)](https://camo.githubusercontent.com/87b440a82d0208dde337826292b567b193853e3fa7ce78099a408200a5712c07/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77686368692f6c61726176656c2d6c696e65626f742d777261707065723f7374796c653d666c61742d73717561726526636f6c6f723d6e617679) [![](https://camo.githubusercontent.com/95544f7c0c1c6759757bc3df47710cd35155f6a6ef67b23caf6d7110c6301f76/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77686368692f6c61726176656c2d6c696e65626f742d777261707065723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/95544f7c0c1c6759757bc3df47710cd35155f6a6ef67b23caf6d7110c6301f76/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77686368692f6c61726176656c2d6c696e65626f742d777261707065723f7374796c653d666c61742d737175617265) [![](https://camo.githubusercontent.com/1ce1a6849e2331b720109ab9a628d6172b455689cab13b803a07dae001005d84/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f77686368692f6c61726176656c2d6c696e65626f742d777261707065723f7374796c653d666c61742d73717561726526636f6c6f723d626c7565)](https://camo.githubusercontent.com/1ce1a6849e2331b720109ab9a628d6172b455689cab13b803a07dae001005d84/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f77686368692f6c61726176656c2d6c696e65626f742d777261707065723f7374796c653d666c61742d73717561726526636f6c6f723d626c7565)

A simple wrapper of `linecorp/line-bot-sdk`

Inspired by [bottener.js](https://github.com/Yoctol/bottender)

Installation
============

[](#installation)

1. composer install

```
composer require whchi/laravel-linebot-wrapper
```

2. publish vendor

```
php artisan vendor:publish --provider="Whchi\LaravelLineBotWrapper\LINEBotServiceProvider"
```

3. setup config `config/linebot.php`

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

4. run migration: create a table named `line_bot_sessions`
5. start use, see sample in [app sample](https://github.com/whchi/laravel-linebot-wrapper/tree/master/samples/app)

> remember to remove VerifyCsrfToken for line route

Usage
=====

[](#usage)

sdk functions
-------------

[](#sdk-functions)

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

Initialize
----------

[](#initialize)

In your webhook entry point

```
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...
    });
}
```

Remember bot session
--------------------

[](#remember-bot-session)

Use event queue is recommended, see [app samples](https://github.com/whchi/laravel-linebot-wrapper/tree/master/samples/app)

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

State handling
--------------

[](#state-handling)

Need Redis running in your enviorment

- init state

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

- set state

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

- get state

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

- reset state

```
$this->context->resetState();
```

Messages handling
-----------------

[](#messages-handling)

see [message samples](https://github.com/whchi/laravel-linebot-wrapper/tree/master/samples/message) for $template

### push API

[](#push-api)

**Make sure your account have PUSH\_API permission**

set userId before use push function

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

- button

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

- confirm

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

- carousel

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

- image carousel

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

- audio

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

- video

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

- image

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

- sticker

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

- location

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

- text

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

- #### multiple messages

    [](#multiple-messages)

Maximum size of `$templateList` is 5, so as reply

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

- #### multiple users

    [](#multiple-users)

```
// 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)
```

- #### flex

    [](#flex)

Maximum size of carousel flex message is 10, more detail: [official doc](https://developers.line.biz/en/docs/messaging-api/using-flex-messages/)

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

- quickReply see $quickReply example at [message samples](https://github.com/whchi/laravel-linebot-wrapper/tree/master/samples/message)

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

### reply API

[](#reply-api)

Change `pushXXXX` to `replyXXXX` without setting userId, that is.

### Leave API

[](#leave-api)

```
$this->context->leave();
```

### other usage

[](#other-usage)

- detect event
    more detail see [official doc](https://developers.line.biz/en/reference/messaging-api/#message-event)

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

- detect message event type

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

- get message event message

```
$this->content->getMessagePayload();
```

- get postback data

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

- get user profile
    more detail see [official doc](https://developers.line.biz/en/reference/messaging-api/#get-profile)

```
$this->context->getUserProfile();
```

- get streaming data(audio / video / image)

```
$this->context->getMessageStreamData();
```

- accessable attributes

```
$this->context->rawEvent;
$this->context->eventType;
$this->context->messageEventType;
$this->context->useId;
$this->context->botSessionId;
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~101 days

Recently: every ~201 days

Total

9

Last Release

1768d ago

Major Versions

1.2.1 → 2.0.02020-03-04

2.0.0 → 3.0.02021-07-07

PHP version history (2 changes)2.0.0PHP ^7.2

3.0.0PHP &gt;=7

### Community

Maintainers

![](https://www.gravatar.com/avatar/2dc92c7e48b95b84282bf4c3bc9f04eef31bd8117484fe862812082c55217026?d=identicon)[whchi](/maintainers/whchi)

---

Top Contributors

[![owwwwwchi](https://avatars.githubusercontent.com/u/75598441?v=4)](https://github.com/owwwwwchi "owwwwwchi (5 commits)")[![whchi](https://avatars.githubusercontent.com/u/11798731?v=4)](https://github.com/whchi "whchi (1 commits)")

---

Tags

laravelwrapperchatbotline

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/whchi-laravel-linebot-wrapper/health.svg)

```
[![Health](https://phpackages.com/badges/whchi-laravel-linebot-wrapper/health.svg)](https://phpackages.com/packages/whchi-laravel-linebot-wrapper)
```

###  Alternatives

[codedredd/laravel-soap

A SoapClient wrapper integration for Laravel

221516.6k3](/packages/codedredd-laravel-soap)[casperlaitw/laravel-fb-messenger

A Laravel Package to Integrate Facebook Messenger API

10631.5k](/packages/casperlaitw-laravel-fb-messenger)[revolution/laravel-line-sdk

LINE SDK for Laravel

2235.8k](/packages/revolution-laravel-line-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
