LINE

LINE Messaging API adapter for Chat SDK. Send text and Flex Message cards, receive media and postback actions, and verify signed webhooks.

Community adapter. Not maintained by Vercel or Chat SDK contributors. For feature requests, bug reports, and support, file an issue on the adapter's repo.

Install

pnpm add chat-adapter-line chat @chat-adapter/state-memory

Quick start

lib/bot.ts
import { Chat } from "chat";
import { createLineAdapter } from "chat-adapter-line";
import { createMemoryState } from "@chat-adapter/state-memory";

const bot = new Chat({
  userName: "mybot",
  adapters: {
    line: createLineAdapter(),
  },
  state: createMemoryState(),
});

bot.onDirectMessage(async (thread, message) => {
  await thread.post(`You said: ${message.text}`);
});

The memory state adapter keeps subscriptions and locks in process memory, which suits local development. Use Redis or PostgreSQL in production.

When called with no arguments, createLineAdapter() reads LINE_CHANNEL_ACCESS_TOKEN and LINE_CHANNEL_SECRET from the environment.

Platform setup

  1. Create a provider and channel in the LINE Developers Console.
  2. Enable the Messaging API for the channel.
  3. Copy the channel access token and channel secret.
  4. Set the webhook URL to a public HTTPS endpoint, such as https://your-domain.com/api/webhooks/line.
  5. Subscribe to message and postback events.

Configuration

Prop

Type

Environment variables

VariableRequiredDescription
LINE_CHANNEL_ACCESS_TOKENYesLINE channel access token, unless you pass channelAccessToken.
LINE_CHANNEL_SECRETYesLINE channel secret, unless you pass channelSecret.

Webhooks

app/api/webhooks/line/route.ts
import { after } from "next/server";
import { bot } from "@/lib/bot";

export async function POST(request: Request): Promise<Response> {
  return bot.webhooks.line(request, {
    waitUntil: (task) => after(() => task),
  });
}

LINE sends each webhook with an x-line-signature header. The adapter computes an HMAC-SHA256 digest with the channel secret and compares it with the header before parsing the body.

Messages and cards

Text and Markdown output are converted to plain text. Chat SDK cards become LINE Flex Messages: the card title and text become the bubble body, and buttons become postback actions in the footer. Button clicks dispatch to Chat SDK action handlers.

Attachments

The adapter receives image, video, audio, and file messages as attachments. It doesn't upload outbound files. Posting a message with files logs a warning and sends any text or card content.

Streaming

Streaming is buffered. The adapter sends a text message after it collects more than 500 characters, then sends the remaining text after the stream ends. It sends at most five messages per stream.

Thread IDs

line:<channelId>:<sourceType>:<sourceId>

sourceType is user, group, or room. sourceId is the LINE user, group, or room ID.

Feature support

Messaging

FeatureSupported
Post message
Message replies
Edit message
Delete message
File uploadsInbound only
StreamingBuffered chunks
Scheduled messages

Rich content

FeatureSupported
Card formatLINE Flex Messages
ButtonsCard postbacks
Link buttons
Select menus
Tables
Charts
Fields
Images in cards
Modals

Conversations

FeatureSupported
Slash commands
Mentions
Add reactions
Remove reactions
Typing indicatorDMs only
Mark as read
Message edit events
Message delete events
DMs
Ephemeral messages
User lookupDM profiles
Parent subject
Native client
Custom API endpoint

Message history

FeatureSupported
Fetch messages
Fetch single message
Fetch thread infoUsers and groups
Fetch channel messages
List threads
Fetch channel infoGroup name
Post channel message

On this page