From 4675aa3fd4c6daa80422ce8babd121a9314a9ebc Mon Sep 17 00:00:00 2001 From: SYNITY Date: Sun, 28 Jun 2026 13:54:19 +0700 Subject: [PATCH] fix(bitrix24): skip native-group mention gate for Open Channel sessions [B24:2794] (#1296) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to #1295. After scoping the Open Channel mention gate by connector, customer messages on 1-to-1 connectors (Facebook Messenger, Zalo OA, …) were STILL being silently dropped — by the second mention-gate stanza further down in handleMessage, which checks the channel-level c.RequireMention() flag without distinguishing Open Channel traffic from native group chats (CRM deal/task chats). For a channel like nguyen-dao-openline configured with RequireMention=true, the flow was: 1. isOpenChannel block → shouldRequireMentionForOpenline("facebook|...") returns false (facebook isn't in the whitelist) → no drop. 2. isGroup block (isOpenChannel implies isGroup) → c.RequireMention()=true AND mentioned=false → DROP. Net effect: the gate-by-connector decision was overridden one stanza later, and every Facebook customer turn disappeared. Fix: scope the drop check inside the isGroup block to native-group chats only (!isOpenChannel). Open Channel sessions already own their mention policy in the earlier isOpenChannel block; re-applying the channel-level RequireMention flag here second-guesses that decision. Importantly, the text-processing that follows the drop check (MessageOriginal fallback, stripMention, bxConvertUserMentionsToReadable) stays unconditional, so an Open Channel STAFF turn that does come in with "[USER=]Bot[/USER]" BBCode still gets cleaned up the same way it always did. The only thing the new guard suppresses is the drop itself. Verified live: Facebook Messenger customer turn (IS_CONNECTOR=Y, CHAT_ENTITY_ID=facebook|34|…) now reaches the agent loop and the bot replies, matching the intent from #1295. Surface parity: backend-only. No API contract / web UI / CLI change. Co-authored-by: DangTinh311 --- internal/channels/bitrix24/handle.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/channels/bitrix24/handle.go b/internal/channels/bitrix24/handle.go index bd187e1a..4f32a18d 100644 --- a/internal/channels/bitrix24/handle.go +++ b/internal/channels/bitrix24/handle.go @@ -164,13 +164,23 @@ func (c *Channel) handleMessage(ctx context.Context, evt *Event) { } } if isGroup { + // Mention DROP CHECK is scoped to native group chats (CRM deal/task, + // plain groups) only. Open Channel sessions own their mention policy + // via shouldRequireMentionForOpenline above — re-applying the channel- + // level RequireMention flag here would silently drop, e.g., every + // Facebook Messenger customer turn (whose connector isn't in the + // require-mention whitelist) even though the upstream gate let it + // through. Text processing below (mention strip + readable rewrite) + // stays unconditional so Openline staff messages with bot BBCode tags + // still get cleaned up. + // // Authority-ordered fallback: structured MENTIONED_LIST → raw // MESSAGE_ORIGINAL → stripped MESSAGE. In group chats Bitrix24 strips // the @mention from MESSAGE before sending the webhook, so checking // MESSAGE alone misses every group mention. See // plans/bitrix24-mcp-refactor/reports/retrospective.md §2 for context. mentioned := c.isMentionedParams(&evt.Params) - if c.RequireMention() && !mentioned { + if !isOpenChannel && c.RequireMention() && !mentioned { slog.Info("bitrix24 message: dropped missing mention", "from_user_id", evt.Params.FromUserID, "dialog_id", evt.Params.DialogID,