From 9f5c37fc4c88ec0689fa82103c238201b6e38845 Mon Sep 17 00:00:00 2001 From: gavrielc Date: Thu, 9 Apr 2026 13:39:40 +0300 Subject: [PATCH] fix: handle platform ID prefix mismatch in router, not register Move prefix handling from register.ts to router.ts. Users register with raw platform IDs (what they naturally have), adapters send prefixed IDs (their internal format). Router now tries stripping the channel type prefix when the exact lookup fails, matching either format. Co-Authored-By: Claude Opus 4.6 (1M context) --- setup/register.ts | 7 ------- src/router.ts | 8 ++++++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/setup/register.ts b/setup/register.ts index dacd8d2..a15e469 100644 --- a/setup/register.ts +++ b/setup/register.ts @@ -118,13 +118,6 @@ export async function run(args: string[]): Promise { process.exit(4); } - // Chat SDK adapters prefix platform IDs with the channel type (e.g. "telegram:123", - // "discord:guild:channel"). Auto-prefix if the user provided a raw ID so the router - // matches the adapter's format. - if (parsed.platformId && !parsed.platformId.startsWith(`${parsed.channel}:`)) { - parsed.platformId = `${parsed.channel}:${parsed.platformId}`; - } - log.info('Registering channel', parsed); // Init v2 central DB diff --git a/src/router.ts b/src/router.ts index 658c117..89723fc 100644 --- a/src/router.ts +++ b/src/router.ts @@ -34,7 +34,15 @@ export interface InboundEvent { */ export async function routeInbound(event: InboundEvent): Promise { // 1. Resolve messaging group + // Adapters send prefixed platform IDs (e.g. "telegram:123") but users may + // register with raw IDs ("123"). Try exact match first, then stripped prefix. let mg = getMessagingGroupByPlatform(event.channelType, event.platformId); + if (!mg) { + const prefix = `${event.channelType}:`; + if (event.platformId.startsWith(prefix)) { + mg = getMessagingGroupByPlatform(event.channelType, event.platformId.slice(prefix.length)); + } + } if (!mg) { // Auto-create messaging group (adapter already decided to forward this)