feat: unify group mention defaults
This commit is contained in:
@@ -171,7 +171,7 @@ Minimal `~/.clawdis/clawdis.json`:
|
||||
### Telegram
|
||||
|
||||
- Set `TELEGRAM_BOT_TOKEN` or `telegram.botToken` (env wins).
|
||||
- Optional: set `telegram.requireMention`, `telegram.allowFrom`, or `telegram.webhookUrl` as needed.
|
||||
- Optional: set `telegram.groups` (with `telegram.groups."*".requireMention`), `telegram.allowFrom`, or `telegram.webhookUrl` as needed.
|
||||
|
||||
```json5
|
||||
{
|
||||
|
||||
@@ -995,8 +995,8 @@ export async function getReplyFromConfig(
|
||||
const webAuthAgeMs = getWebAuthAgeMs();
|
||||
const heartbeatSeconds = resolveHeartbeatSeconds(cfg, undefined);
|
||||
const groupActivation = isGroup
|
||||
? normalizeGroupActivation(sessionEntry?.groupActivation) ??
|
||||
defaultGroupActivation()
|
||||
? (normalizeGroupActivation(sessionEntry?.groupActivation) ??
|
||||
defaultGroupActivation())
|
||||
: undefined;
|
||||
const statusText = buildStatusMessage({
|
||||
agent: {
|
||||
|
||||
@@ -1235,7 +1235,7 @@ const LEGACY_CONFIG_RULES: LegacyConfigRule[] = [
|
||||
{
|
||||
path: ["telegram", "requireMention"],
|
||||
message:
|
||||
"telegram.requireMention was removed; use telegram.groups.\"*\".requireMention instead (run `clawdis doctor` to migrate).",
|
||||
'telegram.requireMention was removed; use telegram.groups."*".requireMention instead (run `clawdis doctor` to migrate).',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1280,8 +1280,10 @@ const LEGACY_CONFIG_MIGRATIONS: LegacyConfigMigration[] = [
|
||||
const groupChat =
|
||||
(routing as Record<string, unknown>).groupChat &&
|
||||
typeof (routing as Record<string, unknown>).groupChat === "object"
|
||||
? ((routing as Record<string, unknown>)
|
||||
.groupChat as Record<string, unknown>)
|
||||
? ((routing as Record<string, unknown>).groupChat as Record<
|
||||
string,
|
||||
unknown
|
||||
>)
|
||||
: null;
|
||||
if (!groupChat) return;
|
||||
const requireMention = groupChat.requireMention;
|
||||
@@ -1331,18 +1333,22 @@ const LEGACY_CONFIG_MIGRATIONS: LegacyConfigMigration[] = [
|
||||
},
|
||||
{
|
||||
id: "telegram.requireMention->telegram.groups.*.requireMention",
|
||||
describe: "Move telegram.requireMention to telegram.groups.*.requireMention",
|
||||
describe:
|
||||
"Move telegram.requireMention to telegram.groups.*.requireMention",
|
||||
apply: (raw, changes) => {
|
||||
const telegram = raw.telegram;
|
||||
if (!telegram || typeof telegram !== "object") return;
|
||||
const requireMention = (telegram as Record<string, unknown>).requireMention;
|
||||
const requireMention = (telegram as Record<string, unknown>)
|
||||
.requireMention;
|
||||
if (requireMention === undefined) return;
|
||||
|
||||
const groups =
|
||||
(telegram as Record<string, unknown>).groups &&
|
||||
typeof (telegram as Record<string, unknown>).groups === "object"
|
||||
? ((telegram as Record<string, unknown>)
|
||||
.groups as Record<string, unknown>)
|
||||
? ((telegram as Record<string, unknown>).groups as Record<
|
||||
string,
|
||||
unknown
|
||||
>)
|
||||
: {};
|
||||
const defaultKey = "*";
|
||||
const entry =
|
||||
|
||||
@@ -2,7 +2,9 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import * as replyModule from "../auto-reply/reply.js";
|
||||
import { createTelegramBot } from "./bot.js";
|
||||
|
||||
const loadConfig = vi.fn(() => ({}));
|
||||
const { loadConfig } = vi.hoisted(() => ({
|
||||
loadConfig: vi.fn(() => ({})),
|
||||
}));
|
||||
vi.mock("../config/config.js", () => ({
|
||||
loadConfig,
|
||||
}));
|
||||
|
||||
@@ -58,6 +58,14 @@ export function applyConfigSnapshot(state: ConfigState, snapshot: ConfigSnapshot
|
||||
.filter((v) => v.length > 0)
|
||||
.join(", ")
|
||||
: "";
|
||||
const telegramGroups =
|
||||
telegram.groups && typeof telegram.groups === "object"
|
||||
? (telegram.groups as Record<string, unknown>)
|
||||
: {};
|
||||
const telegramDefaultGroup =
|
||||
telegramGroups["*"] && typeof telegramGroups["*"] === "object"
|
||||
? (telegramGroups["*"] as Record<string, unknown>)
|
||||
: {};
|
||||
const allowFrom = Array.isArray(telegram.allowFrom)
|
||||
? toList(telegram.allowFrom)
|
||||
: typeof telegram.allowFrom === "string"
|
||||
@@ -67,7 +75,9 @@ export function applyConfigSnapshot(state: ConfigState, snapshot: ConfigSnapshot
|
||||
state.telegramForm = {
|
||||
token: typeof telegram.botToken === "string" ? telegram.botToken : "",
|
||||
requireMention:
|
||||
typeof telegram.requireMention === "boolean" ? telegram.requireMention : true,
|
||||
typeof telegramDefaultGroup.requireMention === "boolean"
|
||||
? telegramDefaultGroup.requireMention
|
||||
: true,
|
||||
allowFrom,
|
||||
proxy: typeof telegram.proxy === "string" ? telegram.proxy : "",
|
||||
webhookUrl: typeof telegram.webhookUrl === "string" ? telegram.webhookUrl : "",
|
||||
|
||||
@@ -147,7 +147,24 @@ export async function saveTelegramConfig(state: ConnectionsState) {
|
||||
if (token) telegram.botToken = token;
|
||||
else delete telegram.botToken;
|
||||
}
|
||||
telegram.requireMention = state.telegramForm.requireMention;
|
||||
const groups =
|
||||
telegram.groups && typeof telegram.groups === "object"
|
||||
? ({ ...(telegram.groups as Record<string, unknown>) } as Record<
|
||||
string,
|
||||
unknown
|
||||
>)
|
||||
: {};
|
||||
const defaultGroup =
|
||||
groups["*"] && typeof groups["*"] === "object"
|
||||
? ({ ...(groups["*"] as Record<string, unknown>) } as Record<
|
||||
string,
|
||||
unknown
|
||||
>)
|
||||
: {};
|
||||
defaultGroup.requireMention = state.telegramForm.requireMention;
|
||||
groups["*"] = defaultGroup;
|
||||
telegram.groups = groups;
|
||||
delete telegram.requireMention;
|
||||
const allowFrom = parseList(state.telegramForm.allowFrom);
|
||||
if (allowFrom.length > 0) telegram.allowFrom = allowFrom;
|
||||
else delete telegram.allowFrom;
|
||||
|
||||
@@ -298,7 +298,7 @@ function renderProvider(
|
||||
/>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Require mention</span>
|
||||
<span>Require mention in groups</span>
|
||||
<select
|
||||
.value=${props.telegramForm.requireMention ? "yes" : "no"}
|
||||
@change=${(e: Event) =>
|
||||
|
||||
Reference in New Issue
Block a user