diff --git a/extensions/telegram/src/bot/delivery.test.ts b/extensions/telegram/src/bot/delivery.test.ts index 0c49da956ad6..816bdb071425 100644 --- a/extensions/telegram/src/bot/delivery.test.ts +++ b/extensions/telegram/src/bot/delivery.test.ts @@ -1246,11 +1246,11 @@ describe("deliverReplies", () => { chat: { id: "123" }, }); const bot = createBot({ sendMessage }); + const oauthProfileText = + "OAuth profile: openai:keshavbotagent@gmail.com (keshavbotagent@gmail.com)"; await deliverWith({ - replies: [ - { text: "OAuth profile: openai:keshavbotagent@gmail.com (keshavbotagent@gmail.com)" }, - ], + replies: [{ text: oauthProfileText }], runtime, bot, richMessages: true, @@ -1261,7 +1261,7 @@ describe("deliverReplies", () => { }; const richMessage = raw.sendRichMessage.mock.calls[0]?.[0]?.rich_message; expect(richMessage).toEqual({ - html: "OAuth profile: openai:keshavbotagent@gmail.com (keshavbotagent@gmail.com)", + html: oauthProfileText, skip_entity_detection: true, }); }); diff --git a/extensions/telegram/src/draft-stream.test.ts b/extensions/telegram/src/draft-stream.test.ts index ec57b915bbf2..fc1a0b65a950 100644 --- a/extensions/telegram/src/draft-stream.test.ts +++ b/extensions/telegram/src/draft-stream.test.ts @@ -693,14 +693,16 @@ describe("createTelegramDraftStream", () => { it("skips rich entity detection for draft text with provider-prefixed email addresses", async () => { const api = createMockDraftApi(); const stream = createDraftStream(api, { richMessages: true }); + const oauthProfileText = + "OAuth profile: openai:keshavbotagent@gmail.com (keshavbotagent@gmail.com)"; - stream.update("OAuth profile: openai:keshavbotagent@gmail.com (keshavbotagent@gmail.com)"); + stream.update(oauthProfileText); await stream.flush(); expect(api.raw.sendRichMessage).toHaveBeenCalledWith({ chat_id: 123, rich_message: { - html: "OAuth profile: openai:keshavbotagent@gmail.com (keshavbotagent@gmail.com)", + html: oauthProfileText, skip_entity_detection: true, }, }); diff --git a/extensions/telegram/src/rich-message.ts b/extensions/telegram/src/rich-message.ts index 52c650f889c1..40df33249a10 100644 --- a/extensions/telegram/src/rich-message.ts +++ b/extensions/telegram/src/rich-message.ts @@ -174,17 +174,11 @@ export function buildTelegramRichMarkdown( markdown: string, options?: TelegramRichMessageOptions, ): TelegramInputRichMessage { - const skipEntityDetection = shouldSkipTelegramRichEntityDetection(markdown, options); - return buildTelegramRichHtml( - markdownToTelegramRichHtml(markdown, { - ...options, - skipEntityDetection, - }), - { - ...options, - skipEntityDetection, - }, - ); + const richOptions = { + ...options, + skipEntityDetection: shouldSkipTelegramRichEntityDetection(markdown, options), + }; + return buildTelegramRichHtml(markdownToTelegramRichHtml(markdown, richOptions), richOptions); } export function buildTelegramRichHtml( @@ -438,16 +432,14 @@ export function splitTelegramRichMessageTextChunks(params: { tableMode?: MarkdownTableMode; skipEntityDetection?: boolean; }): TelegramRichTextChunk[] { - const skipEntityDetection = shouldSkipTelegramRichEntityDetection(params.text, { - skipEntityDetection: params.skipEntityDetection, - }); + const markdownOptions = { + tableMode: params.tableMode, + skipEntityDetection: shouldSkipTelegramRichEntityDetection(params.text, { + skipEntityDetection: params.skipEntityDetection, + }), + }; const renderMarkdownChunk = (chunk: string) => - prepareTelegramRichHtml( - markdownToTelegramRichHtml(chunk, { - tableMode: params.tableMode, - skipEntityDetection, - }), - ); + prepareTelegramRichHtml(markdownToTelegramRichHtml(chunk, markdownOptions)); const htmlChunks = params.textMode === "html" ? splitPreparedTelegramRichHtml({ diff --git a/extensions/telegram/src/send.test.ts b/extensions/telegram/src/send.test.ts index 1b717f766917..570e0659a07c 100644 --- a/extensions/telegram/src/send.test.ts +++ b/extensions/telegram/src/send.test.ts @@ -958,26 +958,24 @@ describe("sendMessageTelegram", () => { it("skips rich entity detection for provider-prefixed email text", async () => { botApi.sendMessage.mockResolvedValue({ message_id: 45, chat: { id: "123" } }); + const oauthProfileText = + "OAuth profile: openai:keshavbotagent@gmail.com (keshavbotagent@gmail.com)"; - await sendMessageTelegram( - "123", - "OAuth profile: openai:keshavbotagent@gmail.com (keshavbotagent@gmail.com)", - { - cfg: { - channels: { - telegram: { - richMessages: true, - }, + await sendMessageTelegram("123", oauthProfileText, { + cfg: { + channels: { + telegram: { + richMessages: true, }, }, - token: "tok", }, - ); + token: "tok", + }); expect(botRawApi.sendRichMessage).toHaveBeenCalledTimes(1); const richMessage = botRawApi.sendRichMessage.mock.calls[0]?.[0]?.rich_message; expect(richMessage).toEqual({ - html: "OAuth profile: openai:keshavbotagent@gmail.com (keshavbotagent@gmail.com)", + html: oauthProfileText, skip_entity_detection: true, }); expect(richMessage?.html).not.toContain("mailto:");