laravel-line-api maintained by pharit
Laravel LINE API
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.jsonrepositories:
"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