LINE Messaging API SDK for PHP

Getting started

Requirements

Installation

composer require linecorp/line-bot-sdk

Create a client

use GuzzleHttp\Client;
use LINE\Clients\MessagingApi\Configuration;
use LINE\Clients\MessagingApi\Api\MessagingApiApi;

$client = new Client();
$config = new Configuration();
$config->setAccessToken('<channel access token>');
$messagingApi = new MessagingApiApi(
    client: $client,
    config: $config,
);

Send a reply

use LINE\Clients\MessagingApi\Model\TextMessage;
use LINE\Clients\MessagingApi\Model\ReplyMessageRequest;

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

Setter style is also supported:

$message = (new TextMessage())
    ->setText('hello!');
$request = (new ReplyMessageRequest())
    ->setReplyToken('<reply token>')
    ->setMessages([$message]);
$messagingApi->replyMessage($request);

Examples

  • EchoBot — Replies to text messages from users.
  • KitchenSink — Demonstrates practical use of the Messaging API.

Search results