Add LINE channel adapter with webhook ingress and gating

This commit is contained in:
William Valentin
2026-02-16 13:02:26 -08:00
parent a954d7e136
commit 76d44a74bf
15 changed files with 584 additions and 5 deletions
+14
View File
@@ -51,6 +51,7 @@ import { RequestBodyTooLargeError, readRequestBody } from '../utils/httpBody.js'
import type { TeamsAdapter } from '../channels/teams/adapter.js';
import type { GoogleChatAdapter } from '../channels/googleChat/adapter.js';
import type { BlueBubblesAdapter } from '../channels/bluebubbles/adapter.js';
import type { LineAdapter } from '../channels/line/adapter.js';
export interface GatewayServerConfig {
port: number;
@@ -120,6 +121,8 @@ export interface GatewayServerConfig {
googleChatHandler?: Pick<GoogleChatAdapter, 'handleRequest'>;
/** Optional BlueBubbles adapter for inbound iMessage event webhooks. */
blueBubblesHandler?: Pick<BlueBubblesAdapter, 'handleRequest'>;
/** Optional LINE adapter for inbound webhook events. */
lineHandler?: Pick<LineAdapter, 'handleRequest'>;
}
export class GatewayServer {
@@ -724,6 +727,12 @@ export class GatewayServer {
return;
}
// LINE events route — bypass gateway auth (LINE webhook posts directly)
if (this.config.lineHandler && req.method === 'POST' && req.url?.startsWith('/line/events')) {
await this.config.lineHandler.handleRequest(req, res);
return;
}
// Apply auth to HTTP requests when configured
const authConfig = this.config.auth ?? {};
if (this.config.authHttp !== false && authConfig.token) {
@@ -842,6 +851,11 @@ export class GatewayServer {
this.config.blueBubblesHandler = handler;
}
/** Set the LINE handler for inbound webhook HTTP routes (late binding). */
setLineHandler(handler: Pick<LineAdapter, 'handleRequest'>): void {
this.config.lineHandler = handler;
}
private async startDiscovery(host: string, port: number): Promise<void> {
const discovery = this.config.discovery;
if (!discovery?.enabled) {