messaging-api-line

raw JSON →
1.1.0 verified Sat Apr 25 auth: no javascript

A Node.js client library for the LINE Messaging API, version 1.1.0. Maintained as part of the Yoctol messaging-apis monorepo, it provides a comprehensive, TypeScript-first wrapper for LINE's REST endpoints including reply, push, multicast, broadcast, and rich menu APIs. The library uses axios for HTTP and wraps errors for better debugging. Key differentiators: full TypeScript types, camelCase key support (v1.0.0+), factory methods for message creation, and support for Flex and Imagemap messages. Release cadence is sporadic with the last release in October 2021.

error Error: replyToken is required
cause Calling client.reply() without a reply token or with an undefined/null token.
fix
Provide a valid replyToken from the webhook event (e.g., req.body.events[0].replyToken). Ensure environment variable is set.
error TypeError: Cannot read properties of undefined (reading 'config')
cause Missing or invalid accessToken/channelSecret in client constructor.
fix
Verify LINE_ACCESS_TOKEN and LINE_CHANNEL_SECRET are set and passed correctly.
error Error: Request failed with status code 401
cause Invalid or expired access token.
fix
Regenerate access token from LINE Developers console and update your code.
error TypeError: client.broadcast is not a function
cause Using an older version (<1.1.0) that does not support broadcast API.
fix
Upgrade to messaging-api-line@1.1.0 or later. npm install messaging-api-line@latest
breaking v1.0.0 switched from snake_case to camelCase keys. Old code using snake_case will break.
fix Update all API parameters and message objects to use camelCase keys (e.g., replyToken → replyToken, originalContentUrl → originalContentUrl).
breaking v1.0.0 removed namespace exports. Use 'messaging-api-line' directly instead of 'messaging-api-line/dist/...'.
fix Change imports from 'messaging-api-line/dist/LineClient' to 'messaging-api-line'.
gotcha The replyToken can only be used once. Attempting to reply twice with the same token will result in an error.
fix Track used tokens and only reply once per webhook event.
deprecated Older versions used snake_case for message types (e.g., 'imagemapMessage'). Version 1.1.0 prefers camelCase for fields but still accepts snake_case for compatibility? Not explicitly deprecated but caution advised.
fix Always use camelCase keys for message fields to ensure compatibility with future versions.
npm install messaging-api-line
yarn add messaging-api-line
pnpm add messaging-api-line

Initializes LineClient with credentials, then demonstrates reply, push, broadcast, and getBotInfo APIs.

import { LineClient } from 'messaging-api-line';

const client = new LineClient({
  accessToken: process.env.LINE_ACCESS_TOKEN ?? '',
  channelSecret: process.env.LINE_CHANNEL_SECRET ?? '',
});

// Reply to a webhook event
await client.reply(REPLY_TOKEN, [
  {
    type: 'text',
    text: 'Hello from messaging-api-line!',
  },
]);

// Push a message to a user
await client.push(USER_ID, [
  {
    type: 'text',
    text: 'This is a push message.',
  },
]);

// Broadcast to all friends
await client.broadcast([
  {
    type: 'text',
    text: 'Broadcast message',
  },
]);

// Get bot info
const botInfo = await client.getBotInfo();
console.log(botInfo);