Skip to content

feat(plugins): add engine.canonicalChatId capability for @lid resolution (#615)#618

Merged
rmyndharis merged 1 commit into
mainfrom
feat/plugin-canonical-chatid
Jul 3, 2026
Merged

feat(plugins): add engine.canonicalChatId capability for @lid resolution (#615)#618
rmyndharis merged 1 commit into
mainfrom
feat/plugin-canonical-chatid

Conversation

@rmyndharis

Copy link
Copy Markdown
Owner

Summary

Adds a plugin-SDK capability, ctx.engine.canonicalChatId(sessionId, chatId), that resolves a WhatsApp @lid privacy id to its stable <phone>@c.us form when the lid→phone mapping is known, and returns the id unchanged otherwise (@c.us, @g.us, channels, or an unresolved @lid). Resolution is a synchronous, best-effort read of the existing in-memory LidMappingStore.

Why

WhatsApp migrates contacts to @lid addressing over time. A plugin that keys a chat by its id — for example an integration mapping a WhatsApp chat to an external conversation — sees a contact's id change from <phone>@c.us to <lid>@lid across that migration, which can split what should be one conversation. This capability lets a plugin collapse both forms to one stable identity.

Details

  • New method on PluginEngineReadCapability, gated by the engine:read permission like the other engine reads, and bridged into the sandbox worker + capability router so sandboxed plugins can call it.
  • Backed by toNeutralJid + LidMappingStore.getCached — the same resolution the webhook from-filter already uses. Best-effort: an id whose lid→phone pair has not been observed yet passes through unchanged.
  • The LidMappingStore dependency is injected optionally, so the binding degrades to identity resolution where the table is not wired (and still enforces engine:read + an active session first).

Host-side prerequisite for the chatwoot-adapter to keep a migrated contact's conversation from splitting (#615).

…ion (#615)

Expose ctx.engine.canonicalChatId(sessionId, chatId) to plugins: resolves a
@lid privacy id to its stable <phone>@c.us form via the shared lid->phone
table (best-effort; unresolved ids pass through), gated by engine:read like
the other engine reads and bridged into the sandbox worker + router.

Lets an adapter key a chat by one identity across WhatsApp's @lid migration —
the host-side prerequisite for the chatwoot-adapter to stop a migrated
contact's conversation from splitting.
@rmyndharis rmyndharis merged commit ed11ad6 into main Jul 3, 2026
5 checks passed
@rmyndharis rmyndharis deleted the feat/plugin-canonical-chatid branch July 3, 2026 12:19
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