由 Zaid 出售

Official Node.js SDK for the LINE Messaging API, enabling developers to build LINE bots and integrate messaging features using TypeScript or JavaScript with CJS and ESM support.
This block provides the official LINE Messaging API SDK for Node.js, exposing clients for the full suite of LINE Bot APIs including Messaging, LIFF, Insight, Manage Audience, Module, Shop, and webhook signature validation. It targets backend developers building LINE Official Account bots in Node.js/TypeScript projects using Express, Fastify, or similar HTTP servers.
index.ts - Main entry point; re-exports all sub-clients, middleware, and typesline-bot-client.ts - LineBotClient unified client class; manually maintained wrapperline-bot-client.generated.ts - Auto-generated base class with delegated API methodsline-bot-client.factory.generated.ts - Auto-generated factory for constructing all sub-clientsmiddleware.ts - Express-compatible webhook middleware for verifying LINE requestsvalidate-signature.ts - Low-level HMAC signature validation utilityhttp-fetch.ts - Internal fetch-based HTTP client with header normalization helpersexceptions.ts - Custom error types (e.g. HTTPFetchError)types.ts - Shared TypeScript types including ApiResponseTypeutils.ts - Internal URL/query-string helpersversion.ts - SDK version string and User-Agent constantchannel-access-token/ - Channel access token issuance and verification API clientinsight/ - Audience demographic and message event analytics API clientliff/ - LINE Front-end Framework (LIFF) app management API clientmanage-audience/ - Audience group management API client (incl. blob upload)messaging-api/ - Core Messaging API client (send messages, manage profiles, etc.)module/ - LINE Module operation API clientmodule-attach/ - LINE Module Attach API clientshop/ - LINE Shop API clientwebhook/ - Webhook event type definitions and helpersnpm install @types/node
No native modules, pod installs, or prebuild steps are required. Node.js 20 or higher is required at runtime.
启动隔离沙箱并在服务器端直接运行 — 无需本地配置。
此版本的 Tetrees AI Review
This TypeScript cli / script completed archive review. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
管道 avcp-2026-08-04.1 · SHA-256 7886e83d9aa5624e…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
审查日期 2026年8月4日
将此产品直接导入你的 AI IDE、网页构建器或云端 IDE。
将 Tetrees 连接到兼容的 AI IDE,列出你拥有的产品并获取已验证 ZIP,同时不会开放卖家上传权限。
暂无评价。
Sign in to join the discussion
Loading discussion…
source/ directory into your project, e.g. as src/line-bot-sdk/.tsconfig.json targets ES2020 or later and has moduleResolution set to node16 or bundler (the source uses .js extension imports for ESM compatibility):{
"compilerOptions": {
"target": "ES2020",
"module": "Node16",
"moduleResolution": "Node16",
"strict": true,
"esModuleInterop": true,
"outDir": "dist"
}
}
CHANNEL_ACCESS_TOKEN=your_channel_access_token
CHANNEL_SECRET=your_channel_secret
import { LineBotClient, middleware, validateSignature } from "./line-bot-sdk/index.js";
.js extension resolution for TypeScript source files is configured, or alias the imports accordingly.LineBotClientclass LineBotClient extends LineBotClientBase {
static fromChannelAccessToken(
config: LineBotClientChannelAccessTokenConfig
): LineBotClient;
}
interface LineBotClientChannelAccessTokenConfig {
readonly channelAccessToken: string;
readonly defaultHeaders?: Record<string, string>;
readonly apiBaseURL?: string;
readonly dataApiBaseURL?: string;
readonly managerBaseURL?: string;
}
The primary entry point for all LINE Bot API operations. Use LineBotClient.fromChannelAccessToken to construct a fully configured instance. It delegates to sub-clients for Insight, LIFF, Messaging API, Manage Audience, Module, and Shop. Use this when you want a single client rather than managing individual API clients.
middlewarefunction middleware(config: { channelSecret: string }): RequestHandler;
Express-compatible middleware that parses and verifies incoming LINE webhook requests. It validates the x-line-signature header and populates req.body with parsed webhook events. Use this as an Express route middleware on your webhook endpoint.
validateSignaturefunction validateSignature(
body: string | Buffer,
channelSecret: string,
signature: string
): boolean;
Low-level utility to manually verify a LINE webhook HMAC-SHA256 signature. Use this when you cannot use the Express middleware directly (e.g. in Fastify, Koa, or raw http servers) and need to validate the signature yourself before processing events.
Create a unified client and reply to a webhook text event using the Messaging API sub-client.
import { LineBotClient } from "./line-bot-sdk/index.js";
const client = LineBotClient.fromChannelAccessToken({
channelAccessToken: process.env.CHANNEL_ACCESS_TOKEN!,
});
async function handleTextEvent(replyToken: string, userText: string) {
await client.messagingApi.replyMessage({
replyToken,
messages: [{ type: "text", text: `You said: ${userText}` }],
});
}
Wire the middleware export into an Express app to automatically validate incoming LINE webhook requests.
import express from "express";
import { middleware } from "./line-bot-sdk/index.js";
const app = express();
app.post(
"/webhook",
middleware({ channelSecret: process.env.CHANNEL_SECRET! }),
(req, res) => {
const events = req.body.events;
for (const event of events) {
console.log("Received event:", event.type);
}
res.sendStatus(200);
}
);
app.listen(3000);
Use the insight named export directly when you only need analytics without constructing a full LineBotClient.
import { insight } from "./line-bot-sdk/index.js";
const insightClient = new insight.InsightClient({
channelAccessToken: process.env.CHANNEL_ACCESS_TOKEN!,
});
async function printDemographics() {
const data = await insightClient.getFriendsDemographics();
console.log("Demographics:", JSON.stringify(data, null, 2));
}
printDemographics();
Use validateSignature for frameworks where you control raw body parsing.
import Fastify from "fastify";
import { validateSignature } from "./line-bot-sdk/index.js";
const fastify = Fastify();
fastify.post("/webhook", {
config: { rawBody: true },
}, async (request, reply) => {
const signature = request.headers["x-line-signature"] as string;
const rawBody = (request as any).rawBody as Buffer;
const isValid = validateSignature(rawBody, process.env.CHANNEL_SECRET!, signature);
if (!isValid) {
return reply.status(401).send({ error: "Invalid signature" });
}
const events = (request.body as any).events;
console.log("Valid events:", events);
reply.status(200).send("OK");
});
fastify.listen({ port: 3000 });
index.ts - Barrel file; re-exports middleware, validateSignature, all exceptions, types, and all sub-namespace API clients. This is the only import path consumers need.line-bot-client.ts - Defines LineBotClient and LineBotClientChannelAccessTokenConfig; the manual wrapper that exposes fromChannelAccessToken static factory.line-bot-client.generated.ts - Auto-generated abstract base with one method per API operation, delegating to the appropriate typed sub-client.line-bot-client.factory.generated.ts - Auto-generated createLineBotClientDelegates factory that constructs all sub-clients from a single config object.middleware.ts - Express RequestHandler that validates LINE webhook signatures and parses event bodies.validate-signature.ts - Standalone HMAC-SHA256 signature check; framework-agnostic.http-fetch.ts - Internal HTTPFetchClient class; exposes normalizeHeaders, mergeHeaders, convertResponseToReadable helpers.exceptions.ts - Exports HTTPFetchError and any other SDK-specific error classes.types.ts - Shared types including ApiResponseType<T> wrapping HTTP response metadata.utils.ts - Internal helpers such as createURLSearchParams.version.ts - Exports USER_AGENT string used in HTTP request headers.channel-access-token/ - ChannelAccessTokenClient for issuing, verifying, and revoking channel access tokens.insight/ - InsightClient covering friend demographics, message events, and delivery statistics.liff/ - LiffClient for adding, updating, and listing LIFF apps.manage-audience/ - ManageAudienceClient and ManageAudienceBlobClient for audience group CRUD and CSV uploads.messaging-api/ - MessagingApiClient and MessagingApiBlobClient for the full Messaging API surface.module/ - LineModuleClient for LINE Module operation endpoints.module-attach/ - LineModuleAttachClient for module attachment flows.shop/ - ShopClient for LINE Shop related API calls.webhook/ - Type definitions for all LINE webhook event payloads..js extension imports fail in CJS projects - The source uses ESM-style .js imports; set "module": "Node16" or "module": "ESNext" in tsconfig.json and use "type": "module" in package.json.req.body is undefined in middleware - Do not place express.json() before the LINE middleware; middleware handles raw body parsing internally for signature validation.CHANNEL_SECRET vs CHANNEL_ACCESS_TOKEN confusion - channelSecret is used only for signature verification; channelAccessToken is used for API calls. Both are required but for different purposes.LineBotClient does not include channel access token management - Use channelAccessToken sub-namespace directly from index.ts for issuing or revoking tokens; LineBotClient intentionally omits this.fetch API (no node-fetch dependency); Node.js 20+ is required or you must polyfill fetch globally.request.rawBody - When using validateSignature in Fastify or Koa, configure your framework to preserve the raw body buffer before JSON parsing; the SDK has no control over this step.I have the LINE Bot SDK source code in `src/line-bot-sdk/` and a USAGE.md
integration guide in the same directory. The upstream npm package is
`@line/bot-sdk@1.0.0-test`.
Please integrate this SDK into my existing Express + TypeScript project
step by step:
1. Read USAGE.md and src/line-bot-sdk/index.ts to understand all exports.
2. Add the webhook endpoint using the `middleware` export with my CHANNEL_SECRET
environment variable.
3. Create a `LineBotClient` instance using `LineBotClient.fromChannelAccessToken`
with my CHANNEL_ACCESS_TOKEN environment variable.
4. Handle incoming `message` events of type `text` and reply using
`client.messagingApi.replyMessage`.
5. Show me the complete updated Express app file with all required imports
from `src/line-bot-sdk/index.js`.
6. Warn me about any tsconfig.json changes needed for ESM module resolution.
Licensed under the Apache License, Version 2.0. See the full license text at https://www.apache.org/licenses/LICENSE-2.0 or in source/LICENSE if present in this block.
Upstream package: @line/bot-sdk by LINE Corp.
Upstream repository: https://github.com/line/line-bot-sdk-nodejs
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
完整安装指南与集成提示词将在购买后解锁。
WordPress & WooCommerce Plugins
免费