pharit / laravel-line-api
A Laravel package for LINE Messaging API (push, reply, multicast, signature verification).
dev-main
2025-08-11 11:03 UTC
Requires
- php: ^8.1|^8.2|^8.3
- illuminate/contracts: ^10.0|^11.0
- illuminate/http: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
This package is auto-updated.
Last update: 2025-08-11 11:07:00 UTC
README
A lightweight Laravel package for LINE Messaging API: push, reply, multicast, broadcast, profile lookup, and webhook signature verification.
Install (local path)
- Add to your app's
composer.json
repositories:
"repositories": [ { "type": "path", "url": "../laravel-line-api", "options": { "symlink": true } } ]
- Require the package in your app:
composer require iaa/laravel-line-api:dev-main
- Publish config:
php artisan vendor:publish --tag=config --provider="Pharit\\LaravelLineApi\\LaravelLineApiServiceProvider"
- Set env vars:
LINE_CHANNEL_ACCESS_TOKEN=your_channel_access_token LINE_CHANNEL_SECRET=your_channel_secret
Usage
use Pharit\\LaravelLineApi\\Facades\\Line; // Reply Line::reply($replyToken, [ Line::textMessage('Hello!'), ]); // Push Line::push($userId, [ ['type' => 'text', 'text' => 'Update available'], ]); // Multicast Line::multicast([$userId1, $userId2], [ ['type' => 'text', 'text' => 'Hello all'], ]); // Broadcast Line::broadcast([ ['type' => 'text', 'text' => 'System maintenance 10pm'], ]); // Profile $profile = Line::getProfile($userId)->json();
Rich menu
use Pharit\\LaravelLineApi\\Facades\\Line; // Create $response = Line::createRichMenu([ 'size' => ['width' => 2500, 'height' => 843], 'selected' => false, 'name' => 'My Menu', 'chatBarText' => 'Tap here', 'areas' => [ [ 'bounds' => ['x' => 0, 'y' => 0, 'width' => 1250, 'height' => 843], 'action' => ['type' => 'message', 'text' => 'Hello'], ], [ 'bounds' => ['x' => 1250, 'y' => 0, 'width' => 1250, 'height' => 843], 'action' => ['type' => 'uri', 'uri' => 'https://example.com'], ], ], ]); $richMenuId = $response->json('richMenuId'); // Upload image (path). Content-Type auto-detected from extension Line::uploadRichMenuImage($richMenuId, storage_path('app/menu.png')); // Link to a user Line::linkRichMenuToUser($userId, $richMenuId); // Set as default for all users Line::setDefaultRichMenu($richMenuId); // List $list = Line::getRichMenuList()->json('richmenus');
Verify webhook signatures
Add middleware to your webhook route to validate X-Line-Signature
:
use Pharit\\LaravelLineApi\\Http\\Middleware\\VerifyLineSignature; Route::post('/line/webhook', Controller::class) ->middleware(VerifyLineSignature::class);
Disable via LINE_VERIFY_SIGNATURE=false
if needed.
Configuration
See config/line.php
after publish.
License
MIT