feat(chatwoot-adapter): relay the operator's own outbound sends to Chatwoot (#615)#29
Merged
Merged
Conversation
…atwoot (#615) Messages composed on a linked phone / the WhatsApp app / the OpenWA API arrive on message:sent (not message:received) and were never relayed, so an ongoing Chatwoot thread went one-sided. Subscribe to message:sent and relay fromMe messages as 'outgoing' into the contact's EXISTING mapped conversation, gated by a new relayOwnMessages setting (default on). An own send to a chat not yet mapped is skipped (never creates a conversation), so a contact WhatsApp has migrated to @lid can't be split off into a duplicate. Echo-suppression: the adapter's own Chatwoot-agent replies also surface on message:sent, so outbound.relay marks the WA id it sent and handleSent skips anything already seen, serialized on a per-chat lock keyed by the canonical (@lid-resolved) chat id. @lid migration: a send to a migrated contact resolves to the @lid address, so message:sent carries chatId=@lid while the mapping is keyed @c.us. handleSent canonicalizes the chat id (ctx.engine.canonicalChatId, best-effort) for the lock key and does a dual lookup (raw then canonical) so a resolvable migrated contact's send lands in its existing conversation. Requires OpenWA 0.8.7. Also: type-based placeholders for caption-less media sends (photo/video/etc) so they never post an empty bubble, and a defensive log when a send returns no message id.
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
Relays the operator's own outbound WhatsApp messages — composed on a linked phone, the WhatsApp mobile app, or the OpenWA REST API — into the mapped Chatwoot conversation as
outgoingmessages, so an ongoing thread stops looking one-sided (#615).Problem
The adapter only subscribed to
message:receivedand dropped everyfromMemessage. WhatsApp delivers messages composed on a linked device through a different path (message:sent), so an operator replying from their phone alongside Chatwoot produced a broken, one-sided thread — the contact's replies showed, the operator's phone messages never did.Changes
message:sentand postfromMemessages as Chatwootoutgoing, into the contact's existing mapped conversation. Gated by a newrelayOwnMessagessetting (default on; turn it off to keep phone-composed messages out of the helpdesk).@lid— whose@c.usmapping isn't always resolvable — into a duplicate; the chat still appears once the contact replies.fromMeand returns onmessage:sent. The outbound path marks the WhatsApp id it sent and the own-send handler skips anything already seen, serialized on a per-chat lock.@lidmigration. A send to a migrated contact resolves to the@lidaddress, somessage:sentcarrieschatId=@lidwhile the mapping is keyed@c.us. The handler canonicalizes the chat id (ctx.engine.canonicalChatId) for the lock key and does a dual lookup (raw then canonical), so a resolvable migrated contact's send lands in its existing conversation.Compatibility
Version
0.4.0;minOpenWAVersion0.8.7(uses the newcanonicalChatIdhost capability). Existing behavior is unchanged for inbound relay, outbound agent replies, and handover.