Skip to content

Commit e7bacb6

Browse files
edenfunfsteipete
andauthored
fix(line): let the configured policy turn off quote-as-mention (#133619)
* fix(line): honor the configured implicit-mention policy for quotes * fix(line): apply implicit quote policy at shared ingress Pass the existing resolved policy to the shared mention gate. Consolidate quote-policy coverage for default, enabled, disabled and explicit mentions, including ambient history for skipped quotes. Keep the real mention helper behind its narrow SDK facade. Co-authored-by: xuyuanhao <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: xuyuanhao <[email protected]>
1 parent 006527d commit e7bacb6

4 files changed

Lines changed: 51 additions & 16 deletions

File tree

‎docs/channels/groups.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ Supported implicit mention facts are channel-specific:
343343
| Quote of the bot | LINE, WhatsApp, Zalo personal |
344344
| Bot joined the thread | Mattermost, Slack, Tlon |
345345

346-
Each fact defaults to enabled when the channel produces it. Among bundled channels, Mattermost, Slack, and Tlon read the corresponding `implicitMentions` flag; set it to `false` to stop that fact from bypassing mention gating. Native explicit mentions remain unaffected. The other bundled producers listed above do not currently read `implicitMentions`, so their facts always count as mentions and the flag cannot turn them off. A flag also has no effect on channels that do not produce that fact.
346+
Each fact defaults to enabled when the channel produces it. Among bundled channels, LINE, Mattermost, Slack, and Tlon read the corresponding `implicitMentions` flag; set it to `false` to stop that fact from bypassing mention gating. LINE reads it from the shared `channels.defaults.implicitMentions` block only; it does not accept a channel- or account-scoped `implicitMentions` block of its own. Native explicit mentions remain unaffected. The other bundled producers listed above do not currently read `implicitMentions`, so their facts always count as mentions and the flag cannot turn them off. A flag also has no effect on channels that do not produce that fact.
347347

348348
```json5
349349
{

‎docs/channels/line.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ Allowlists and policies:
225225
`groupPolicy: "allowlist"`, set `groupAllowFrom` or the per-group `allowFrom`; an empty group allowlist blocks group messages even when DMs are open.
226226
- `channels.line.groups."*"` is the defaults entry for every group and room, not a fallback that a named entry replaces. A named entry overrides `"*"` field by field, so each field the named entry omits is taken from `"*"`. This matches how `requireMention` already resolves through the shared group scope tree; see [Groups](/channels/groups).
227227
- Upgrade check: if you set `enabled` or `allowFrom` only on `channels.line.groups."*"` while also listing a named group or room, those wildcard values now apply to that named entry as well. Earlier releases returned the named entry alone, so wildcard-only fields never reached it. Before upgrading, review any `"*"` entry that sets `enabled: false` or narrows `allowFrom`, and repeat the value on a named entry that should keep its current access.
228-
- Quoting one of the bot's own messages counts as addressing it, so a group reply made with LINE's quote gesture reaches the agent without an explicit mention. LINE does not read the `implicitMentions` flags, so this always counts; see [Groups](/channels/groups). The bot recognizes a quote of its own message from the most recent ones it remembers sending (a few hundred per account), so quoting an older message, or one sent before the last Gateway restart, still needs a mention.
228+
- Quoting one of the bot's own messages counts as addressing it, so a group reply made with LINE's quote gesture reaches the agent without an explicit mention. Set `channels.defaults.implicitMentions.quotedBot: false` to stop it from bypassing the mention requirement; LINE reads that shared default and has no channel-scoped `implicitMentions` block of its own. See [Groups](/channels/groups). The bot recognizes a quote of its own message from the most recent ones it remembers sending (a few hundred per account), so quoting an older message, or one sent before the last Gateway restart, still needs a mention.
229229
- Static sender access groups can be referenced from `allowFrom`, `groupAllowFrom`, and per-group `allowFrom` with `accessGroup:<name>`; see [Access groups](/channels/access-groups).
230230
- Runtime note: if `channels.line` is completely missing, runtime falls back to `groupPolicy="allowlist"` for group checks (even if `channels.defaults.groupPolicy` is set).
231231

‎extensions/line/src/bot-handlers.test.ts‎

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ const pairingDeliveryMocks = vi.hoisted(() => ({
1919

2020
// Avoid pulling in globals/pairing/media dependencies; this suite only asserts
2121
// allowlist/groupPolicy gating and message-context wiring.
22-
vi.mock("openclaw/plugin-sdk/channel-inbound", async (importOriginal) => ({
23-
// Mention-kind construction is pure and part of the behavior under test, so it
24-
// comes from the real module rather than a stub.
25-
...(await importOriginal<typeof import("openclaw/plugin-sdk/channel-inbound")>()),
22+
vi.mock("openclaw/plugin-sdk/channel-inbound", async () => ({
23+
// Keep mention facts real without loading the inbound execution lifecycle.
24+
implicitMentionKindWhen: (await import("openclaw/plugin-sdk/channel-mention-gating"))
25+
.implicitMentionKindWhen,
2626
buildMentionRegexes: () => [],
2727
isChannelPartialDeliveryError: (error: unknown) =>
2828
Boolean(
@@ -264,6 +264,7 @@ function createLineWebhookTestContext(params: {
264264
requireMention?: boolean;
265265
groupHistories?: Map<string, HistoryEntry[]>;
266266
accessGroups?: Record<string, { type: "message.senders"; members: Record<string, string[]> }>;
267+
implicitMentions?: { quotedBot?: boolean };
267268
}): Parameters<typeof handleLineWebhookEvents>[1] {
268269
const allowFrom = params.allowFrom ?? (params.dmPolicy === "open" ? ["*"] : undefined);
269270
const lineConfig = {
@@ -275,7 +276,10 @@ function createLineWebhookTestContext(params: {
275276
return {
276277
cfg: {
277278
...(params.accessGroups ? { accessGroups: params.accessGroups } : {}),
278-
channels: { line: lineConfig },
279+
channels: {
280+
line: lineConfig,
281+
defaults: { implicitMentions: params.implicitMentions },
282+
},
279283
},
280284
account: {
281285
accountId: "default",
@@ -1230,20 +1234,38 @@ describe("handleLineWebhookEvents", () => {
12301234
expect(buildLineMessageContextMock).not.toHaveBeenCalled();
12311235
});
12321236

1233-
it("processes a group message that quotes the bot's own message when requireMention is set", async () => {
1237+
it.each([
1238+
{ name: "default quote policy", quotedBot: undefined, mentioned: false, dispatched: true },
1239+
{ name: "enabled quote policy", quotedBot: true, mentioned: false, dispatched: true },
1240+
{ name: "disabled quote policy", quotedBot: false, mentioned: false, dispatched: false },
1241+
{
1242+
name: "explicit mention with quotes disabled",
1243+
quotedBot: false,
1244+
mentioned: true,
1245+
dispatched: true,
1246+
},
1247+
])("respects $name for a quote of the bot", async ({ quotedBot, mentioned, dispatched }) => {
12341248
const processMessage = vi.fn();
1235-
// The id LINE returns for a push is the id a later quote points at.
1236-
recordLineSentMessages("default", ["m-bot-sent-1"]);
1249+
const groupHistories = new Map<string, HistoryEntry[]>();
1250+
recordLineSentMessages("default", ["m-bot-quote-policy"]);
1251+
const text = mentioned ? "@Bot explain this" : "does quoting you count as addressing you";
12371252
const event = createTestMessageEvent({
12381253
message: {
1239-
id: "m-quote-1",
1254+
id: "m-quote-policy",
12401255
type: "text",
1241-
text: "does quoting you count as addressing you",
1242-
quotedMessageId: "m-bot-sent-1",
1243-
quoteToken: "q-quote-1",
1256+
text,
1257+
quotedMessageId: "m-bot-quote-policy",
1258+
quoteToken: "q-quote-policy",
1259+
...(mentioned
1260+
? {
1261+
mention: {
1262+
mentionees: [{ index: 0, length: 4, type: "user" as const, isSelf: true }],
1263+
},
1264+
}
1265+
: {}),
12441266
},
12451267
source: { type: "group", groupId: "group-quote", userId: "user-quote" },
1246-
webhookEventId: "evt-quote-1",
1268+
webhookEventId: "evt-quote-policy",
12471269
});
12481270

12491271
await handleLineWebhookEvents(
@@ -1252,10 +1274,16 @@ describe("handleLineWebhookEvents", () => {
12521274
processMessage,
12531275
groupPolicy: "open",
12541276
requireMention: true,
1277+
implicitMentions: { quotedBot },
1278+
groupHistories,
12551279
}),
12561280
);
12571281

1258-
expect(processMessage).toHaveBeenCalled();
1282+
expect.soft(processMessage).toHaveBeenCalledTimes(dispatched ? 1 : 0);
1283+
expect.soft(buildLineMessageContextMock).toHaveBeenCalledTimes(dispatched ? 1 : 0);
1284+
expect(groupHistories.get("group-quote") ?? []).toEqual(
1285+
dispatched ? [] : [expect.objectContaining({ sender: "user-quote", body: text })],
1286+
);
12591287
});
12601288

12611289
it("skips a group message quoting a message the bot did not send", async () => {

‎extensions/line/src/bot-handlers.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
type ChannelInboundMediaInput,
1010
} from "openclaw/plugin-sdk/channel-inbound";
1111
import {
12+
resolveChannelImplicitMentions,
1213
resolveStableChannelMessageIngress,
1314
type ChannelIngressContextBinding,
1415
type ResolvedChannelMessageIngress,
@@ -263,6 +264,12 @@ async function resolveLineEventAdmission(
263264
activation: {
264265
requireMention: isGroup && event.type === "message" && requireMention,
265266
allowTextCommands: true,
267+
// Apply quote policy in the shared gate, preserving explicit mentions.
268+
implicitMentions: resolveChannelImplicitMentions({
269+
cfg,
270+
channel: "line",
271+
accountId: account.accountId,
272+
}),
266273
},
267274
},
268275
allowFrom: normalizeStringEntries(account.config.allowFrom),

0 commit comments

Comments
 (0)