Skip to content

fix(platform-id): trust pre-prefixed ids regardless of channel key#2654

Open
elancode wants to merge 1 commit into
nanocoai:mainfrom
elancode:fix/platform-id-trust-prefixed
Open

fix(platform-id): trust pre-prefixed ids regardless of channel key#2654
elancode wants to merge 1 commit into
nanocoai:mainfrom
elancode:fix/platform-id-trust-prefixed

Conversation

@elancode
Copy link
Copy Markdown

What

namespacedPlatformId() now trusts any caller-supplied <prefix>:<id> value as the chat-sdk's already-encoded form, instead of only matching when the prefix equals the channel registry key.

Why

When one chat-sdk adapter is registered under a channel key that differs from its SDK-side name (e.g. a second Telegram bot wired under channel telegram-2, whose underlying @chat-adapter/telegram still emits telegram:<id>), the previous logic prepended the channel key on top, producing telegram-2:telegram:<id>. That value never matches any real inbound platform_id, so messaging_groups created via scripts/init-first-agent.ts end up unreachable.

How

  • Drop the raw.startsWith(${channel}:) exact match.
  • Add a regex check ^[a-z][a-z0-9_-]*:/i so any <lowercase-token>:… shape is trusted as already-encoded.
  • Native short-circuits preserved (@, +, group:, deltachat).

Tests

Added src/platform-id.test.ts with 6 cases covering bare ids, channel-matching prefix, non-matching prefix (the bug), WhatsApp / iMessage JIDs, Signal phone numbers / group ids, and DeltaChat numeric ids.

Test Files  1 passed (1)
     Tests  6 passed (6)

Full suite (pnpm test) — 338 passed, 0 failed. pnpm run build (tsc) — clean.

Refs #2653

`namespacedPlatformId` previously only treated a value as already
prefixed when it started with `${channel}:`. When one chat-sdk
adapter is registered under a channel key that differs from its
SDK-emitted prefix (e.g. a second Telegram bot wired under channel
`telegram-2`, whose underlying chat-sdk still emits `telegram:<id>`),
the function double-prefixed the value into `telegram-2:telegram:<id>`
and downstream messaging_groups rows then failed to match any inbound.

Trust any `<lowercase-token>:` shape as already-encoded. Native
short-circuits (`@`, `+`, `group:`, `deltachat`) preserved.

Refs nanocoai#2653

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant