Skip to content

Latest commit

 

History

History
123 lines (91 loc) · 3.99 KB

File metadata and controls

123 lines (91 loc) · 3.99 KB

linekit

A modular integration toolkit for LINE Messaging API, Login, and LIFF.

Website GitHub

繁體中文 | English

Features

  • Modular: separate packages for Core, Messaging, Login, and Adapters.
  • Framework Agnostic: use with Express, Fastify, or standard Web APIs.
  • Type-Safe: written in TypeScript with complete definitions.
  • Secure: timing-safe signature verification, input validation, CSRF protection helpers.
  • Developer Friendly: simple, explicit API for bots and login.

Installation

npm install @linekit/core @linekit/messaging @linekit/adapters-express

Usage

Basic Bot (Express)

import express from "express";
import { createLineApp } from "@linekit/core";
import { lineMiddleware } from "@linekit/express";

const app = express();
const config = {
  channelId: process.env.CHANNEL_ID,
  channelSecret: process.env.CHANNEL_SECRET,
  channelAccessToken: process.env.CHANNEL_ACCESS_TOKEN,
};

const line = createLineApp(config);

app.post(
  "/webhook",
  lineMiddleware(config), // Validates signature and parses body
  line.router({
    message: async (ctx) => {
      if (ctx.event.message.type === "text") {
        await ctx.replyText(`You said: ${ctx.event.message.text}`);
      }
    },
    follow: async (ctx) => {
      await ctx.pushText("Thanks for following!");
    },
  })
);

app.listen(3000, () => console.log("Bot running on port 3000"));

LINE Login

import { login, generateAuthUrl, issueAccessToken } from "@linekit/login";

// Generate OAuth URL with CSRF protection
const state = login.generateState();
const authUrl = generateAuthUrl({
  channelId: "YOUR_CHANNEL_ID",
  redirectUri: "https://example.com/callback",
  state,
});

// After callback, validate state and exchange code for tokens
if (login.validateState(savedState, returnedState)) {
  const tokens = await issueAccessToken(channelId, channelSecret, code, redirectUri);
  const user = await login.verify(tokens.id_token, channelId);
  console.log(user.name, user.email);
}

Packages

  • @linekit/core: Webhook verification (timing-safe), Context, Router with error handling.
  • @linekit/messaging: Messaging API client (Reply, Push, Multicast, Rich Menu) with input validation.
  • @linekit/login: OAuth flow, ID Token verification, CSRF state helpers.
  • @linekit/express: Adapter for Express.js.

LINE API Compatibility

This toolkit is built against the following LINE API versions:

API Version Reference
Messaging API v2 docs
LINE Login v2.1 (OAuth 2.1) docs
LIFF v2 docs

Endpoint Base URLs:

  • Messaging API: https://api.line.me/v2/bot/
  • LINE Login: https://api.line.me/oauth2/v2.1/
  • Authorization: https://access.line.me/oauth2/v2.1/

API Limits (enforced by linekit):

  • Maximum 5 messages per request
  • Maximum 500 recipients per multicast request

Documentation

📚 Full Tutorials & API Reference - Comprehensive guides with flow diagrams

Examples

  • Basic Bot: A simple echo bot connecting to the Messaging API.
  • Login Demo: A web application demonstrating the "Log in with LINE" OAuth 2.1 flow.
  • Marketing Demo: A CLI tool for creating and managing Rich Menus.

License

MIT