- How do I install linecorp/line-bot-sdk in a Laravel project?
- Install it with Composer using composer require linecorp/line-bot-sdk. The SDK requires PHP 8.2 or later, so confirm your Laravel runtime meets that before adding it. After installation, configure your channel access token and create a Guzzle client plus a MessagingApiApi instance. In Laravel you can bind these in a service provider or use the package's facade and dependency injection support.
- Does linecorp/line-bot-sdk support Laravel and which PHP version is required?
- Yes, the SDK works well with Laravel because it is framework-agnostic and exposes generated API classes you can resolve from the container. It requires PHP 8.2 or later, which aligns with modern Laravel releases. Laravel integration is supported through a service provider and a \LINEMessagingApi facade, while direct injection of MessagingApiApi is also possible.
- How do I send a LINE reply or push message using the PHP SDK?
- Create a Guzzle HTTP client and a \LINE\Clients\MessagingApi\Configuration with your channel access token, then instantiate MessagingApiApi. Build a TextMessage and a ReplyMessageRequest with the reply token, and call replyMessage. The SDK also supports setter-style request construction and typed message models for push and other messaging endpoints.
- How do I handle LINE webhook events in a Laravel application?
- Use EventRequestParser to parse and validate incoming LINE webhook payloads, then map the parsed events to Laravel routes or middleware. You can dispatch each event as a Laravel event for decoupled listeners and queued jobs. This keeps the webhook controller thin and lets you handle message, follow, and other event types separately.
- Is there a Laravel facade for linecorp/line-bot-sdk?
- Yes, the package's Laravel integration includes a \LINEMessagingApi facade and a service provider to keep container binding simple. You can also inject the generated MessagingApiApi class directly when you prefer constructor injection. Both approaches work with Laravel's service container and make testing easier.
- How can I test LINE bot code in Laravel without calling the real LINE API?
- Because MessagingApiApi can be injected, you can mock or fake it in unit and feature tests rather than sending real HTTP requests. For lower-level tests, provide a fake GuzzleHttp\ClientInterface implementation to the API class. Use the ~WithHttpInfo methods when you need to assert response headers such as x-line-request-id alongside status codes.
- What is the Partner Messaging Channel PNP templated API in line-bot-sdk v12.8.0?
- Version 12.8.0 adds the partner-gated templated LINE notification message API for sending templated PNP messages to hashed phone numbers. It includes PnpTemplatedMessageRequest and related model classes, delivery statistics, and custom aggregation units for templated and flexible PNP messages. It requires a pre-registered templateKey in the LINE partner console and partner approval before end-to-end testing.
- How do I get the x-line-request-id header from the LINE SDK response?
- Call the ~WithHttpInfo variant of the API method instead of the plain method. It returns the response body together with headers and the status code, so you can read x-line-request-id or x-line-accepted-request-id and store them for support and debugging. This is useful when logging LINE API calls in production.
- What are the dependency risks of linecorp/line-bot-sdk v12.8.0 with Guzzle PSR-7 v3?
- The release bumps guzzlehttp/psr7 to v3 and updates the OpenAPI generator, which can conflict with packages still pinned to PSR-7 v1 or v2. Run composer update --dry-run in your Laravel project to check for resolution conflicts before upgrading. Minor generator bumps can also introduce class-shape changes, so test the SDK integration after updating.
- Is linecorp/line-bot-sdk the official LINE SDK for PHP and is it production-ready?
- Yes, it is the official LINE Messaging API SDK for PHP, published by LINE and backed by official API documentation and PHPDoc. It is suitable for production LINE bots and includes Guzzle-based HTTP handling, typed request and response models, and error handling via ApiException. The v12.8.0 release is a minor update that does not remove existing push, reply, or webhook behavior.