fix(bitrix24): skip native-group mention gate for Open Channel sessions [B24:2794] (#1296)

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=<botID>]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 <dangtinh31193@gmail.com>
This commit is contained in:
SYNITYandDangTinh311 authored and GitHub committed 2026-06-28 13:54:19 +07:00
1 parent 164ea2ea4a
commit 4675aa3fd4
1 file changed
+11 -1
+11 -1
View File
@@ -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,