Skip to content

Conversation

@wahyuwidgetworks
Copy link

Summary

  • Add a [WIDGET-WORKS] DB fallback in messages.upsert to detect messages already synced to Chatwoot by key and reuse existing Chatwoot IDs.
  • Skip Chatwoot sync when a prior message with the same key already has chatwootMessageId (covers Chatwoot automation echoes), while keeping the upstream cache guard.
  • Limit the fallback to Chatwoot-enabled, non-broadcast flows.

Testing

  • Not run (logic-only dedupe guard).

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 1195 to 1199
if (shouldSyncChatwoot) {
const existingChatwootMessage = await this.prismaRepository.message.findFirst({
where: {
key: { path: ['id'], equals: received.key.id },
chatwootMessageId: { not: null },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Scope Chatwoot dedupe lookup to current instance

The new Chatwoot dedupe fallback calls message.findFirst using only the message key id, without filtering by instanceId (lines 1195-1199). Earlier in the same handler the duplicate cache key is ${this.instance.id}_${received.key.id}, which suggests message ids are not considered globally unique across tenants. In a multi-instance deployment, a message id collision would cause this lookup to return another tenant’s Chatwoot record, set those Chatwoot ids on the incoming message, and skip eventWhatsapp, effectively dropping Chatwoot sync for the current instance and leaking conversation ids across tenants. The query should be constrained to the current instance to avoid cross-tenant contamination.

Useful? React with 👍 / 👎.

@wahyuwidgetworks wahyuwidgetworks merged commit c378971 into production-v2.3.2 Dec 3, 2025
1 check passed
@wahyuwidgetworks wahyuwidgetworks deleted the fix/chatwoot-automation-echo-dedupe branch December 4, 2025 15:54
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.

2 participants