mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
feat(telegram): add disableAudioPreflight config for groups and topics
This commit is contained in:
committed by
Peter Steinberger
parent
d89c25d69e
commit
d3cb85eaf5
@@ -185,6 +185,8 @@ export type TelegramTopicConfig = {
|
||||
allowFrom?: Array<string | number>;
|
||||
/** Optional system prompt snippet for this topic. */
|
||||
systemPrompt?: string;
|
||||
/** If true, skip automatic voice-note transcription for mention detection in this topic. */
|
||||
disableAudioPreflight?: boolean;
|
||||
};
|
||||
|
||||
export type TelegramGroupConfig = {
|
||||
@@ -204,6 +206,8 @@ export type TelegramGroupConfig = {
|
||||
allowFrom?: Array<string | number>;
|
||||
/** Optional system prompt snippet for this group. */
|
||||
systemPrompt?: string;
|
||||
/** If true, skip automatic voice-note transcription for mention detection in this group. */
|
||||
disableAudioPreflight?: boolean;
|
||||
};
|
||||
|
||||
export type TelegramDirectConfig = {
|
||||
|
||||
@@ -41,4 +41,53 @@ describe("buildTelegramMessageContext audio transcript body", () => {
|
||||
expect(ctx?.ctxPayload?.Body).toContain("hey bot please help");
|
||||
expect(ctx?.ctxPayload?.Body).not.toContain("<media:audio>");
|
||||
});
|
||||
|
||||
it("skips preflight transcription when disableAudioPreflight is true", async () => {
|
||||
transcribeFirstAudioMock.mockClear();
|
||||
|
||||
const ctx = await buildTelegramMessageContext({
|
||||
primaryCtx: {
|
||||
message: {
|
||||
message_id: 2,
|
||||
chat: { id: -1001234567891, type: "supergroup", title: "Test Group 2" },
|
||||
date: 1700000100,
|
||||
from: { id: 43, first_name: "Bob" },
|
||||
voice: { file_id: "voice-2" },
|
||||
},
|
||||
me: { id: 7, username: "bot" },
|
||||
} as never,
|
||||
allMedia: [{ path: "/tmp/voice2.ogg", contentType: "audio/ogg" }],
|
||||
storeAllowFrom: [],
|
||||
options: { forceWasMentioned: true },
|
||||
bot: {
|
||||
api: {
|
||||
sendChatAction: vi.fn(),
|
||||
setMessageReaction: vi.fn(),
|
||||
},
|
||||
} as never,
|
||||
cfg: {
|
||||
agents: { defaults: { model: "anthropic/claude-opus-4-5", workspace: "/tmp/openclaw" } },
|
||||
channels: { telegram: {} },
|
||||
messages: { groupChat: { mentionPatterns: ["\\bbot\\b"] } },
|
||||
} as never,
|
||||
account: { accountId: "default" } as never,
|
||||
historyLimit: 0,
|
||||
groupHistories: new Map(),
|
||||
dmPolicy: "open",
|
||||
allowFrom: [],
|
||||
groupAllowFrom: [],
|
||||
ackReactionScope: "off",
|
||||
logger: { info: vi.fn() },
|
||||
resolveGroupActivation: () => true,
|
||||
resolveGroupRequireMention: () => true,
|
||||
resolveTelegramGroupConfig: () => ({
|
||||
groupConfig: { requireMention: true, disableAudioPreflight: true },
|
||||
topicConfig: undefined,
|
||||
}),
|
||||
});
|
||||
|
||||
expect(ctx).not.toBeNull();
|
||||
expect(transcribeFirstAudioMock).not.toHaveBeenCalled();
|
||||
expect(ctx?.ctxPayload?.Body).toContain("<media:audio>");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -393,11 +393,19 @@ export const buildTelegramMessageContext = async ({
|
||||
let bodyText = rawBody;
|
||||
const hasAudio = allMedia.some((media) => media.contentType?.startsWith("audio/"));
|
||||
|
||||
const disableAudioPreflight =
|
||||
firstDefined(topicConfig?.disableAudioPreflight, groupConfig?.disableAudioPreflight) === true;
|
||||
|
||||
// Preflight audio transcription for mention detection in groups
|
||||
// This allows voice notes to be checked for mentions before being dropped
|
||||
let preflightTranscript: string | undefined;
|
||||
const needsPreflightTranscription =
|
||||
isGroup && requireMention && hasAudio && !hasUserText && mentionRegexes.length > 0;
|
||||
isGroup &&
|
||||
requireMention &&
|
||||
hasAudio &&
|
||||
!hasUserText &&
|
||||
mentionRegexes.length > 0 &&
|
||||
!disableAudioPreflight;
|
||||
|
||||
if (needsPreflightTranscription) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user