npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kpab/flue-line

v0.1.0

Published

Verified LINE Messaging API webhook ingress and reply/push tools for Flue applications.

Readme

@kpab/flue-line

Verified LINE Messaging API webhook ingress, plus reply/push send tools, for Flue applications.

This is an unofficial, community-maintained channel. As of this writing there is no first-party @flue/line package in the Flue ecosystem — @kpab/flue-line fills that gap, following the same design as first-party channels like @flue/github and @flue/slack.

日本語版 README はこちら

Quickstart

npm install @kpab/flue-line

@flue/runtime is a peer dependency — install it if you haven't already (any Flue app already has it):

npm install @flue/runtime

Overview

createLineChannel() verifies every inbound delivery's X-Line-Signature against the exact request bytes before your webhook callback ever runs, and narrows each event by its type:

import { createLineChannel } from '@kpab/flue-line';

export const channel = createLineChannel({
  channelSecret: process.env.LINE_CHANNEL_SECRET!,

  // Path: /channels/line/webhook
  async webhook({ event, destination }) {
    // `event.type` discriminates the rest of `event`'s shape.
    if (event.type === 'message' && event.message.type === 'text') {
      console.log(event.message.text);
    }
  },
});

LINE batches multiple events into a single HTTP delivery — unlike GitHub's one-event-per-delivery model — so webhook() is called once per event in that delivery, not once per request. Returning a Response from any call stops processing the remaining events in that delivery and sends it directly; returning nothing (for every event) yields an empty 200 once they're all processed. The package is stateless: LINE has no delivery id to deduplicate on, so keep your handler idempotent.

Supported event types (event.type): message (narrows message.type to text | image | video | audio | file | location | sticker), unsend, follow, unfollow, join, leave, memberJoined, memberLeft, postback, videoPlayComplete, beacon, accountLink, and membership — matching the official webhook event schema. LINE Things (IoT device link/unlink/scenario) and a handful of other niche event types are out of scope.

Configure

Create a Messaging API channel in the LINE Developers console and set:

LINE_CHANNEL_SECRET=...        # Basic settings tab — verifies inbound webhooks
LINE_CHANNEL_ACCESS_TOKEN=...  # Messaging API tab — Bearer token for reply/push

Turn off the LINE Official Account's own auto-reply and greeting messages in the LINE Official Account Manager so only your agent replies.

Channel module

Place this export in src/channels/line.ts. Flue discovers it and serves POST /channels/line/webhook relative to the flue() mount:

import { dispatch } from '@flue/runtime';
import { createLineChannel } from '@kpab/flue-line';
import assistant from '../agents/assistant.ts';

export const channel = createLineChannel({
  channelSecret: process.env.LINE_CHANNEL_SECRET!,

  async webhook({ event }) {
    if (event.type !== 'message' || event.message.type !== 'text') return;
    if (event.source?.type !== 'user') return;

    await dispatch(assistant, {
      // One session per LINE user.
      id: channel.conversationKey({ type: 'user', userId: event.source.userId }),
      input: {
        type: 'line.message',
        eventId: event.webhookEventId,
        text: event.message.text,
      },
    });
  },
});

channel.conversationKey() serializes a canonical, namespaced identifier for a 1-on-1 user, group chat, or multi-person room — it is not an authorization capability. channel.parseConversationKey() parses only keys produced by conversationKey(), and round-trips them back to a { type: 'user' | 'group' | 'room', ... } ref you can pass straight to the push tool's to.

Bind the tool

Outbound send calls (reply/push) live in a separate module, @kpab/flue-line/tools, so the channel itself never depends on them — the channel's job is verified ingress, and yours is deciding when and how to answer.

defineAgent()'s initializer runs once per session and only receives { id, env } (@flue/runtime's AgentInitializerContext) — not the per-message input passed to dispatch() — so a session's tools are wired once from context.id, not from a single event. Bind the push tool there, parsing the stable LINE destination back out of the conversation key:

import { defineAgent } from '@flue/runtime';
import { createPushMessageTool } from '@kpab/flue-line/tools';
import { channel } from '../channels/line.ts';

export default defineAgent((context) => {
  const ref = channel.parseConversationKey(context.id);
  const to = ref.type === 'user' ? ref.userId : ref.type === 'group' ? ref.groupId : ref.roomId;

  return {
    model: 'anthropic/claude-sonnet-4-6',
    instructions: 'Reply to LINE messages helpfully and concisely.',
    tools: [createPushMessageTool({ channelAccessToken: process.env.LINE_CHANNEL_ACCESS_TOKEN!, to })],
  };
});

A LINE reply token is single-use and expires shortly after its webhook fires, so it doesn't fit a tool wired once for a session's whole lifetime. Use createReplyMessageTool({ channelAccessToken, replyToken }) for an immediate acknowledgement instead, called directly (not exposed to the model) from inside webhook(), before dispatch():

await createReplyMessageTool({
  channelAccessToken: process.env.LINE_CHANNEL_ACCESS_TOKEN!,
  replyToken: event.replyToken,
}).run({ input: { text: 'Got it, thinking…' }, signal: undefined });

In both cases the model only ever chooses the message text — the replyToken and push to destination are bound by trusted code, never exposed as a model-selectable input.

See examples/minimal-agent for a complete, runnable app wiring the channel and both tools together.

Testing

npm test            # Node.js (vitest)
npm run test:workerd # Cloudflare Workers (Miniflare, nodejs_compat)

Signature verification uses Web Crypto SubtleCrypto only, so the same implementation runs unmodified on both runtimes.

License

Apache-2.0, matching Flue itself. See LICENSE.