PHPackages                             linecorp/line-bot-sdk - 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. linecorp/line-bot-sdk

ActiveLibrary[API Development](/categories/api)

linecorp/line-bot-sdk
=====================

SDK of the LINE BOT API for PHP

v12.6.0(2d ago)7413.2M↓33.4%647[2 issues](https://github.com/line/line-bot-sdk-php/issues)20Apache-2.0PHPPHP ^8.2CI passing

Since Apr 27Pushed 1w ago89 watchersCompare

[ Source](https://github.com/line/line-bot-sdk-php)[ Packagist](https://packagist.org/packages/linecorp/line-bot-sdk)[ Docs](https://github.com/line/line-bot-sdk-php)[ RSS](/packages/linecorp-line-bot-sdk/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (22)Versions (121)Used By (20)

LINE Messaging API SDK for PHP
==============================

[](#line-messaging-api-sdk-for-php)

[![Build Status](https://github.com/line/line-bot-sdk-php/actions/workflows/php-checks.yml/badge.svg?branch=master)](https://github.com/line/line-bot-sdk-php/actions)[![Packagist Version](https://camo.githubusercontent.com/ea75951ab040114b4d80be792bca1b927459e3ca00325cc9430b9129ac5557c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c696e65636f72702f6c696e652d626f742d73646b)](https://packagist.org/packages/linecorp/line-bot-sdk)

Introduction
------------

[](#introduction)

The LINE Messaging API SDK for PHP makes it easy to develop bots using LINE Messaging API, and you can create a sample bot within minutes.

Documentation
-------------

[](#documentation)

See the official API documentation for more information.

- English:
- Japanese:

PHPDoc

-

Requirements
------------

[](#requirements)

- PHP 8.2 or later

Installation
------------

[](#installation)

Install the LINE Messaging API SDK using [Composer](https://getcomposer.org/).

```
$ composer require linecorp/line-bot-sdk

```

Getting started
---------------

[](#getting-started)

### Create the bot client instance

[](#create-the-bot-client-instance)

The bot client instance is a handler of the Messaging API.

```
$client = new \GuzzleHttp\Client();
$config = new \LINE\Clients\MessagingApi\Configuration();
$config->setAccessToken('');
$messagingApi = new \LINE\Clients\MessagingApi\Api\MessagingApiApi(
  client: $client,
  config: $config,
);
```

You must use the Client with `GuzzleHttp\ClientInterface` implementation.

### Call API

[](#call-api)

You can call an API through the messagingApi instance.

A very simple example:

```
$message = new TextMessage(['text' => 'hello!']);
$request = new ReplyMessageRequest([
    'replyToken' => '',
    'messages' => [$message],
]);
$response = $messagingApi->replyMessage($request);
```

This procedure sends a message to the destination that is associated with ``.

We also support setter style.

```
$message = (new TextMessage())
  ->setText('hello!');
$request = (new ReplyMessageRequest)
  ->setReplyToken('')
  ->setMessages([$message]);
try {
  $messagingApi->replyMessage($request);
  // Success
} catch (\LINE\Clients\MessagingApi\ApiException $e) {
  // Failed
  echo $e->getCode() . ' ' . $e->getResponseBody();
}
```

How to get x-line-request-id header and error message
-----------------------------------------------------

[](#how-to-get-x-line-request-id-header-and-error-message)

You may need to store the `x-line-request-id` header obtained as a response from several APIs. In this case, please use `~WithHttpInfo` functions. You can get headers and status codes. The `x-line-accepted-request-id` or `content-type` header can also be obtained in the same way.

```
$request = new ReplyMessageRequest([
    'replyToken' => $replyToken,
    'messages' => [$textMessage = (new TextMessage(['text' => 'reply with http info']))],
]);
$response = $messagingApi->replyMessageWithHttpInfo($request);
$this->logger->info('body:' . $response[0]);
$this->logger->info('http status code:' . $response[1]);
$this->logger->info('headers(x-line-request-id):' . $response[2]['x-line-request-id'][0]);
```

You can get error messages from `\LINE\Clients\MessagingApi\ApiException` when you use `MessagingApiApi`. Each client defines its own exception class.

```
try {
    $profile = $messagingApi->getProfile("invalid-userId");
} catch (\LINE\Clients\MessagingApi\ApiException $e) {
    $headers = $e->getResponseHeaders();
    $lineRequestId = isset($headers['x-line-request-id']) ? $headers['x-line-request-id'][0] : 'Not Available';
    $httpStatusCode = $e->getCode();
    $errorMessage = $e->getResponseBody();

    $this->logger->info("x-line-request-id: $lineRequestId");
    $this->logger->info("http status code: $httpStatusCode");
    $this->logger->info("error response: $errorMessage");
}
```

When you need to get `x-line-accepted-request-id` header from error response, you can get it: `$headers['x-line-accepted-request-id'][0]`.

Components
----------

[](#components)

### Webhook

[](#webhook)

LINE's server sends user actions (such as a message, image, or location) to your bot server. Request of that contains event(s); event is action of the user.

The following shows how the webhook is handled:

1. Receive webhook from LINE's server.
2. Parse request payload by `EventRequestParser#parseEventRequest($body, $channelSecret, $signature)`.
3. Iterate parsed events and some react as you like.

The following examples show how webhooks are handled:

- [EchoBot: Route.php](/examples/EchoBot/src/LINEBot/EchoBot/Route.php)
- [KitchenSink: Route.php](/examples/KitchenSink/src/LINEBot/KitchenSink/Route.php)

More information
----------------

[](#more-information)

For more information, see the [official API documents](#documentation) and PHPDoc. If it's your first time using this library, we recommend taking a look at `examples` and the PHPDoc of `\LINE` .

Hints
-----

[](#hints)

### Examples

[](#examples)

This repository contains two examples of how to use the LINE Messaging API.

#### [EchoBot](/examples/EchoBot)

[](#echobot)

A simple sample implementation. This application reacts to text messages that are sent from users.

#### [KitchenSink](/examples/KitchenSink)

[](#kitchensink)

A full-stack (and slightly complex) sample implementation. This application demonstrates a practical use of the LINE Messaging API.

### PHPDoc

[](#phpdoc)

This library provides PHPDoc to describe how to use the methods. You can generate the documentation using phpDocumenter using the following command.

$ wget $ php phpDocumentor.phar run -d src -t docs The HTML files are generated in docs/.

### Official API documentation

[](#official-api-documentation)

[Official API documents](#documentation) shows the detail of Messaging API and fundamental usage of SDK.

See also
--------

[](#see-also)

### Laravel Support

[](#laravel-support)

Easy to use from Laravel. After installed, add `LINE_BOT_CHANNEL_ACCESS_TOKEN` to `.env`

```
LINE_BOT_CHANNEL_ACCESS_TOKEN=

```

then you can use facades like following.

```
$profile = \LINEMessagingApi::pushMessage(....);

```

Facade uses `\GuzzleHttp\Client` by default. If you want to change the config, run

```
$ php artisan vendor:publish --provider="LINE\Laravel\LINEBotServiceProvider" --tag=config
```

Then `line-bot.php` will be published to `config/` dir. If you want to configure a custom header, do the following.

```
return [
    'channel_access_token' => env('LINE_BOT_CHANNEL_ACCESS_TOKEN'),
    'channel_id' => env('LINE_BOT_CHANNEL_ID'),
    'channel_secret' => env('LINE_BOT_CHANNEL_SECRET'),
    'client' => [
        'config' => [
          'headers' => ['X-Foo' => 'Bar'],
        ],
    ],
];
```

Help and media
--------------

[](#help-and-media)

FAQ:

News:

Versioning
----------

[](#versioning)

This project respects semantic versioning.

- See

However, if a feature that was publicly released is discontinued for business reasons and becomes completely unusable, we will release changes as a patch release.

Contributing
------------

[](#contributing)

Please check [CONTRIBUTING](CONTRIBUTING.md) before making a contribution.

For hacking instructions, please refer [HACKING.md](/HACKING.md).

License
-------

[](#license)

```
Copyright 2016 LINE Corporation

Licensed under the Apache License, version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

```

###  Health Score

81

—

ExcellentBetter than 100% of packages

Maintenance99

Actively maintained with recent releases

Popularity68

Solid adoption and visibility

Community51

Growing community involvement

Maturity93

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~36 days

Recently: every ~61 days

Total

103

Last Release

2d ago

Major Versions

7.6.1 → 8.0.02023-05-18

8.1.0 → 9.0.02023-08-01

9.12.0 → v10.0.02024-12-26

v10.3.0 → v11.0.02025-03-26

v11.4.0 → v12.0.02025-10-22

PHP version history (7 changes)0.0.1PHP &gt;=5.4

1.0.0PHP &gt;=5.6

3.0.0PHP &gt;=5.5

7.6.0PHP &gt;=7.2

8.0.0PHP &gt;=8.1

v11.2.0PHP ^8.1

v12.5.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/9f0c869f2309b1ce3d94c68d73456e1171cb0720e05026ee288c2f1aaf94a2f0?d=identicon)[Vaduz](/maintainers/Vaduz)

![](https://www.gravatar.com/avatar/d1cf7d041852357b4cbd39c523156762d66a6447116029801fcc7a75b0ebc455?d=identicon)[satosby](/maintainers/satosby)

![](https://avatars.githubusercontent.com/u/16463693?v=4)[moririnson](/maintainers/moririnson)[@moririnson](https://github.com/moririnson)

---

Top Contributors

[![moririnson](https://avatars.githubusercontent.com/u/16463693?v=4)](https://github.com/moririnson "moririnson (354 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (214 commits)")[![Vaduz](https://avatars.githubusercontent.com/u/69694?v=4)](https://github.com/Vaduz "Vaduz (110 commits)")[![moznion](https://avatars.githubusercontent.com/u/1422834?v=4)](https://github.com/moznion "moznion (103 commits)")[![Yang-33](https://avatars.githubusercontent.com/u/24933664?v=4)](https://github.com/Yang-33 "Yang-33 (62 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (40 commits)")[![hinoguma](https://avatars.githubusercontent.com/u/42476086?v=4)](https://github.com/hinoguma "hinoguma (28 commits)")[![snmatsui](https://avatars.githubusercontent.com/u/10430686?v=4)](https://github.com/snmatsui "snmatsui (26 commits)")[![nanato12](https://avatars.githubusercontent.com/u/49806926?v=4)](https://github.com/nanato12 "nanato12 (26 commits)")[![eucyt](https://avatars.githubusercontent.com/u/63095160?v=4)](https://github.com/eucyt "eucyt (24 commits)")[![itsuki-hayashi](https://avatars.githubusercontent.com/u/2121340?v=4)](https://github.com/itsuki-hayashi "itsuki-hayashi (12 commits)")[![vocolboy](https://avatars.githubusercontent.com/u/6601427?v=4)](https://github.com/vocolboy "vocolboy (9 commits)")[![kiwi-26](https://avatars.githubusercontent.com/u/5287568?v=4)](https://github.com/kiwi-26 "kiwi-26 (8 commits)")[![tokuhirom](https://avatars.githubusercontent.com/u/21084?v=4)](https://github.com/tokuhirom "tokuhirom (7 commits)")[![parsilver](https://avatars.githubusercontent.com/u/4928451?v=4)](https://github.com/parsilver "parsilver (4 commits)")[![TyperEJ](https://avatars.githubusercontent.com/u/42922266?v=4)](https://github.com/TyperEJ "TyperEJ (4 commits)")[![habara-k](https://avatars.githubusercontent.com/u/34413567?v=4)](https://github.com/habara-k "habara-k (3 commits)")[![satosby](https://avatars.githubusercontent.com/u/40451173?v=4)](https://github.com/satosby "satosby (3 commits)")[![tamucola](https://avatars.githubusercontent.com/u/11000908?v=4)](https://github.com/tamucola "tamucola (3 commits)")[![TessaYeh](https://avatars.githubusercontent.com/u/13792873?v=4)](https://github.com/TessaYeh "TessaYeh (3 commits)")

---

Tags

botlinelinebotphpsdksdkbotline

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/linecorp-line-bot-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/linecorp-line-bot-sdk/health.svg)](https://phpackages.com/packages/linecorp-line-bot-sdk)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M574](/packages/shopware-core)

PHPackages © 2026

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