Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Line Api Laravel Laravel Package

chitanok/line-api-laravel

Laravel package for building simple LINE Messaging API bots. Provides a service provider and basic setup to send and receive LINE messages and create a lightweight bot for notifications or customer interactions.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require chitanok/line-api-laravel
    

    Publish the config file:

    php artisan vendor:publish --provider="Chitanok\LineApiLaravel\LineServiceProvider" --tag="config"
    
  2. Configuration Edit .env with your LINE Developer credentials:

    LINE_CHANNEL_SECRET=your_channel_secret
    LINE_CHANNEL_ACCESS_TOKEN=your_channel_access_token
    LINE_BOT_ID=your_bot_id
    LINE_BOT_SECRET=your_bot_secret
    
  3. First Use Case: Webhook Setup Add the middleware to routes/web.php:

    Route::post('/line-webhook', [LineWebhookController::class, 'handle']);
    

    Register the webhook URL in the LINE Developers Console.

  4. Sending a Simple Message

    use Chitanok\LineApiLaravel\Facades\Line;
    
    Line::sendMessage('User ID', 'Hello from Laravel!');
    

Implementation Patterns

Core Workflows

  1. Handling Incoming Events Extend LineWebhookController to process events:

    public function handle(Request $request)
    {
        $events = Line::parseEvents($request->getContent());
    
        foreach ($events as $event) {
            if ($event->type === 'message') {
                $this->handleMessage($event);
            }
        }
    }
    
  2. Rich Message Responses Use built-in message types:

    Line::sendMessage('user123', [
        'type' => 'flex',
        'altText' => 'Flex Message',
        'contents' => ['type' => 'bubble', ...],
    ]);
    
  3. User Management Fetch user profiles:

    $user = Line::getProfile('user123');
    
  4. Broadcasting to Groups

    Line::sendMessage('group123', 'Hello group!');
    

Integration Tips

  • Middleware: Use LineAuthMiddleware to validate requests in protected routes.
  • Events: Bind to line.event for global event handling:
    event(new LineEvent($event));
    
  • Queue Jobs: Offload responses to LineMessageJob for async processing:
    dispatch(new LineMessageJob('user123', 'Delayed message'));
    

Gotchas and Tips

Common Pitfalls

  1. Webhook Verification

    • Always validate X-Line-Signature in production:
      if (!Line::validateSignature($request->header('X-Line-Signature'), $request->getContent())) {
          abort(401);
      }
      
    • Test locally with LINE_DEBUG=true in .env.
  2. Rate Limits

    • LINE API enforces rate limits. Cache frequent requests.
  3. Message Failures

    • Implement retry logic for failed messages using Line::sendMessage()’s options:
      Line::sendMessage('user123', 'Message', ['retry' => 3]);
      
  4. Flex Message Bubble Validation

Debugging

  • Enable debug mode in .env:
    LINE_DEBUG=true
    
  • Log raw events for inspection:
    \Log::debug('LINE Event', ['event' => $event->toArray()]);
    

Extension Points

  1. Custom Event Handlers Override LineEvent to add custom logic:

    class CustomLineEvent extends LineEvent {
        public function handle()
        {
            if ($this->type === 'sticker') {
                // Custom sticker logic
            }
        }
    }
    
  2. Provider Extensions Bind custom services in AppServiceProvider:

    $this->app->bind('line.custom', function () {
        return new CustomLineService();
    });
    
  3. Template Messages Use Line::sendTemplateMessage() for pre-designed templates (e.g., confirmations):

    Line::sendTemplateMessage('user123', 'template_id', ['key' => 'value']);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor