Implementation:Openclaw Openclaw ResolveChannelGroupRequireMention
| Knowledge Sources | |
|---|---|
| Domains | Messaging, Configuration, Group Chat |
| Last Updated | 2026-02-06 12:00 GMT |
Overview
Concrete functions for resolving whether a group message requires an explicit bot mention and for evaluating mention gating at message processing time, provided by the OpenClaw gateway.
Description
The resolveChannelGroupRequireMention function in src/config/group-policy.ts (lines 148-175) resolves the effective requireMention boolean for a given group by cascading through per-group config, wildcard default config, and an optional programmatic override. It returns true (require mention) by default if no config is found, following the deny-by-default security posture.
The resolveMentionGating function in src/channels/mention-gating.ts (lines 30-36) takes the resolved requireMention boolean along with platform-specific mention detection results and determines whether the message should be skipped. It considers explicit mentions, implicit mentions (e.g., replies to the bot), and bypass conditions (e.g., control commands that should be processed even without a mention).
Together, these two functions form the complete mention gating pipeline: first resolve whether mentions are required for this group, then evaluate whether the current message satisfies the requirement.
Usage
Call resolveChannelGroupRequireMention during inbound message routing to determine the mention requirement for a specific group. Then pass the result to resolveMentionGating along with the message's mention detection data to decide whether to process or skip the message.
Code Reference
Source Location
- Repository: openclaw
- File (group policy):
src/config/group-policy.ts - Lines (resolveChannelGroupRequireMention): 148-175
- File (mention gating):
src/channels/mention-gating.ts - Lines (resolveMentionGating): 30-36
Signature (resolveChannelGroupRequireMention)
export function resolveChannelGroupRequireMention(params: {
cfg: OpenClawConfig;
channel: GroupPolicyChannel;
groupId?: string | null;
accountId?: string | null;
requireMentionOverride?: boolean;
overrideOrder?: "before-config" | "after-config";
}): boolean
Signature (resolveMentionGating)
export function resolveMentionGating(params: MentionGateParams): MentionGateResult
Supporting Types
export type MentionGateParams = {
requireMention: boolean;
canDetectMention: boolean;
wasMentioned: boolean;
implicitMention?: boolean;
shouldBypassMention?: boolean;
};
export type MentionGateResult = {
effectiveWasMentioned: boolean;
shouldSkip: boolean;
};
Import
import { resolveChannelGroupRequireMention } from "./config/group-policy.js";
import { resolveMentionGating } from "./channels/mention-gating.js";
I/O Contract
Inputs (resolveChannelGroupRequireMention)
| Name | Type | Required | Description |
|---|---|---|---|
| cfg | OpenClawConfig |
Yes | Current gateway configuration |
| channel | GroupPolicyChannel |
Yes | Channel identifier (e.g., "telegram", "discord")
|
| groupId | null | No | Platform-specific group identifier; used to look up per-group config |
| accountId | null | No | Account identifier; used to resolve account-specific group settings |
| requireMentionOverride | boolean |
No | Programmatic override from the channel adapter |
| overrideOrder | "after-config" | No | Whether the override takes precedence before or after config; defaults to "after-config"
|
Inputs (resolveMentionGating)
| Name | Type | Required | Description |
|---|---|---|---|
| requireMention | boolean |
Yes | Whether a mention is required (from resolveChannelGroupRequireMention)
|
| canDetectMention | boolean |
Yes | Whether the platform supports mention detection |
| wasMentioned | boolean |
Yes | Whether the bot was explicitly mentioned in the message |
| implicitMention | boolean |
No | Whether the message implicitly mentions the bot (e.g., a reply to the bot) |
| shouldBypassMention | boolean |
No | Whether the mention requirement should be bypassed (e.g., control commands) |
Outputs
| Name | Type | Description |
|---|---|---|
| resolveChannelGroupRequireMention | boolean |
Whether mentions are required for the given group; defaults to true
|
| resolveMentionGating | MentionGateResult |
Contains effectiveWasMentioned (consolidated mention status) and shouldSkip (whether to skip processing)
|
Usage Examples
Basic Group Mention Resolution
const requireMention = resolveChannelGroupRequireMention({
cfg,
channel: "telegram",
groupId: "-1001234567890",
accountId: "default",
});
// true if group config says requireMention, or true by default
Full Mention Gating Pipeline
const requireMention = resolveChannelGroupRequireMention({
cfg,
channel: "discord",
groupId: "987654321",
accountId: "default",
});
const { shouldSkip, effectiveWasMentioned } = resolveMentionGating({
requireMention,
canDetectMention: true,
wasMentioned: false,
implicitMention: false,
});
if (shouldSkip) {
return; // Bot was not mentioned; ignore message
}
Override Before Config
// Channel adapter wants to force mention=false for a specific context
const requireMention = resolveChannelGroupRequireMention({
cfg,
channel: "slack",
groupId: "C01234ABCDE",
accountId: "default",
requireMentionOverride: false,
overrideOrder: "before-config",
});
// false, because before-config override takes precedence