fix: lint errors
This commit is contained in:
committed by
Peter Steinberger
parent
0e1dcf9cb4
commit
eb7656d68c
@@ -91,14 +91,7 @@ export type SessionConfig = {
|
||||
export type LoggingConfig = {
|
||||
level?: "silent" | "fatal" | "error" | "warn" | "info" | "debug" | "trace";
|
||||
file?: string;
|
||||
consoleLevel?:
|
||||
| "silent"
|
||||
| "fatal"
|
||||
| "error"
|
||||
| "warn"
|
||||
| "info"
|
||||
| "debug"
|
||||
| "trace";
|
||||
consoleLevel?: "silent" | "fatal" | "error" | "warn" | "info" | "debug" | "trace";
|
||||
consoleStyle?: "pretty" | "compact" | "json";
|
||||
/** Redact sensitive tokens in tool summaries. Default: "tools". */
|
||||
redactSensitive?: "off" | "tools";
|
||||
@@ -122,9 +115,7 @@ export type WebConfig = {
|
||||
};
|
||||
|
||||
// Provider docking: allowlists keyed by provider id (and internal "webchat").
|
||||
export type AgentElevatedAllowFromConfig = Partial<
|
||||
Record<string, Array<string | number>>
|
||||
>;
|
||||
export type AgentElevatedAllowFromConfig = Partial<Record<string, Array<string | number>>>;
|
||||
|
||||
export type IdentityConfig = {
|
||||
name?: string;
|
||||
@@ -495,11 +486,7 @@ export type DiscordGuildChannelConfig = {
|
||||
systemPrompt?: string;
|
||||
};
|
||||
|
||||
export type DiscordReactionNotificationMode =
|
||||
| "off"
|
||||
| "own"
|
||||
| "all"
|
||||
| "allowlist";
|
||||
export type DiscordReactionNotificationMode = "off" | "own" | "all" | "allowlist";
|
||||
|
||||
export type DiscordGuildEntry = {
|
||||
slug?: string;
|
||||
@@ -614,11 +601,7 @@ export type SlackChannelConfig = {
|
||||
systemPrompt?: string;
|
||||
};
|
||||
|
||||
export type SignalReactionNotificationMode =
|
||||
| "off"
|
||||
| "own"
|
||||
| "all"
|
||||
| "allowlist";
|
||||
export type SignalReactionNotificationMode = "off" | "own" | "all" | "allowlist";
|
||||
|
||||
export type SlackReactionNotificationMode = "off" | "own" | "all" | "allowlist";
|
||||
|
||||
@@ -1863,4 +1846,4 @@ export type ConfigFileSnapshot = {
|
||||
config: ClawdbotConfig;
|
||||
issues: ConfigValidationIssue[];
|
||||
legacyIssues: LegacyConfigIssue[];
|
||||
};
|
||||
};
|
||||
|
||||
@@ -87,16 +87,8 @@ const QueueModeSchema = z.union([
|
||||
z.literal("queue"),
|
||||
z.literal("interrupt"),
|
||||
]);
|
||||
const QueueDropSchema = z.union([
|
||||
z.literal("old"),
|
||||
z.literal("new"),
|
||||
z.literal("summarize"),
|
||||
]);
|
||||
const ReplyToModeSchema = z.union([
|
||||
z.literal("off"),
|
||||
z.literal("first"),
|
||||
z.literal("all"),
|
||||
]);
|
||||
const QueueDropSchema = z.union([z.literal("old"), z.literal("new"), z.literal("summarize")]);
|
||||
const ReplyToModeSchema = z.union([z.literal("off"), z.literal("first"), z.literal("all")]);
|
||||
|
||||
// GroupPolicySchema: controls how group messages are handled
|
||||
// Used with .default("allowlist").optional() pattern:
|
||||
@@ -116,18 +108,12 @@ const BlockStreamingChunkSchema = z.object({
|
||||
minChars: z.number().int().positive().optional(),
|
||||
maxChars: z.number().int().positive().optional(),
|
||||
breakPreference: z
|
||||
.union([
|
||||
z.literal("paragraph"),
|
||||
z.literal("newline"),
|
||||
z.literal("sentence"),
|
||||
])
|
||||
.union([z.literal("paragraph"), z.literal("newline"), z.literal("sentence")])
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const HumanDelaySchema = z.object({
|
||||
mode: z
|
||||
.union([z.literal("off"), z.literal("natural"), z.literal("custom")])
|
||||
.optional(),
|
||||
mode: z.union([z.literal("off"), z.literal("natural"), z.literal("custom")]).optional(),
|
||||
minMs: z.number().int().nonnegative().optional(),
|
||||
maxMs: z.number().int().nonnegative().optional(),
|
||||
});
|
||||
@@ -135,12 +121,8 @@ const HumanDelaySchema = z.object({
|
||||
const CliBackendSchema = z.object({
|
||||
command: z.string(),
|
||||
args: z.array(z.string()).optional(),
|
||||
output: z
|
||||
.union([z.literal("json"), z.literal("text"), z.literal("jsonl")])
|
||||
.optional(),
|
||||
resumeOutput: z
|
||||
.union([z.literal("json"), z.literal("text"), z.literal("jsonl")])
|
||||
.optional(),
|
||||
output: z.union([z.literal("json"), z.literal("text"), z.literal("jsonl")]).optional(),
|
||||
resumeOutput: z.union([z.literal("json"), z.literal("text"), z.literal("jsonl")]).optional(),
|
||||
input: z.union([z.literal("arg"), z.literal("stdin")]).optional(),
|
||||
maxPromptArgChars: z.number().int().positive().optional(),
|
||||
env: z.record(z.string(), z.string()).optional(),
|
||||
@@ -150,14 +132,10 @@ const CliBackendSchema = z.object({
|
||||
sessionArg: z.string().optional(),
|
||||
sessionArgs: z.array(z.string()).optional(),
|
||||
resumeArgs: z.array(z.string()).optional(),
|
||||
sessionMode: z
|
||||
.union([z.literal("always"), z.literal("existing"), z.literal("none")])
|
||||
.optional(),
|
||||
sessionMode: z.union([z.literal("always"), z.literal("existing"), z.literal("none")]).optional(),
|
||||
sessionIdFields: z.array(z.string()).optional(),
|
||||
systemPromptArg: z.string().optional(),
|
||||
systemPromptMode: z
|
||||
.union([z.literal("append"), z.literal("replace")])
|
||||
.optional(),
|
||||
systemPromptMode: z.union([z.literal("append"), z.literal("replace")]).optional(),
|
||||
systemPromptWhen: z
|
||||
.union([z.literal("first"), z.literal("always"), z.literal("never")])
|
||||
.optional(),
|
||||
@@ -236,9 +214,7 @@ const TranscribeAudioSchema = z
|
||||
})
|
||||
.optional();
|
||||
|
||||
const HexColorSchema = z
|
||||
.string()
|
||||
.regex(/^#?[0-9a-fA-F]{6}$/, "expected hex color (RRGGBB)");
|
||||
const HexColorSchema = z.string().regex(/^#?[0-9a-fA-F]{6}$/, "expected hex color (RRGGBB)");
|
||||
|
||||
const ExecutableTokenSchema = z
|
||||
.string()
|
||||
@@ -312,18 +288,16 @@ const TelegramAccountSchemaBase = z.object({
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const TelegramAccountSchema = TelegramAccountSchemaBase.superRefine(
|
||||
(value, ctx) => {
|
||||
requireOpenAllowFrom({
|
||||
policy: value.dmPolicy,
|
||||
allowFrom: value.allowFrom,
|
||||
ctx,
|
||||
path: ["allowFrom"],
|
||||
message:
|
||||
'channels.telegram.dmPolicy="open" requires channels.telegram.allowFrom to include "*"',
|
||||
});
|
||||
},
|
||||
);
|
||||
const TelegramAccountSchema = TelegramAccountSchemaBase.superRefine((value, ctx) => {
|
||||
requireOpenAllowFrom({
|
||||
policy: value.dmPolicy,
|
||||
allowFrom: value.allowFrom,
|
||||
ctx,
|
||||
path: ["allowFrom"],
|
||||
message:
|
||||
'channels.telegram.dmPolicy="open" requires channels.telegram.allowFrom to include "*"',
|
||||
});
|
||||
});
|
||||
|
||||
const TelegramConfigSchema = TelegramAccountSchemaBase.extend({
|
||||
accounts: z.record(z.string(), TelegramAccountSchema.optional()).optional(),
|
||||
@@ -372,9 +346,7 @@ const DiscordGuildSchema = z.object({
|
||||
requireMention: z.boolean().optional(),
|
||||
reactionNotifications: z.enum(["off", "own", "all", "allowlist"]).optional(),
|
||||
users: z.array(z.union([z.string(), z.number()])).optional(),
|
||||
channels: z
|
||||
.record(z.string(), DiscordGuildChannelSchema.optional())
|
||||
.optional(),
|
||||
channels: z.record(z.string(), DiscordGuildChannelSchema.optional()).optional(),
|
||||
});
|
||||
|
||||
const DiscordAccountSchema = z.object({
|
||||
@@ -527,18 +499,15 @@ const SignalAccountSchemaBase = z.object({
|
||||
reactionAllowlist: z.array(z.union([z.string(), z.number()])).optional(),
|
||||
});
|
||||
|
||||
const SignalAccountSchema = SignalAccountSchemaBase.superRefine(
|
||||
(value, ctx) => {
|
||||
requireOpenAllowFrom({
|
||||
policy: value.dmPolicy,
|
||||
allowFrom: value.allowFrom,
|
||||
ctx,
|
||||
path: ["allowFrom"],
|
||||
message:
|
||||
'channels.signal.dmPolicy="open" requires channels.signal.allowFrom to include "*"',
|
||||
});
|
||||
},
|
||||
);
|
||||
const SignalAccountSchema = SignalAccountSchemaBase.superRefine((value, ctx) => {
|
||||
requireOpenAllowFrom({
|
||||
policy: value.dmPolicy,
|
||||
allowFrom: value.allowFrom,
|
||||
ctx,
|
||||
path: ["allowFrom"],
|
||||
message: 'channels.signal.dmPolicy="open" requires channels.signal.allowFrom to include "*"',
|
||||
});
|
||||
});
|
||||
|
||||
const SignalConfigSchema = SignalAccountSchemaBase.extend({
|
||||
accounts: z.record(z.string(), SignalAccountSchema.optional()).optional(),
|
||||
@@ -548,8 +517,7 @@ const SignalConfigSchema = SignalAccountSchemaBase.extend({
|
||||
allowFrom: value.allowFrom,
|
||||
ctx,
|
||||
path: ["allowFrom"],
|
||||
message:
|
||||
'channels.signal.dmPolicy="open" requires channels.signal.allowFrom to include "*"',
|
||||
message: 'channels.signal.dmPolicy="open" requires channels.signal.allowFrom to include "*"',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -559,9 +527,7 @@ const IMessageAccountSchemaBase = z.object({
|
||||
enabled: z.boolean().optional(),
|
||||
cliPath: ExecutableTokenSchema.optional(),
|
||||
dbPath: z.string().optional(),
|
||||
service: z
|
||||
.union([z.literal("imessage"), z.literal("sms"), z.literal("auto")])
|
||||
.optional(),
|
||||
service: z.union([z.literal("imessage"), z.literal("sms"), z.literal("auto")]).optional(),
|
||||
region: z.string().optional(),
|
||||
dmPolicy: DmPolicySchema.optional().default("pairing"),
|
||||
allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
|
||||
@@ -587,18 +553,16 @@ const IMessageAccountSchemaBase = z.object({
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const IMessageAccountSchema = IMessageAccountSchemaBase.superRefine(
|
||||
(value, ctx) => {
|
||||
requireOpenAllowFrom({
|
||||
policy: value.dmPolicy,
|
||||
allowFrom: value.allowFrom,
|
||||
ctx,
|
||||
path: ["allowFrom"],
|
||||
message:
|
||||
'channels.imessage.dmPolicy="open" requires channels.imessage.allowFrom to include "*"',
|
||||
});
|
||||
},
|
||||
);
|
||||
const IMessageAccountSchema = IMessageAccountSchemaBase.superRefine((value, ctx) => {
|
||||
requireOpenAllowFrom({
|
||||
policy: value.dmPolicy,
|
||||
allowFrom: value.allowFrom,
|
||||
ctx,
|
||||
path: ["allowFrom"],
|
||||
message:
|
||||
'channels.imessage.dmPolicy="open" requires channels.imessage.allowFrom to include "*"',
|
||||
});
|
||||
});
|
||||
|
||||
const IMessageConfigSchema = IMessageAccountSchemaBase.extend({
|
||||
accounts: z.record(z.string(), IMessageAccountSchema.optional()).optional(),
|
||||
@@ -696,24 +660,18 @@ const WhatsAppAccountSchema = z
|
||||
.object({
|
||||
emoji: z.string().optional(),
|
||||
direct: z.boolean().optional().default(true),
|
||||
group: z
|
||||
.enum(["always", "mentions", "never"])
|
||||
.optional()
|
||||
.default("mentions"),
|
||||
group: z.enum(["always", "mentions", "never"]).optional().default("mentions"),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
.superRefine((value, ctx) => {
|
||||
if (value.dmPolicy !== "open") return;
|
||||
const allow = (value.allowFrom ?? [])
|
||||
.map((v) => String(v).trim())
|
||||
.filter(Boolean);
|
||||
const allow = (value.allowFrom ?? []).map((v) => String(v).trim()).filter(Boolean);
|
||||
if (allow.includes("*")) return;
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: ["allowFrom"],
|
||||
message:
|
||||
'channels.whatsapp.accounts.*.dmPolicy="open" requires allowFrom to include "*"',
|
||||
message: 'channels.whatsapp.accounts.*.dmPolicy="open" requires allowFrom to include "*"',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -755,18 +713,13 @@ const WhatsAppConfigSchema = z
|
||||
.object({
|
||||
emoji: z.string().optional(),
|
||||
direct: z.boolean().optional().default(true),
|
||||
group: z
|
||||
.enum(["always", "mentions", "never"])
|
||||
.optional()
|
||||
.default("mentions"),
|
||||
group: z.enum(["always", "mentions", "never"]).optional().default("mentions"),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
.superRefine((value, ctx) => {
|
||||
if (value.dmPolicy !== "open") return;
|
||||
const allow = (value.allowFrom ?? [])
|
||||
.map((v) => String(v).trim())
|
||||
.filter(Boolean);
|
||||
const allow = (value.allowFrom ?? []).map((v) => String(v).trim()).filter(Boolean);
|
||||
if (allow.includes("*")) return;
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
@@ -816,11 +769,7 @@ const SessionSchema = z
|
||||
.object({
|
||||
channel: z.string().optional(),
|
||||
chatType: z
|
||||
.union([
|
||||
z.literal("direct"),
|
||||
z.literal("group"),
|
||||
z.literal("room"),
|
||||
])
|
||||
.union([z.literal("direct"), z.literal("group"), z.literal("room")])
|
||||
.optional(),
|
||||
keyPrefix: z.string().optional(),
|
||||
})
|
||||
@@ -845,9 +794,7 @@ const MessagesSchema = z
|
||||
groupChat: GroupChatSchema,
|
||||
queue: QueueSchema,
|
||||
ackReaction: z.string().optional(),
|
||||
ackReactionScope: z
|
||||
.enum(["group-mentions", "group-all", "direct", "all"])
|
||||
.optional(),
|
||||
ackReactionScope: z.enum(["group-mentions", "group-all", "direct", "all"]).optional(),
|
||||
removeAckAfterReply: z.boolean().optional(),
|
||||
})
|
||||
.optional();
|
||||
@@ -972,12 +919,7 @@ const ToolPolicySchema = z
|
||||
.optional();
|
||||
|
||||
const ToolProfileSchema = z
|
||||
.union([
|
||||
z.literal("minimal"),
|
||||
z.literal("coding"),
|
||||
z.literal("messaging"),
|
||||
z.literal("full"),
|
||||
])
|
||||
.union([z.literal("minimal"), z.literal("coding"), z.literal("messaging"), z.literal("full")])
|
||||
.optional();
|
||||
|
||||
// Provider docking: allowlists keyed by provider id (no schema updates when adding providers).
|
||||
@@ -987,18 +929,10 @@ const ElevatedAllowFromSchema = z
|
||||
|
||||
const AgentSandboxSchema = z
|
||||
.object({
|
||||
mode: z
|
||||
.union([z.literal("off"), z.literal("non-main"), z.literal("all")])
|
||||
.optional(),
|
||||
workspaceAccess: z
|
||||
.union([z.literal("none"), z.literal("ro"), z.literal("rw")])
|
||||
.optional(),
|
||||
sessionToolsVisibility: z
|
||||
.union([z.literal("spawned"), z.literal("all")])
|
||||
.optional(),
|
||||
scope: z
|
||||
.union([z.literal("session"), z.literal("agent"), z.literal("shared")])
|
||||
.optional(),
|
||||
mode: z.union([z.literal("off"), z.literal("non-main"), z.literal("all")]).optional(),
|
||||
workspaceAccess: z.union([z.literal("none"), z.literal("ro"), z.literal("rw")]).optional(),
|
||||
sessionToolsVisibility: z.union([z.literal("spawned"), z.literal("all")]).optional(),
|
||||
scope: z.union([z.literal("session"), z.literal("agent"), z.literal("shared")]).optional(),
|
||||
perSession: z.boolean().optional(),
|
||||
workspaceRoot: z.string().optional(),
|
||||
docker: SandboxDockerSchema,
|
||||
@@ -1181,11 +1115,7 @@ const BindingsSchema = z
|
||||
accountId: z.string().optional(),
|
||||
peer: z
|
||||
.object({
|
||||
kind: z.union([
|
||||
z.literal("dm"),
|
||||
z.literal("group"),
|
||||
z.literal("channel"),
|
||||
]),
|
||||
kind: z.union([z.literal("dm"), z.literal("group"), z.literal("channel")]),
|
||||
id: z.string(),
|
||||
})
|
||||
.optional(),
|
||||
@@ -1221,9 +1151,7 @@ const HookMappingSchema = z
|
||||
})
|
||||
.optional(),
|
||||
action: z.union([z.literal("wake"), z.literal("agent")]).optional(),
|
||||
wakeMode: z
|
||||
.union([z.literal("now"), z.literal("next-heartbeat")])
|
||||
.optional(),
|
||||
wakeMode: z.union([z.literal("now"), z.literal("next-heartbeat")]).optional(),
|
||||
name: z.string().optional(),
|
||||
sessionKey: z.string().optional(),
|
||||
messageTemplate: z.string().optional(),
|
||||
@@ -1274,9 +1202,7 @@ const HooksGmailSchema = z
|
||||
.optional(),
|
||||
tailscale: z
|
||||
.object({
|
||||
mode: z
|
||||
.union([z.literal("off"), z.literal("serve"), z.literal("funnel")])
|
||||
.optional(),
|
||||
mode: z.union([z.literal("off"), z.literal("serve"), z.literal("funnel")]).optional(),
|
||||
path: z.string().optional(),
|
||||
target: z.string().optional(),
|
||||
})
|
||||
@@ -1328,11 +1254,7 @@ const AgentDefaultsSchema = z
|
||||
contextPruning: z
|
||||
.object({
|
||||
mode: z
|
||||
.union([
|
||||
z.literal("off"),
|
||||
z.literal("adaptive"),
|
||||
z.literal("aggressive"),
|
||||
])
|
||||
.union([z.literal("off"), z.literal("adaptive"), z.literal("aggressive")])
|
||||
.optional(),
|
||||
keepLastAssistants: z.number().int().nonnegative().optional(),
|
||||
softTrimRatio: z.number().min(0).max(1).optional(),
|
||||
@@ -1361,9 +1283,7 @@ const AgentDefaultsSchema = z
|
||||
.optional(),
|
||||
compaction: z
|
||||
.object({
|
||||
mode: z
|
||||
.union([z.literal("default"), z.literal("safeguard")])
|
||||
.optional(),
|
||||
mode: z.union([z.literal("default"), z.literal("safeguard")]).optional(),
|
||||
reserveTokensFloor: z.number().int().nonnegative().optional(),
|
||||
memoryFlush: z
|
||||
.object({
|
||||
@@ -1387,12 +1307,8 @@ const AgentDefaultsSchema = z
|
||||
.optional(),
|
||||
verboseDefault: z.union([z.literal("off"), z.literal("on")]).optional(),
|
||||
elevatedDefault: z.union([z.literal("off"), z.literal("on")]).optional(),
|
||||
blockStreamingDefault: z
|
||||
.union([z.literal("off"), z.literal("on")])
|
||||
.optional(),
|
||||
blockStreamingBreak: z
|
||||
.union([z.literal("text_end"), z.literal("message_end")])
|
||||
.optional(),
|
||||
blockStreamingDefault: z.union([z.literal("off"), z.literal("on")]).optional(),
|
||||
blockStreamingBreak: z.union([z.literal("text_end"), z.literal("message_end")]).optional(),
|
||||
blockStreamingChunk: BlockStreamingChunkSchema.optional(),
|
||||
blockStreamingCoalesce: BlockStreamingCoalesceSchema.optional(),
|
||||
humanDelay: HumanDelaySchema.optional(),
|
||||
@@ -1426,22 +1342,10 @@ const AgentDefaultsSchema = z
|
||||
.optional(),
|
||||
sandbox: z
|
||||
.object({
|
||||
mode: z
|
||||
.union([z.literal("off"), z.literal("non-main"), z.literal("all")])
|
||||
.optional(),
|
||||
workspaceAccess: z
|
||||
.union([z.literal("none"), z.literal("ro"), z.literal("rw")])
|
||||
.optional(),
|
||||
sessionToolsVisibility: z
|
||||
.union([z.literal("spawned"), z.literal("all")])
|
||||
.optional(),
|
||||
scope: z
|
||||
.union([
|
||||
z.literal("session"),
|
||||
z.literal("agent"),
|
||||
z.literal("shared"),
|
||||
])
|
||||
.optional(),
|
||||
mode: z.union([z.literal("off"), z.literal("non-main"), z.literal("all")]).optional(),
|
||||
workspaceAccess: z.union([z.literal("none"), z.literal("ro"), z.literal("rw")]).optional(),
|
||||
sessionToolsVisibility: z.union([z.literal("spawned"), z.literal("all")]).optional(),
|
||||
scope: z.union([z.literal("session"), z.literal("agent"), z.literal("shared")]).optional(),
|
||||
perSession: z.boolean().optional(),
|
||||
workspaceRoot: z.string().optional(),
|
||||
docker: SandboxDockerSchema,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -17,15 +17,8 @@ import {
|
||||
resolveChannelGroupPolicy,
|
||||
resolveChannelGroupRequireMention,
|
||||
} from "../config/group-policy.js";
|
||||
import {
|
||||
loadSessionStore,
|
||||
resolveStorePath,
|
||||
updateLastRoute,
|
||||
} from "../config/sessions.js";
|
||||
import { loadSessionStore, resolveStorePath } from "../config/sessions.js";
|
||||
import { danger, logVerbose, shouldLogVerbose } from "../globals.js";
|
||||
import { recordChannelActivity } from "../infra/channel-activity.js";
|
||||
import { createDedupeCache } from "../infra/dedupe.js";
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
import { enqueueSystemEvent } from "../infra/system-events.js";
|
||||
import { getChildLogger } from "../logging.js";
|
||||
import { resolveAgentRoute } from "../routing/resolve-route.js";
|
||||
@@ -47,12 +40,6 @@ import {
|
||||
type TelegramUpdateKeyContext,
|
||||
} from "./bot-updates.js";
|
||||
import { resolveTelegramFetch } from "./fetch.js";
|
||||
import {
|
||||
readTelegramAllowFromStore,
|
||||
upsertTelegramPairingRequest,
|
||||
} from "./pairing-store.js";
|
||||
import { wasSentByBot } from "./sent-message-cache.js";
|
||||
import { resolveTelegramVoiceSend } from "./voice.js";
|
||||
|
||||
export type TelegramBotOptions = {
|
||||
token: string;
|
||||
@@ -334,23 +321,18 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
||||
// Detect added reactions
|
||||
const oldEmojis = new Set(
|
||||
reaction.old_reaction
|
||||
.filter(
|
||||
(r): r is { type: "emoji"; emoji: string } => r.type === "emoji",
|
||||
)
|
||||
.filter((r): r is { type: "emoji"; emoji: string } => r.type === "emoji")
|
||||
.map((r) => r.emoji),
|
||||
);
|
||||
const addedReactions = reaction.new_reaction
|
||||
.filter(
|
||||
(r): r is { type: "emoji"; emoji: string } => r.type === "emoji",
|
||||
)
|
||||
.filter((r): r is { type: "emoji"; emoji: string } => r.type === "emoji")
|
||||
.filter((r) => !oldEmojis.has(r.emoji));
|
||||
|
||||
if (addedReactions.length === 0) return;
|
||||
|
||||
// Build sender label
|
||||
const senderName = user
|
||||
? [user.first_name, user.last_name].filter(Boolean).join(" ").trim() ||
|
||||
user.username
|
||||
? [user.first_name, user.last_name].filter(Boolean).join(" ").trim() || user.username
|
||||
: undefined;
|
||||
const senderUsername = user?.username ? `@${user.username}` : undefined;
|
||||
let senderLabel = senderName;
|
||||
@@ -373,11 +355,8 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
||||
});
|
||||
|
||||
// Resolve agent route for session
|
||||
const isGroup =
|
||||
reaction.chat.type === "group" || reaction.chat.type === "supergroup";
|
||||
const peerId = isGroup
|
||||
? buildTelegramGroupPeerId(chatId, resolvedThreadId)
|
||||
: String(chatId);
|
||||
const isGroup = reaction.chat.type === "group" || reaction.chat.type === "supergroup";
|
||||
const peerId = isGroup ? buildTelegramGroupPeerId(chatId, resolvedThreadId) : String(chatId);
|
||||
const route = resolveAgentRoute({
|
||||
cfg,
|
||||
channel: "telegram",
|
||||
@@ -396,9 +375,7 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
||||
logVerbose(`telegram: reaction event enqueued: ${text}`);
|
||||
}
|
||||
} catch (err) {
|
||||
runtime.error?.(
|
||||
danger(`telegram reaction handler failed: ${String(err)}`),
|
||||
);
|
||||
runtime.error?.(danger(`telegram reaction handler failed: ${String(err)}`));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -34,10 +34,7 @@ export function createTelegramRunnerOptions(cfg: ClawdbotConfig): RunOptions<unk
|
||||
// Match grammY defaults
|
||||
timeout: 30,
|
||||
// Request reaction updates from Telegram
|
||||
allowed_updates: [
|
||||
"message",
|
||||
"message_reaction",
|
||||
],
|
||||
allowed_updates: ["message", "message_reaction"],
|
||||
},
|
||||
// Suppress grammY getUpdates stack traces; we log concise errors ourselves.
|
||||
silent: true,
|
||||
|
||||
@@ -24,8 +24,7 @@ export function resolveTelegramReactionLevel(params: {
|
||||
cfg: params.cfg,
|
||||
accountId: params.accountId,
|
||||
});
|
||||
const level = (account.config.reactionLevel ??
|
||||
"ack") as TelegramReactionLevel;
|
||||
const level = (account.config.reactionLevel ?? "ack") as TelegramReactionLevel;
|
||||
|
||||
switch (level) {
|
||||
case "off":
|
||||
|
||||
@@ -18,10 +18,7 @@ import { resolveTelegramAccount } from "./accounts.js";
|
||||
import { resolveTelegramFetch } from "./fetch.js";
|
||||
import { markdownToTelegramHtml } from "./format.js";
|
||||
import { recordSentMessage } from "./sent-message-cache.js";
|
||||
import {
|
||||
parseTelegramTarget,
|
||||
stripTelegramInternalPrefixes,
|
||||
} from "./targets.js";
|
||||
import { parseTelegramTarget, stripTelegramInternalPrefixes } from "./targets.js";
|
||||
import { resolveTelegramVoiceSend } from "./voice.js";
|
||||
|
||||
type TelegramSendOpts = {
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
clearSentMessageCache,
|
||||
recordSentMessage,
|
||||
wasSentByBot,
|
||||
} from "./sent-message-cache.js";
|
||||
import { clearSentMessageCache, recordSentMessage, wasSentByBot } from "./sent-message-cache.js";
|
||||
|
||||
describe("sent-message-cache", () => {
|
||||
afterEach(() => {
|
||||
|
||||
@@ -29,10 +29,7 @@ function cleanupExpired(entry: CacheEntry): void {
|
||||
/**
|
||||
* Record a message ID as sent by the bot.
|
||||
*/
|
||||
export function recordSentMessage(
|
||||
chatId: number | string,
|
||||
messageId: number,
|
||||
): void {
|
||||
export function recordSentMessage(chatId: number | string, messageId: number): void {
|
||||
const key = getChatKey(chatId);
|
||||
let entry = sentMessages.get(key);
|
||||
if (!entry) {
|
||||
@@ -50,10 +47,7 @@ export function recordSentMessage(
|
||||
/**
|
||||
* Check if a message was sent by the bot.
|
||||
*/
|
||||
export function wasSentByBot(
|
||||
chatId: number | string,
|
||||
messageId: number,
|
||||
): boolean {
|
||||
export function wasSentByBot(chatId: number | string, messageId: number): boolean {
|
||||
const key = getChatKey(chatId);
|
||||
const entry = sentMessages.get(key);
|
||||
if (!entry) return false;
|
||||
|
||||
@@ -63,10 +63,7 @@ export async function startTelegramWebhook(opts: {
|
||||
|
||||
await bot.api.setWebhook(publicUrl, {
|
||||
secret_token: opts.secret,
|
||||
allowed_updates: [
|
||||
"message",
|
||||
"message_reaction",
|
||||
],
|
||||
allowed_updates: ["message", "message_reaction"],
|
||||
});
|
||||
|
||||
await new Promise<void>((resolve) => server.listen(port, host, resolve));
|
||||
|
||||
Reference in New Issue
Block a user