Skip to content

fix(bluebubbles): extract chatGuid from chats array in webhook payload#8295

Open
BukeLy wants to merge 2 commits intoNousResearch:mainfrom
BukeLy:fix/bluebubbles-dm-routing-priority
Open

fix(bluebubbles): extract chatGuid from chats array in webhook payload#8295
BukeLy wants to merge 2 commits intoNousResearch:mainfrom
BukeLy:fix/bluebubbles-dm-routing-priority

Conversation

@BukeLy
Copy link
Copy Markdown

@BukeLy BukeLy commented Apr 12, 2026

What does this PR do?

BlueBubbles webhook payloads do not populate the top-level chatGuid or chatIdentifier fields on message records. The chat GUID is only available inside the chats array. Without the correct chatGuid, the adapter falls back to the sender's phone number, and _resolve_chat_guid may resolve it to a group chat where the contact is a participant — causing DM replies to go to the wrong chat.

This PR falls back to record["chats"][0]["guid"] when direct chatGuid fields are empty, and removes the stale payload.get("guid") fallback that incorrectly matched the message GUID.

Related Issue

Fixes #8514

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/platforms/bluebubbles.py: Added chats[0].guid fallback, removed incorrect payload.get("guid") fallback
  • tests/gateway/test_bluebubbles.py: Added TestBlueBubblesChatGuidFromChatsArray (5 tests)

How to Test

  1. Send a DM - verify reply goes to DM (not group)
  2. Send in group chat - verify reply goes to group
  3. Message with no chats array - verify fallback to chat_identifier

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes
  • I've tested on my platform: macOS 15.4 (Sequoia), Apple Silicon

Documentation & Housekeeping

  • N/A - BlueBubbles-specific fix, no config or doc changes needed
  • Cross-platform: BlueBubbles is macOS-only, no impact on other platforms

BlueBubbles webhook payloads do not populate the top-level `chatGuid`
field on message records. The chat GUID is only available inside the
`chats` array (e.g. `record["chats"][0]["guid"]`).

Without the correct chatGuid, the adapter falls back to the sender's
phone number as the session chat ID. When the same contact exists in
both a DM and a group chat, `_resolve_chat_guid` may resolve the
phone number to the wrong conversation, causing DM replies to land
in the group or vice versa.

Now fall back to `chats[0].guid` when direct chatGuid fields are
empty. Also removes the stale `payload.get("guid")` fallback which
incorrectly matched the message GUID (not chat GUID).
@BukeLy BukeLy force-pushed the fix/bluebubbles-dm-routing-priority branch from 9105f61 to 2a676ec Compare April 12, 2026 10:29
@BukeLy BukeLy changed the title fix(bluebubbles): prefer DM over group when resolving chat GUID fix(bluebubbles): extract chatGuid from chats array in webhook payload Apr 12, 2026
Test extraction of chat GUID from the chats[] array when top-level
chatGuid fields are null (common in BB webhook payloads). Covers DM,
group, direct-field priority, empty array, and missing key cases.
@BukeLy
Copy link
Copy Markdown
Author

BukeLy commented Apr 13, 2026

Hi @jbarket @chalkers @leon @intertwine,
could you please take a look at this PR and help enable the CI run? Thanks!

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.

[Bug]: BlueBubbles webhook payload chatGuid is null — DM replies go to wrong chat

1 participant