feat(plugins): add engine.canonicalChatId capability for @lid resolution (#615)#618
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a plugin-SDK capability,
ctx.engine.canonicalChatId(sessionId, chatId), that resolves a WhatsApp@lidprivacy id to its stable<phone>@c.usform 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-memoryLidMappingStore.Why
WhatsApp migrates contacts to
@lidaddressing 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.usto<lid>@lidacross that migration, which can split what should be one conversation. This capability lets a plugin collapse both forms to one stable identity.Details
PluginEngineReadCapability, gated by theengine:readpermission like the other engine reads, and bridged into the sandbox worker + capability router so sandboxed plugins can call it.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.LidMappingStoredependency is injected optionally, so the binding degrades to identity resolution where the table is not wired (and still enforcesengine:read+ an active session first).Host-side prerequisite for the
chatwoot-adapterto keep a migrated contact's conversation from splitting (#615).