@ai-devkit/channel-connector 0.13.3 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/ChannelConfigRepository.d.ts +1 -1
- package/dist/ChannelConfigRepository.d.ts.map +1 -1
- package/dist/ChannelConfigRepository.js +13 -13
- package/dist/ChannelConfigRepository.js.map +1 -1
- package/dist/ChannelManager.d.ts +1 -1
- package/dist/ChannelManager.d.ts.map +1 -1
- package/dist/ChannelManager.js +9 -9
- package/dist/ChannelManager.js.map +1 -1
- package/dist/__tests__/ChannelConfigRepository.test.js +72 -72
- package/dist/__tests__/ChannelConfigRepository.test.js.map +1 -1
- package/dist/__tests__/ChannelManager.test.js +26 -26
- package/dist/__tests__/ChannelManager.test.js.map +1 -1
- package/dist/__tests__/adapters/slack/SlackAdapter.test.js +137 -137
- package/dist/__tests__/adapters/slack/SlackAdapter.test.js.map +1 -1
- package/dist/__tests__/adapters/slack/SlackMessageDelivery.test.js +36 -36
- package/dist/__tests__/adapters/slack/SlackMessageDelivery.test.js.map +1 -1
- package/dist/__tests__/adapters/slack/slackMarkdown.test.js +25 -25
- package/dist/__tests__/adapters/slack/slackMarkdown.test.js.map +1 -1
- package/dist/__tests__/adapters/slack/slackQuestion.test.js +41 -41
- package/dist/__tests__/adapters/slack/slackQuestion.test.js.map +1 -1
- package/dist/__tests__/adapters/telegram/TelegramAdapter.test.js +177 -154
- package/dist/__tests__/adapters/telegram/TelegramAdapter.test.js.map +1 -1
- package/dist/__tests__/adapters/telegram/telegramHtml.test.js +109 -109
- package/dist/__tests__/adapters/telegram/telegramHtml.test.js.map +1 -1
- package/dist/adapters/ChannelAdapter.d.ts +1 -1
- package/dist/adapters/ChannelAdapter.d.ts.map +1 -1
- package/dist/adapters/ChannelAdapter.js +1 -1
- package/dist/adapters/ChannelAdapter.js.map +1 -1
- package/dist/adapters/slack/SlackAdapter.d.ts +2 -2
- package/dist/adapters/slack/SlackAdapter.d.ts.map +1 -1
- package/dist/adapters/slack/SlackAdapter.js +17 -17
- package/dist/adapters/slack/SlackAdapter.js.map +1 -1
- package/dist/adapters/slack/SlackMessageDelivery.d.ts +1 -1
- package/dist/adapters/slack/SlackMessageDelivery.d.ts.map +1 -1
- package/dist/adapters/slack/SlackMessageDelivery.js +6 -6
- package/dist/adapters/slack/SlackMessageDelivery.js.map +1 -1
- package/dist/adapters/slack/slackMarkdown.d.ts.map +1 -1
- package/dist/adapters/slack/slackMarkdown.js +36 -36
- package/dist/adapters/slack/slackMarkdown.js.map +1 -1
- package/dist/adapters/slack/slackQuestion.d.ts +7 -7
- package/dist/adapters/slack/slackQuestion.d.ts.map +1 -1
- package/dist/adapters/slack/slackQuestion.js +13 -13
- package/dist/adapters/slack/slackQuestion.js.map +1 -1
- package/dist/adapters/telegram/TelegramAdapter.d.ts +12 -2
- package/dist/adapters/telegram/TelegramAdapter.d.ts.map +1 -1
- package/dist/adapters/telegram/TelegramAdapter.js +38 -27
- package/dist/adapters/telegram/TelegramAdapter.js.map +1 -1
- package/dist/adapters/telegram/TelegramMessageDelivery.d.ts.map +1 -1
- package/dist/adapters/telegram/TelegramMessageDelivery.js +2 -2
- package/dist/adapters/telegram/TelegramMessageDelivery.js.map +1 -1
- package/dist/adapters/telegram/telegramHtml.d.ts.map +1 -1
- package/dist/adapters/telegram/telegramHtml.js +16 -16
- package/dist/adapters/telegram/telegramHtml.js.map +1 -1
- package/dist/adapters/telegram/telegramKeyboard.d.ts +1 -1
- package/dist/adapters/telegram/telegramKeyboard.d.ts.map +1 -1
- package/dist/adapters/telegram/telegramKeyboard.js.map +1 -1
- package/dist/adapters/telegram/telegramMarkdown.d.ts.map +1 -1
- package/dist/adapters/telegram/telegramMarkdown.js +28 -28
- package/dist/adapters/telegram/telegramMarkdown.js.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +6 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +21 -22
- package/vitest.config.ts +16 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/__tests__/adapters/telegram/TelegramAdapter.test.ts"],"sourcesContent":["import * as telegrafModule from 'telegraf';\nimport * as telegramHtml from '../../../adapters/telegram/telegramHtml.js';\nimport { TelegramAdapter } from '../../../adapters/telegram/TelegramAdapter.js';\nimport type { IncomingMessage } from '../../../types.js';\n\n// Mock telegraf\nvi.mock('telegraf', () => {\n const handlers: Record<string, (...args: any[]) => any> = {};\n const mockBot = {\n launch: vi.fn().mockResolvedValue(undefined),\n stop: vi.fn().mockResolvedValue(undefined),\n on: vi.fn((event: string, handler: (...args: any[]) => any) => {\n handlers[event] = handler;\n }),\n telegram: {\n sendMessage: vi.fn().mockResolvedValue(undefined),\n editMessageReplyMarkup: vi.fn().mockResolvedValue(undefined),\n answerCbQuery: vi.fn().mockResolvedValue(undefined),\n getMe: vi.fn().mockResolvedValue({ username: 'test_bot' }),\n },\n _handlers: handlers,\n _triggerText: async (chatId: number, userId: number, text: string) => {\n const ctx = {\n message: {\n chat: { id: chatId },\n from: { id: userId },\n text,\n date: Math.floor(Date.now() / 1000),\n },\n reply: vi.fn().mockResolvedValue(undefined),\n };\n if (handlers['text']) {\n await handlers['text'](ctx);\n }\n return ctx;\n },\n _triggerCallback: async (chatId: number, userId: number, data: string, messageId = 555) => {\n const ctx = {\n callbackQuery: {\n id: 'cbq-test',\n data,\n message: { message_id: messageId, chat: { id: chatId } },\n from: { id: userId },\n },\n answerCbQuery: vi.fn().mockResolvedValue(undefined),\n };\n if (handlers['callback_query']) {\n await handlers['callback_query'](ctx);\n }\n return ctx;\n },\n };\n return {\n Telegraf: vi.fn(function () { return mockBot; }),\n __mockBot: mockBot,\n };\n});\n\nfunction getMockBot() {\n return (telegrafModule as unknown as { __mockBot: ReturnType<typeof vi.fn>['mock'] & Record<string, unknown> }).__mockBot;\n}\n\nfunction expectHtmlChunkWithinLimit(chunk: string): void {\n expect(chunk.length).toBeLessThanOrEqual(4096);\n expect(chunk).not.toMatch(/&(?:l|lt|g|gt|a|am|amp|q|qu|quo|quot)$/);\n expect((chunk.match(/<pre>/g) ?? []).length).toBe((chunk.match(/<\\/pre>/g) ?? []).length);\n expect((chunk.match(/<code(?: class=\"language-[^\"]+\")?>/g) ?? []).length).toBe((chunk.match(/<\\/code>/g) ?? []).length);\n}\n\ndescribe('TelegramAdapter', () => {\n let adapter: TelegramAdapter;\n\n beforeEach(() => {\n vi.clearAllMocks();\n adapter = new TelegramAdapter({ botToken: 'test-token-123' });\n });\n\n describe('type', () => {\n it('should return \"telegram\"', () => {\n expect(adapter.type).toBe('telegram');\n });\n });\n\n describe('start', () => {\n it('should launch the telegraf bot', async () => {\n const bot = getMockBot();\n await adapter.start();\n expect(bot.launch).toHaveBeenCalled();\n });\n });\n\n describe('stop', () => {\n it('should stop the telegraf bot', async () => {\n const bot = getMockBot();\n await adapter.start();\n await adapter.stop();\n expect(bot.stop).toHaveBeenCalled();\n });\n });\n\n describe('onMessage', () => {\n it('should silently ignore messages when no handler is registered', async () => {\n // Don't register a handler\n await adapter.start();\n\n const bot = getMockBot();\n const ctx = await bot._triggerText(12345, 67890, 'hello');\n\n // Should not throw or reply\n expect(ctx.reply).not.toHaveBeenCalled();\n });\n\n it('should handle non-Error thrown by handler', async () => {\n const handler = vi.fn().mockRejectedValue('string error');\n adapter.onMessage(handler);\n await adapter.start();\n\n const bot = getMockBot();\n const ctx = await bot._triggerText(12345, 67890, 'hello');\n\n expect(ctx.reply).toHaveBeenCalledWith(\n 'Error processing message: Unknown error'\n );\n });\n\n it('should call handler with IncomingMessage on incoming text', async () => {\n const handler = vi.fn().mockResolvedValue(undefined);\n adapter.onMessage(handler);\n await adapter.start();\n\n const bot = getMockBot();\n await bot._triggerText(12345, 67890, 'hello agent');\n\n expect(handler).toHaveBeenCalledTimes(1);\n const msg: IncomingMessage = handler.mock.calls[0][0];\n expect(msg.channelType).toBe('telegram');\n expect(msg.chatId).toBe('12345');\n expect(msg.userId).toBe('67890');\n expect(msg.text).toBe('hello agent');\n expect(msg.timestamp).toBeInstanceOf(Date);\n });\n\n it('should handle handler errors gracefully', async () => {\n const handler = vi.fn().mockRejectedValue(new Error('handler failed'));\n adapter.onMessage(handler);\n await adapter.start();\n\n const bot = getMockBot();\n const ctx = await bot._triggerText(12345, 67890, 'hello');\n\n // Should not throw, and should reply with error\n expect(ctx.reply).toHaveBeenCalledWith(\n expect.stringContaining('Error processing message')\n );\n });\n });\n\n describe('sendMessage', () => {\n it('should send plain text with parse_mode HTML', async () => {\n const bot = getMockBot();\n await adapter.sendMessage('12345', 'hello from bot');\n\n expect(bot.telegram.sendMessage).toHaveBeenCalledWith(\n '12345',\n 'hello from bot',\n { parse_mode: 'HTML' }\n );\n });\n\n it('should render markdown as Telegram HTML', async () => {\n const bot = getMockBot();\n await adapter.sendMessage('12345', '**bold** and *italic* and `code`');\n\n const sent = bot.telegram.sendMessage.mock.calls[0][1];\n expect(sent).toContain('<b>bold</b>');\n expect(sent).toContain('<i>italic</i>');\n expect(sent).toContain('<code>code</code>');\n expect(bot.telegram.sendMessage.mock.calls[0][2]).toEqual({\n parse_mode: 'HTML',\n });\n });\n\n it('should chunk messages exceeding 4096 chars', async () => {\n const bot = getMockBot();\n const line = 'A'.repeat(100) + '\\n';\n const longMessage = line.repeat(50); // 5050 chars\n\n await adapter.sendMessage('12345', longMessage);\n\n expect(bot.telegram.sendMessage.mock.calls.length).toBeGreaterThan(1);\n for (const call of bot.telegram.sendMessage.mock.calls) {\n expect(call[1].length).toBeLessThanOrEqual(4096);\n expect(call[2]).toEqual({ parse_mode: 'HTML' });\n }\n });\n\n it('should split long fenced code into independently valid HTML code blocks', async () => {\n const bot = getMockBot();\n const codeLine = 'const sample = \"<code>tag</code>\" && value < limit;\\n';\n const longMessage = `Before\\n\\n\\`\\`\\`ts\\n${codeLine.repeat(100)}\\`\\`\\`\\n\\nAfter`;\n\n await adapter.sendMessage('12345', longMessage);\n\n expect(bot.telegram.sendMessage.mock.calls.length).toBeGreaterThan(1);\n for (const call of bot.telegram.sendMessage.mock.calls) {\n const chunk = call[1];\n expect(call[2]).toEqual({ parse_mode: 'HTML' });\n expectHtmlChunkWithinLimit(chunk);\n if (chunk.includes('<pre>')) {\n expect(chunk).toContain('<code class=\"language-ts\">');\n expect(chunk).toContain('<code>tag</code>');\n }\n }\n });\n\n it('should split nested list fenced code without sending partial HTML tags', async () => {\n const bot = getMockBot();\n const codeLine = ' return \"<code>tag</code>\" && input < output;\\n';\n const longMessage = [\n '- parent item',\n ' - child item with code',\n ' ```js',\n codeLine.repeat(100).trimEnd(),\n ' ```',\n '- final item',\n ].join('\\n');\n\n await adapter.sendMessage('12345', longMessage);\n\n expect(bot.telegram.sendMessage.mock.calls.length).toBeGreaterThan(1);\n for (const call of bot.telegram.sendMessage.mock.calls) {\n const chunk = call[1];\n expect(call[2]).toEqual({ parse_mode: 'HTML' });\n expectHtmlChunkWithinLimit(chunk);\n }\n });\n\n it('should split long paragraphs at readable markdown boundaries', async () => {\n const bot = getMockBot();\n const sentence = 'This is a long sentence with enough words to make chunking choose sentence boundaries. ';\n const longMessage = sentence.repeat(80);\n\n await adapter.sendMessage('12345', longMessage);\n\n expect(bot.telegram.sendMessage.mock.calls.length).toBeGreaterThan(1);\n for (const call of bot.telegram.sendMessage.mock.calls) {\n const chunk = call[1];\n expect(call[2]).toEqual({ parse_mode: 'HTML' });\n expectHtmlChunkWithinLimit(chunk);\n expect(chunk.endsWith('.') || chunk.endsWith('.\\n\\n') || chunk.endsWith(' ')).toBe(true);\n }\n });\n\n it('should keep emoji chunks within the configured JavaScript string length limit', async () => {\n const bot = getMockBot();\n const longMessage = `Status ${'🧪'.repeat(2500)}`;\n\n await adapter.sendMessage('12345', longMessage);\n\n expect(bot.telegram.sendMessage.mock.calls.length).toBeGreaterThan(1);\n for (const call of bot.telegram.sendMessage.mock.calls) {\n expect(call[1].length).toBeLessThanOrEqual(4096);\n expect(call[2]).toEqual({ parse_mode: 'HTML' });\n }\n });\n\n it('should hard split at 4096 when no newlines available', async () => {\n const bot = getMockBot();\n const longMessage = 'A'.repeat(5000);\n\n await adapter.sendMessage('12345', longMessage);\n\n expect(bot.telegram.sendMessage.mock.calls.length).toBe(2);\n expect(bot.telegram.sendMessage.mock.calls[0][1].length).toBe(4096);\n expect(bot.telegram.sendMessage.mock.calls[1][1].length).toBe(904);\n });\n\n it('should prefer paragraph (\\\\n\\\\n) over single \\\\n when chunking', async () => {\n const bot = getMockBot();\n // 4 paragraphs of ~1500 chars each, total > 4096\n const paragraph = 'A'.repeat(1500);\n const message = `${paragraph}\\n\\n${paragraph}\\n\\n${paragraph}\\n\\n${paragraph}`;\n\n await adapter.sendMessage('12345', message);\n\n // First chunk should end at a \\n\\n boundary, not mid-paragraph\n const firstChunk = bot.telegram.sendMessage.mock.calls[0][1];\n expect(firstChunk).toBe(`${paragraph}\\n\\n${paragraph}`);\n });\n\n it('should send short messages in a single call', async () => {\n const bot = getMockBot();\n await adapter.sendMessage('12345', 'short message');\n\n expect(bot.telegram.sendMessage).toHaveBeenCalledTimes(1);\n });\n\n it('should retry as plain text when Telegram rejects HTML with parse-entities error', async () => {\n const bot = getMockBot();\n const parseError = Object.assign(new Error('400: Bad Request'), {\n description: \"Bad Request: can't parse entities: Unsupported start tag \\\"foo\\\"\",\n });\n bot.telegram.sendMessage\n .mockRejectedValueOnce(parseError)\n .mockResolvedValueOnce(undefined);\n\n await adapter.sendMessage('12345', '**hello**');\n\n expect(bot.telegram.sendMessage).toHaveBeenCalledTimes(2);\n\n // First call: rendered HTML with parse_mode\n const [, htmlChunk, htmlOpts] = bot.telegram.sendMessage.mock.calls[0];\n expect(htmlChunk).toContain('<b>hello</b>');\n expect(htmlOpts).toEqual({ parse_mode: 'HTML' });\n\n // Second call: same content, plain text (tags stripped, no parse_mode)\n const [, plainChunk, plainOpts] = bot.telegram.sendMessage.mock.calls[1];\n expect(plainChunk).toBe('hello');\n expect(plainOpts).toBeUndefined();\n });\n\n it('should detect parse-entities error from \"message\" field too', async () => {\n const bot = getMockBot();\n // Some error shapes carry the marker on `message` rather than `description`\n const parseError = new Error(\"can't parse entities\");\n bot.telegram.sendMessage\n .mockRejectedValueOnce(parseError)\n .mockResolvedValueOnce(undefined);\n\n await adapter.sendMessage('12345', '**hi**');\n\n expect(bot.telegram.sendMessage).toHaveBeenCalledTimes(2);\n });\n\n it('should decode HTML entities when falling back to plain text', async () => {\n const bot = getMockBot();\n const parseError = Object.assign(new Error('400'), {\n description: \"Bad Request: can't parse entities\",\n });\n bot.telegram.sendMessage\n .mockRejectedValueOnce(parseError)\n .mockResolvedValueOnce(undefined);\n\n // Source has chars that escapeHtml encodes; fallback should decode them\n await adapter.sendMessage('12345', 'a < b && c > d');\n\n const [, plainChunk] = bot.telegram.sendMessage.mock.calls[1];\n expect(plainChunk).toContain('a < b && c > d');\n expect(plainChunk).not.toContain('<');\n expect(plainChunk).not.toContain('&');\n });\n\n it('should deliver nested lists without throwing', async () => {\n const bot = getMockBot();\n\n await adapter.sendMessage('12345', '- agent\\n - Status');\n\n expect(bot.telegram.sendMessage).toHaveBeenCalledTimes(1);\n expect(bot.telegram.sendMessage.mock.calls[0][1]).toContain('Status');\n });\n\n it('should send plain text when markdown formatting throws', async () => {\n const bot = getMockBot();\n const formatter = vi.spyOn(telegramHtml, 'markdownToTelegramHtml')\n .mockImplementationOnce(() => {\n throw new Error('formatter failed');\n });\n\n await adapter.sendMessage('12345', '- agent\\n - Status');\n\n expect(bot.telegram.sendMessage).toHaveBeenCalledTimes(1);\n expect(bot.telegram.sendMessage.mock.calls[0][0]).toBe('12345');\n expect(bot.telegram.sendMessage.mock.calls[0][1]).toBe('- agent\\n - Status');\n expect(bot.telegram.sendMessage.mock.calls[0][2]).toBeUndefined();\n\n formatter.mockRestore();\n });\n\n it('should propagate non-parse-entities errors without falling back', async () => {\n const bot = getMockBot();\n const otherError = Object.assign(new Error('403'), {\n description: 'Forbidden: bot was blocked by the user',\n });\n bot.telegram.sendMessage.mockRejectedValueOnce(otherError);\n\n await expect(adapter.sendMessage('12345', 'hi')).rejects.toBe(otherError);\n\n // Only the HTML attempt should have happened — no fallback retry\n expect(bot.telegram.sendMessage).toHaveBeenCalledTimes(1);\n });\n });\n\n describe('sendInlineKeyboard', () => {\n it('sends with parse_mode HTML and inline_keyboard payload, returns message_id', async () => {\n const bot = getMockBot();\n (bot.telegram.sendMessage as any).mockResolvedValueOnce({ message_id: 42 });\n\n const id = await adapter.sendInlineKeyboard('12345', '<b>hi</b>', [\n [{ text: 'A', callbackData: 'q:1:o:0' }],\n [{ text: 'B', callbackData: 'q:1:o:1' }],\n ]);\n\n expect(id).toBe(42);\n expect(bot.telegram.sendMessage).toHaveBeenCalledWith('12345', '<b>hi</b>', {\n parse_mode: 'HTML',\n reply_markup: {\n inline_keyboard: [\n [{ text: 'A', callback_data: 'q:1:o:0' }],\n [{ text: 'B', callback_data: 'q:1:o:1' }],\n ],\n },\n });\n });\n });\n\n describe('editInlineKeyboard', () => {\n it('replaces the keyboard on an existing message', async () => {\n const bot = getMockBot();\n await adapter.editInlineKeyboard('12345', 99, [[{ text: '✓ A', callbackData: 'q:1:o:0' }]]);\n expect(bot.telegram.editMessageReplyMarkup).toHaveBeenCalledWith('12345', 99, undefined, {\n inline_keyboard: [[{ text: '✓ A', callback_data: 'q:1:o:0' }]],\n });\n });\n\n it('passes undefined reply_markup to remove the keyboard', async () => {\n const bot = getMockBot();\n await adapter.editInlineKeyboard('12345', 99, null);\n expect(bot.telegram.editMessageReplyMarkup).toHaveBeenCalledWith('12345', 99, undefined, undefined);\n });\n });\n\n describe('answerCallback', () => {\n it('forwards id and optional text to telegraf', async () => {\n const bot = getMockBot();\n await adapter.answerCallback('cbq-1', 'thanks');\n expect(bot.telegram.answerCbQuery).toHaveBeenCalledWith('cbq-1', 'thanks');\n });\n });\n\n describe('onCallback', () => {\n it('invokes the registered handler with a normalized IncomingCallback', async () => {\n const handler = vi.fn().mockResolvedValue(undefined);\n adapter.onCallback(handler);\n await adapter.start();\n\n const bot = getMockBot();\n await (bot as any)._triggerCallback(12345, 67890, 'q:abc:o:1', 777);\n\n expect(handler).toHaveBeenCalledOnce();\n const cb = handler.mock.calls[0][0];\n expect(cb.channelType).toBe('telegram');\n expect(cb.chatId).toBe('12345');\n expect(cb.userId).toBe('67890');\n expect(cb.messageId).toBe(777);\n expect(cb.callbackData).toBe('q:abc:o:1');\n expect(cb.callbackQueryId).toBe('cbq-test');\n });\n\n it('answers callbacks when no handler is registered', async () => {\n await adapter.start();\n const bot = getMockBot();\n const ctx = await (bot as any)._triggerCallback(12345, 67890, 'q:x:o:0');\n expect(ctx.answerCbQuery).toHaveBeenCalled();\n });\n\n it('answers with error when handler rejects', async () => {\n adapter.onCallback(vi.fn().mockRejectedValue(new Error('boom')));\n await adapter.start();\n const bot = getMockBot();\n const ctx = await (bot as any)._triggerCallback(12345, 67890, 'q:x:o:0');\n expect(ctx.answerCbQuery).toHaveBeenCalledWith('Error');\n });\n });\n\n describe('isHealthy', () => {\n it('should return true after start', async () => {\n await adapter.start();\n expect(await adapter.isHealthy()).toBe(true);\n });\n\n it('should return false before start', async () => {\n expect(await adapter.isHealthy()).toBe(false);\n });\n\n it('should return false after stop', async () => {\n await adapter.start();\n await adapter.stop();\n expect(await adapter.isHealthy()).toBe(false);\n });\n });\n});\n"],"names":["telegrafModule","telegramHtml","TelegramAdapter","vi","mock","handlers","mockBot","launch","fn","mockResolvedValue","undefined","stop","on","event","handler","telegram","sendMessage","editMessageReplyMarkup","answerCbQuery","getMe","username","_handlers","_triggerText","chatId","userId","text","ctx","message","chat","id","from","date","Math","floor","Date","now","reply","_triggerCallback","data","messageId","callbackQuery","message_id","Telegraf","__mockBot","getMockBot","expectHtmlChunkWithinLimit","chunk","expect","length","toBeLessThanOrEqual","not","toMatch","match","toBe","describe","adapter","beforeEach","clearAllMocks","botToken","it","type","bot","start","toHaveBeenCalled","mockRejectedValue","onMessage","toHaveBeenCalledWith","toHaveBeenCalledTimes","msg","calls","channelType","timestamp","toBeInstanceOf","Error","stringContaining","parse_mode","sent","toContain","toEqual","line","repeat","longMessage","toBeGreaterThan","call","codeLine","includes","trimEnd","join","sentence","endsWith","paragraph","firstChunk","parseError","Object","assign","description","mockRejectedValueOnce","mockResolvedValueOnce","htmlChunk","htmlOpts","plainChunk","plainOpts","toBeUndefined","formatter","spyOn","mockImplementationOnce","mockRestore","otherError","rejects","sendInlineKeyboard","callbackData","reply_markup","inline_keyboard","callback_data","editInlineKeyboard","answerCallback","onCallback","toHaveBeenCalledOnce","cb","callbackQueryId","isHealthy"],"mappings":"AAAA,YAAYA,oBAAoB,WAAW;AAC3C,YAAYC,kBAAkB,6CAA6C;AAC3E,SAASC,eAAe,QAAQ,gDAAgD;AAGhF,gBAAgB;AAChBC,GAAGC,IAAI,CAAC,YAAY;IAChB,MAAMC,WAAoD,CAAC;IAC3D,MAAMC,UAAU;QACZC,QAAQJ,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;QAClCC,MAAMR,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;QAChCE,IAAIT,GAAGK,EAAE,CAAC,CAACK,OAAeC;YACtBT,QAAQ,CAACQ,MAAM,GAAGC;QACtB;QACAC,UAAU;YACNC,aAAab,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;YACvCO,wBAAwBd,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;YAClDQ,eAAef,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;YACzCS,OAAOhB,GAAGK,EAAE,GAAGC,iBAAiB,CAAC;gBAAEW,UAAU;YAAW;QAC5D;QACAC,WAAWhB;QACXiB,cAAc,OAAOC,QAAgBC,QAAgBC;YACjD,MAAMC,MAAM;gBACRC,SAAS;oBACLC,MAAM;wBAAEC,IAAIN;oBAAO;oBACnBO,MAAM;wBAAED,IAAIL;oBAAO;oBACnB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"version":3,"sources":["../../../../src/__tests__/adapters/telegram/TelegramAdapter.test.ts"],"sourcesContent":["import * as telegrafModule from \"telegraf\";\nimport * as telegramHtml from \"../../../adapters/telegram/telegramHtml.js\";\nimport {\n TelegramAdapter,\n validateTelegramBotToken,\n} from \"../../../adapters/telegram/TelegramAdapter.js\";\nimport type { IncomingMessage } from \"../../../types.js\";\n\n// Mock telegraf\nvi.mock(\"telegraf\", () => {\n const handlers: Record<string, (...args: any[]) => any> = {};\n const mockBot = {\n launch: vi.fn().mockResolvedValue(undefined),\n stop: vi.fn().mockResolvedValue(undefined),\n on: vi.fn((event: string, handler: (...args: any[]) => any) => {\n handlers[event] = handler;\n }),\n telegram: {\n sendMessage: vi.fn().mockResolvedValue(undefined),\n editMessageReplyMarkup: vi.fn().mockResolvedValue(undefined),\n answerCbQuery: vi.fn().mockResolvedValue(undefined),\n getMe: vi.fn().mockResolvedValue({ username: \"test_bot\" }),\n },\n _handlers: handlers,\n _triggerText: async (chatId: number, userId: number, text: string) => {\n const ctx = {\n message: {\n chat: { id: chatId },\n from: { id: userId },\n text,\n date: Math.floor(Date.now() / 1000),\n },\n reply: vi.fn().mockResolvedValue(undefined),\n };\n if (handlers[\"text\"]) {\n await handlers[\"text\"](ctx);\n }\n return ctx;\n },\n _triggerCallback: async (chatId: number, userId: number, data: string, messageId = 555) => {\n const ctx = {\n callbackQuery: {\n id: \"cbq-test\",\n data,\n message: { message_id: messageId, chat: { id: chatId } },\n from: { id: userId },\n },\n answerCbQuery: vi.fn().mockResolvedValue(undefined),\n };\n if (handlers[\"callback_query\"]) {\n await handlers[\"callback_query\"](ctx);\n }\n return ctx;\n },\n };\n return {\n Telegraf: vi.fn(function () {\n return mockBot;\n }),\n __mockBot: mockBot,\n };\n});\n\nfunction getMockBot() {\n return (\n telegrafModule as unknown as {\n __mockBot: ReturnType<typeof vi.fn>[\"mock\"] & Record<string, unknown>;\n }\n ).__mockBot;\n}\n\nfunction expectHtmlChunkWithinLimit(chunk: string): void {\n expect(chunk.length).toBeLessThanOrEqual(4096);\n expect(chunk).not.toMatch(/&(?:l|lt|g|gt|a|am|amp|q|qu|quo|quot)$/);\n expect((chunk.match(/<pre>/g) ?? []).length).toBe((chunk.match(/<\\/pre>/g) ?? []).length);\n expect((chunk.match(/<code(?: class=\"language-[^\"]+\")?>/g) ?? []).length).toBe(\n (chunk.match(/<\\/code>/g) ?? []).length,\n );\n}\n\ndescribe(\"TelegramAdapter\", () => {\n it(\"returns the bot username for a valid token\", async () => {\n const getMe = vi.fn().mockResolvedValue({ username: \"test_bot\" });\n await expect(validateTelegramBotToken(\"123:abc\", { getMe })).resolves.toEqual({\n username: \"test_bot\",\n });\n expect(getMe).toHaveBeenCalledOnce();\n });\n\n it(\"rejects when the API reports no username\", async () => {\n const getMe = vi.fn().mockResolvedValue({});\n await expect(validateTelegramBotToken(\"123:abc\", { getMe })).rejects.toThrow(\n \"Telegram bot token returned no username\",\n );\n });\n\n it(\"propagates API errors such as 401 Unauthorized\", async () => {\n const getMe = vi.fn().mockRejectedValue(new Error(\"401: Unauthorized\"));\n await expect(validateTelegramBotToken(\"123:abc\", { getMe })).rejects.toThrow(\n \"401: Unauthorized\",\n );\n });\n\n let adapter: TelegramAdapter;\n\n beforeEach(() => {\n vi.clearAllMocks();\n adapter = new TelegramAdapter({ botToken: \"test-token-123\" });\n });\n\n describe(\"type\", () => {\n it('should return \"telegram\"', () => {\n expect(adapter.type).toBe(\"telegram\");\n });\n });\n\n describe(\"start\", () => {\n it(\"should launch the telegraf bot\", async () => {\n const bot = getMockBot();\n await adapter.start();\n expect(bot.launch).toHaveBeenCalled();\n });\n });\n\n describe(\"stop\", () => {\n it(\"should stop the telegraf bot\", async () => {\n const bot = getMockBot();\n await adapter.start();\n await adapter.stop();\n expect(bot.stop).toHaveBeenCalled();\n });\n });\n\n describe(\"onMessage\", () => {\n it(\"should silently ignore messages when no handler is registered\", async () => {\n // Don't register a handler\n await adapter.start();\n\n const bot = getMockBot();\n const ctx = await bot._triggerText(12345, 67890, \"hello\");\n\n // Should not throw or reply\n expect(ctx.reply).not.toHaveBeenCalled();\n });\n\n it(\"should handle non-Error thrown by handler\", async () => {\n const handler = vi.fn().mockRejectedValue(\"string error\");\n adapter.onMessage(handler);\n await adapter.start();\n\n const bot = getMockBot();\n const ctx = await bot._triggerText(12345, 67890, \"hello\");\n\n expect(ctx.reply).toHaveBeenCalledWith(\"Error processing message: Unknown error\");\n });\n\n it(\"should call handler with IncomingMessage on incoming text\", async () => {\n const handler = vi.fn().mockResolvedValue(undefined);\n adapter.onMessage(handler);\n await adapter.start();\n\n const bot = getMockBot();\n await bot._triggerText(12345, 67890, \"hello agent\");\n\n expect(handler).toHaveBeenCalledTimes(1);\n const msg: IncomingMessage = handler.mock.calls[0][0];\n expect(msg.channelType).toBe(\"telegram\");\n expect(msg.chatId).toBe(\"12345\");\n expect(msg.userId).toBe(\"67890\");\n expect(msg.text).toBe(\"hello agent\");\n expect(msg.timestamp).toBeInstanceOf(Date);\n });\n\n it(\"should handle handler errors gracefully\", async () => {\n const handler = vi.fn().mockRejectedValue(new Error(\"handler failed\"));\n adapter.onMessage(handler);\n await adapter.start();\n\n const bot = getMockBot();\n const ctx = await bot._triggerText(12345, 67890, \"hello\");\n\n // Should not throw, and should reply with error\n expect(ctx.reply).toHaveBeenCalledWith(expect.stringContaining(\"Error processing message\"));\n });\n });\n\n describe(\"sendMessage\", () => {\n it(\"should send plain text with parse_mode HTML\", async () => {\n const bot = getMockBot();\n await adapter.sendMessage(\"12345\", \"hello from bot\");\n\n expect(bot.telegram.sendMessage).toHaveBeenCalledWith(\"12345\", \"hello from bot\", {\n parse_mode: \"HTML\",\n });\n });\n\n it(\"should render markdown as Telegram HTML\", async () => {\n const bot = getMockBot();\n await adapter.sendMessage(\"12345\", \"**bold** and *italic* and `code`\");\n\n const sent = bot.telegram.sendMessage.mock.calls[0][1];\n expect(sent).toContain(\"<b>bold</b>\");\n expect(sent).toContain(\"<i>italic</i>\");\n expect(sent).toContain(\"<code>code</code>\");\n expect(bot.telegram.sendMessage.mock.calls[0][2]).toEqual({\n parse_mode: \"HTML\",\n });\n });\n\n it(\"should chunk messages exceeding 4096 chars\", async () => {\n const bot = getMockBot();\n const line = \"A\".repeat(100) + \"\\n\";\n const longMessage = line.repeat(50); // 5050 chars\n\n await adapter.sendMessage(\"12345\", longMessage);\n\n expect(bot.telegram.sendMessage.mock.calls.length).toBeGreaterThan(1);\n for (const call of bot.telegram.sendMessage.mock.calls) {\n expect(call[1].length).toBeLessThanOrEqual(4096);\n expect(call[2]).toEqual({ parse_mode: \"HTML\" });\n }\n });\n\n it(\"should split long fenced code into independently valid HTML code blocks\", async () => {\n const bot = getMockBot();\n const codeLine = 'const sample = \"<code>tag</code>\" && value < limit;\\n';\n const longMessage = `Before\\n\\n\\`\\`\\`ts\\n${codeLine.repeat(100)}\\`\\`\\`\\n\\nAfter`;\n\n await adapter.sendMessage(\"12345\", longMessage);\n\n expect(bot.telegram.sendMessage.mock.calls.length).toBeGreaterThan(1);\n for (const call of bot.telegram.sendMessage.mock.calls) {\n const chunk = call[1];\n expect(call[2]).toEqual({ parse_mode: \"HTML\" });\n expectHtmlChunkWithinLimit(chunk);\n if (chunk.includes(\"<pre>\")) {\n expect(chunk).toContain('<code class=\"language-ts\">');\n expect(chunk).toContain(\"<code>tag</code>\");\n }\n }\n });\n\n it(\"should split nested list fenced code without sending partial HTML tags\", async () => {\n const bot = getMockBot();\n const codeLine = ' return \"<code>tag</code>\" && input < output;\\n';\n const longMessage = [\n \"- parent item\",\n \" - child item with code\",\n \" ```js\",\n codeLine.repeat(100).trimEnd(),\n \" ```\",\n \"- final item\",\n ].join(\"\\n\");\n\n await adapter.sendMessage(\"12345\", longMessage);\n\n expect(bot.telegram.sendMessage.mock.calls.length).toBeGreaterThan(1);\n for (const call of bot.telegram.sendMessage.mock.calls) {\n const chunk = call[1];\n expect(call[2]).toEqual({ parse_mode: \"HTML\" });\n expectHtmlChunkWithinLimit(chunk);\n }\n });\n\n it(\"should split long paragraphs at readable markdown boundaries\", async () => {\n const bot = getMockBot();\n const sentence =\n \"This is a long sentence with enough words to make chunking choose sentence boundaries. \";\n const longMessage = sentence.repeat(80);\n\n await adapter.sendMessage(\"12345\", longMessage);\n\n expect(bot.telegram.sendMessage.mock.calls.length).toBeGreaterThan(1);\n for (const call of bot.telegram.sendMessage.mock.calls) {\n const chunk = call[1];\n expect(call[2]).toEqual({ parse_mode: \"HTML\" });\n expectHtmlChunkWithinLimit(chunk);\n expect(chunk.endsWith(\".\") || chunk.endsWith(\".\\n\\n\") || chunk.endsWith(\" \")).toBe(true);\n }\n });\n\n it(\"should keep emoji chunks within the configured JavaScript string length limit\", async () => {\n const bot = getMockBot();\n const longMessage = `Status ${\"🧪\".repeat(2500)}`;\n\n await adapter.sendMessage(\"12345\", longMessage);\n\n expect(bot.telegram.sendMessage.mock.calls.length).toBeGreaterThan(1);\n for (const call of bot.telegram.sendMessage.mock.calls) {\n expect(call[1].length).toBeLessThanOrEqual(4096);\n expect(call[2]).toEqual({ parse_mode: \"HTML\" });\n }\n });\n\n it(\"should hard split at 4096 when no newlines available\", async () => {\n const bot = getMockBot();\n const longMessage = \"A\".repeat(5000);\n\n await adapter.sendMessage(\"12345\", longMessage);\n\n expect(bot.telegram.sendMessage.mock.calls.length).toBe(2);\n expect(bot.telegram.sendMessage.mock.calls[0][1].length).toBe(4096);\n expect(bot.telegram.sendMessage.mock.calls[1][1].length).toBe(904);\n });\n\n it(\"should prefer paragraph (\\\\n\\\\n) over single \\\\n when chunking\", async () => {\n const bot = getMockBot();\n // 4 paragraphs of ~1500 chars each, total > 4096\n const paragraph = \"A\".repeat(1500);\n const message = `${paragraph}\\n\\n${paragraph}\\n\\n${paragraph}\\n\\n${paragraph}`;\n\n await adapter.sendMessage(\"12345\", message);\n\n // First chunk should end at a \\n\\n boundary, not mid-paragraph\n const firstChunk = bot.telegram.sendMessage.mock.calls[0][1];\n expect(firstChunk).toBe(`${paragraph}\\n\\n${paragraph}`);\n });\n\n it(\"should send short messages in a single call\", async () => {\n const bot = getMockBot();\n await adapter.sendMessage(\"12345\", \"short message\");\n\n expect(bot.telegram.sendMessage).toHaveBeenCalledTimes(1);\n });\n\n it(\"should retry as plain text when Telegram rejects HTML with parse-entities error\", async () => {\n const bot = getMockBot();\n const parseError = Object.assign(new Error(\"400: Bad Request\"), {\n description: 'Bad Request: can\\'t parse entities: Unsupported start tag \"foo\"',\n });\n bot.telegram.sendMessage.mockRejectedValueOnce(parseError).mockResolvedValueOnce(undefined);\n\n await adapter.sendMessage(\"12345\", \"**hello**\");\n\n expect(bot.telegram.sendMessage).toHaveBeenCalledTimes(2);\n\n // First call: rendered HTML with parse_mode\n const [, htmlChunk, htmlOpts] = bot.telegram.sendMessage.mock.calls[0];\n expect(htmlChunk).toContain(\"<b>hello</b>\");\n expect(htmlOpts).toEqual({ parse_mode: \"HTML\" });\n\n // Second call: same content, plain text (tags stripped, no parse_mode)\n const [, plainChunk, plainOpts] = bot.telegram.sendMessage.mock.calls[1];\n expect(plainChunk).toBe(\"hello\");\n expect(plainOpts).toBeUndefined();\n });\n\n it('should detect parse-entities error from \"message\" field too', async () => {\n const bot = getMockBot();\n // Some error shapes carry the marker on `message` rather than `description`\n const parseError = new Error(\"can't parse entities\");\n bot.telegram.sendMessage.mockRejectedValueOnce(parseError).mockResolvedValueOnce(undefined);\n\n await adapter.sendMessage(\"12345\", \"**hi**\");\n\n expect(bot.telegram.sendMessage).toHaveBeenCalledTimes(2);\n });\n\n it(\"should decode HTML entities when falling back to plain text\", async () => {\n const bot = getMockBot();\n const parseError = Object.assign(new Error(\"400\"), {\n description: \"Bad Request: can't parse entities\",\n });\n bot.telegram.sendMessage.mockRejectedValueOnce(parseError).mockResolvedValueOnce(undefined);\n\n // Source has chars that escapeHtml encodes; fallback should decode them\n await adapter.sendMessage(\"12345\", \"a < b && c > d\");\n\n const [, plainChunk] = bot.telegram.sendMessage.mock.calls[1];\n expect(plainChunk).toContain(\"a < b && c > d\");\n expect(plainChunk).not.toContain(\"<\");\n expect(plainChunk).not.toContain(\"&\");\n });\n\n it(\"should deliver nested lists without throwing\", async () => {\n const bot = getMockBot();\n\n await adapter.sendMessage(\"12345\", \"- agent\\n - Status\");\n\n expect(bot.telegram.sendMessage).toHaveBeenCalledTimes(1);\n expect(bot.telegram.sendMessage.mock.calls[0][1]).toContain(\"Status\");\n });\n\n it(\"should send plain text when markdown formatting throws\", async () => {\n const bot = getMockBot();\n const formatter = vi\n .spyOn(telegramHtml, \"markdownToTelegramHtml\")\n .mockImplementationOnce(() => {\n throw new Error(\"formatter failed\");\n });\n\n await adapter.sendMessage(\"12345\", \"- agent\\n - Status\");\n\n expect(bot.telegram.sendMessage).toHaveBeenCalledTimes(1);\n expect(bot.telegram.sendMessage.mock.calls[0][0]).toBe(\"12345\");\n expect(bot.telegram.sendMessage.mock.calls[0][1]).toBe(\"- agent\\n - Status\");\n expect(bot.telegram.sendMessage.mock.calls[0][2]).toBeUndefined();\n\n formatter.mockRestore();\n });\n\n it(\"should propagate non-parse-entities errors without falling back\", async () => {\n const bot = getMockBot();\n const otherError = Object.assign(new Error(\"403\"), {\n description: \"Forbidden: bot was blocked by the user\",\n });\n bot.telegram.sendMessage.mockRejectedValueOnce(otherError);\n\n await expect(adapter.sendMessage(\"12345\", \"hi\")).rejects.toBe(otherError);\n\n // Only the HTML attempt should have happened — no fallback retry\n expect(bot.telegram.sendMessage).toHaveBeenCalledTimes(1);\n });\n });\n\n describe(\"sendInlineKeyboard\", () => {\n it(\"sends with parse_mode HTML and inline_keyboard payload, returns message_id\", async () => {\n const bot = getMockBot();\n (bot.telegram.sendMessage as any).mockResolvedValueOnce({ message_id: 42 });\n\n const id = await adapter.sendInlineKeyboard(\"12345\", \"<b>hi</b>\", [\n [{ text: \"A\", callbackData: \"q:1:o:0\" }],\n [{ text: \"B\", callbackData: \"q:1:o:1\" }],\n ]);\n\n expect(id).toBe(42);\n expect(bot.telegram.sendMessage).toHaveBeenCalledWith(\"12345\", \"<b>hi</b>\", {\n parse_mode: \"HTML\",\n reply_markup: {\n inline_keyboard: [\n [{ text: \"A\", callback_data: \"q:1:o:0\" }],\n [{ text: \"B\", callback_data: \"q:1:o:1\" }],\n ],\n },\n });\n });\n });\n\n describe(\"editInlineKeyboard\", () => {\n it(\"replaces the keyboard on an existing message\", async () => {\n const bot = getMockBot();\n await adapter.editInlineKeyboard(\"12345\", 99, [[{ text: \"✓ A\", callbackData: \"q:1:o:0\" }]]);\n expect(bot.telegram.editMessageReplyMarkup).toHaveBeenCalledWith(\"12345\", 99, undefined, {\n inline_keyboard: [[{ text: \"✓ A\", callback_data: \"q:1:o:0\" }]],\n });\n });\n\n it(\"passes undefined reply_markup to remove the keyboard\", async () => {\n const bot = getMockBot();\n await adapter.editInlineKeyboard(\"12345\", 99, null);\n expect(bot.telegram.editMessageReplyMarkup).toHaveBeenCalledWith(\n \"12345\",\n 99,\n undefined,\n undefined,\n );\n });\n });\n\n describe(\"answerCallback\", () => {\n it(\"forwards id and optional text to telegraf\", async () => {\n const bot = getMockBot();\n await adapter.answerCallback(\"cbq-1\", \"thanks\");\n expect(bot.telegram.answerCbQuery).toHaveBeenCalledWith(\"cbq-1\", \"thanks\");\n });\n });\n\n describe(\"onCallback\", () => {\n it(\"invokes the registered handler with a normalized IncomingCallback\", async () => {\n const handler = vi.fn().mockResolvedValue(undefined);\n adapter.onCallback(handler);\n await adapter.start();\n\n const bot = getMockBot();\n await (bot as any)._triggerCallback(12345, 67890, \"q:abc:o:1\", 777);\n\n expect(handler).toHaveBeenCalledOnce();\n const cb = handler.mock.calls[0][0];\n expect(cb.channelType).toBe(\"telegram\");\n expect(cb.chatId).toBe(\"12345\");\n expect(cb.userId).toBe(\"67890\");\n expect(cb.messageId).toBe(777);\n expect(cb.callbackData).toBe(\"q:abc:o:1\");\n expect(cb.callbackQueryId).toBe(\"cbq-test\");\n });\n\n it(\"answers callbacks when no handler is registered\", async () => {\n await adapter.start();\n const bot = getMockBot();\n const ctx = await (bot as any)._triggerCallback(12345, 67890, \"q:x:o:0\");\n expect(ctx.answerCbQuery).toHaveBeenCalled();\n });\n\n it(\"answers with error when handler rejects\", async () => {\n adapter.onCallback(vi.fn().mockRejectedValue(new Error(\"boom\")));\n await adapter.start();\n const bot = getMockBot();\n const ctx = await (bot as any)._triggerCallback(12345, 67890, \"q:x:o:0\");\n expect(ctx.answerCbQuery).toHaveBeenCalledWith(\"Error\");\n });\n });\n\n describe(\"isHealthy\", () => {\n it(\"should return true after start\", async () => {\n await adapter.start();\n expect(await adapter.isHealthy()).toBe(true);\n });\n\n it(\"should return false before start\", async () => {\n expect(await adapter.isHealthy()).toBe(false);\n });\n\n it(\"should return false after stop\", async () => {\n await adapter.start();\n await adapter.stop();\n expect(await adapter.isHealthy()).toBe(false);\n });\n });\n});\n"],"names":["telegrafModule","telegramHtml","TelegramAdapter","validateTelegramBotToken","vi","mock","handlers","mockBot","launch","fn","mockResolvedValue","undefined","stop","on","event","handler","telegram","sendMessage","editMessageReplyMarkup","answerCbQuery","getMe","username","_handlers","_triggerText","chatId","userId","text","ctx","message","chat","id","from","date","Math","floor","Date","now","reply","_triggerCallback","data","messageId","callbackQuery","message_id","Telegraf","__mockBot","getMockBot","expectHtmlChunkWithinLimit","chunk","expect","length","toBeLessThanOrEqual","not","toMatch","match","toBe","describe","it","resolves","toEqual","toHaveBeenCalledOnce","rejects","toThrow","mockRejectedValue","Error","adapter","beforeEach","clearAllMocks","botToken","type","bot","start","toHaveBeenCalled","onMessage","toHaveBeenCalledWith","toHaveBeenCalledTimes","msg","calls","channelType","timestamp","toBeInstanceOf","stringContaining","parse_mode","sent","toContain","line","repeat","longMessage","toBeGreaterThan","call","codeLine","includes","trimEnd","join","sentence","endsWith","paragraph","firstChunk","parseError","Object","assign","description","mockRejectedValueOnce","mockResolvedValueOnce","htmlChunk","htmlOpts","plainChunk","plainOpts","toBeUndefined","formatter","spyOn","mockImplementationOnce","mockRestore","otherError","sendInlineKeyboard","callbackData","reply_markup","inline_keyboard","callback_data","editInlineKeyboard","answerCallback","onCallback","cb","callbackQueryId","isHealthy"],"mappings":"AAAA,YAAYA,oBAAoB,WAAW;AAC3C,YAAYC,kBAAkB,6CAA6C;AAC3E,SACEC,eAAe,EACfC,wBAAwB,QACnB,gDAAgD;AAGvD,gBAAgB;AAChBC,GAAGC,IAAI,CAAC,YAAY;IAClB,MAAMC,WAAoD,CAAC;IAC3D,MAAMC,UAAU;QACdC,QAAQJ,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;QAClCC,MAAMR,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;QAChCE,IAAIT,GAAGK,EAAE,CAAC,CAACK,OAAeC;YACxBT,QAAQ,CAACQ,MAAM,GAAGC;QACpB;QACAC,UAAU;YACRC,aAAab,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;YACvCO,wBAAwBd,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;YAClDQ,eAAef,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;YACzCS,OAAOhB,GAAGK,EAAE,GAAGC,iBAAiB,CAAC;gBAAEW,UAAU;YAAW;QAC1D;QACAC,WAAWhB;QACXiB,cAAc,OAAOC,QAAgBC,QAAgBC;YACnD,MAAMC,MAAM;gBACVC,SAAS;oBACPC,MAAM;wBAAEC,IAAIN;oBAAO;oBACnBO,MAAM;wBAAED,IAAIL;oBAAO;oBACnBC;oBACAM,MAAMC,KAAKC,KAAK,CAACC,KAAKC,GAAG,KAAK;gBAChC;gBACAC,OAAOjC,GAAGK,EAAE,GAAGC,iBAAiB,CAACC;YACnC;YACA,IAAIL,QAAQ,CAAC,OAAO,EAAE;gBACpB,MAAMA,QAAQ,CAAC,OAAO,CAACqB;YACzB;YACA,OAAOA;QACT;QACAW,kBAAkB,OAAOd,QAAgBC,QAAgBc,MAAcC,YAAY,GAAG;YACpF,MAAMb,MAAM;gBACVc,eAAe;oBACbX,IAAI;oBACJS;oBACAX,SAAS;wBAAEc,YAAYF;wBAAWX,MAA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;YACnBtB,OAAO,MAAMgB,QAAQ2D,SAAS,IAAIrE,IAAI,CAAC;QACzC;QAEAE,GAAG,oCAAoC;YACrCR,OAAO,MAAMgB,QAAQ2D,SAAS,IAAIrE,IAAI,CAAC;QACzC;QAEAE,GAAG,kCAAkC;YACnC,MAAMQ,QAAQM,KAAK;YACnB,MAAMN,QAAQpD,IAAI;YAClBoC,OAAO,MAAMgB,QAAQ2D,SAAS,IAAIrE,IAAI,CAAC;QACzC;IACF;AACF"}
|
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
import { markdownToTelegramHtml } from
|
|
2
|
-
describe(
|
|
3
|
-
it(
|
|
4
|
-
const out = markdownToTelegramHtml(
|
|
5
|
-
expect(out).toContain(
|
|
6
|
-
expect(out).toContain(
|
|
7
|
-
expect(out).toContain(
|
|
8
|
-
});
|
|
9
|
-
it(
|
|
10
|
-
const md =
|
|
1
|
+
import { markdownToTelegramHtml } from "../../../adapters/telegram/telegramHtml.js";
|
|
2
|
+
describe("markdownToTelegramHtml", ()=>{
|
|
3
|
+
it("renders bold, italic, strikethrough", ()=>{
|
|
4
|
+
const out = markdownToTelegramHtml("**b** _i_ ~~s~~");
|
|
5
|
+
expect(out).toContain("<b>b</b>");
|
|
6
|
+
expect(out).toContain("<i>i</i>");
|
|
7
|
+
expect(out).toContain("<s>s</s>");
|
|
8
|
+
});
|
|
9
|
+
it("renders inline code and fenced code with language", ()=>{
|
|
10
|
+
const md = "Run `npm test`\n\n```ts\nconst x = 1;\n```\n\n```\nplain\n```";
|
|
11
11
|
const out = markdownToTelegramHtml(md);
|
|
12
|
-
expect(out).toContain(
|
|
12
|
+
expect(out).toContain("<code>npm test</code>");
|
|
13
13
|
expect(out).toContain('<pre><code class="language-ts">const x = 1;</code></pre>');
|
|
14
|
-
expect(out).toContain(
|
|
14
|
+
expect(out).toContain("<pre><code>plain</code></pre>");
|
|
15
15
|
});
|
|
16
|
-
it(
|
|
17
|
-
const md =
|
|
16
|
+
it("renders links and converts headings to bold", ()=>{
|
|
17
|
+
const md = "# Title\n\nSee [docs](https://x.com).";
|
|
18
18
|
const out = markdownToTelegramHtml(md);
|
|
19
|
-
expect(out).toContain(
|
|
19
|
+
expect(out).toContain("<b>Title</b>");
|
|
20
20
|
expect(out).toContain('<a href="https://x.com">docs</a>');
|
|
21
21
|
});
|
|
22
|
-
it(
|
|
23
|
-
const out = markdownToTelegramHtml(
|
|
22
|
+
it("renders images as alt-text links", ()=>{
|
|
23
|
+
const out = markdownToTelegramHtml("");
|
|
24
24
|
expect(out).toBe('<a href="https://x.com/d.png">diagram</a>');
|
|
25
25
|
});
|
|
26
|
-
it(
|
|
27
|
-
const out = markdownToTelegramHtml(
|
|
26
|
+
it("falls back to URL when image has no alt text", ()=>{
|
|
27
|
+
const out = markdownToTelegramHtml("");
|
|
28
28
|
expect(out).toContain('<a href="https://x.com/d.png">https://x.com/d.png</a>');
|
|
29
29
|
});
|
|
30
|
-
it(
|
|
31
|
-
const out = markdownToTelegramHtml(
|
|
32
|
-
expect(out).toContain(
|
|
33
|
-
expect(out).toContain(
|
|
34
|
-
expect(out).toContain(
|
|
35
|
-
expect(out).not.toContain(
|
|
36
|
-
});
|
|
37
|
-
it(
|
|
38
|
-
const out = markdownToTelegramHtml(
|
|
39
|
-
expect(out).toContain(
|
|
40
|
-
expect(out).toContain(
|
|
41
|
-
expect(out).not.toContain(
|
|
42
|
-
});
|
|
43
|
-
it(
|
|
44
|
-
const out = markdownToTelegramHtml(
|
|
45
|
-
expect(out).toContain(
|
|
46
|
-
expect(out).toContain(
|
|
47
|
-
expect(out).not.toContain(
|
|
48
|
-
});
|
|
49
|
-
it(
|
|
50
|
-
const out = markdownToTelegramHtml(
|
|
51
|
-
expect(out).toContain(
|
|
52
|
-
expect(out).not.toContain(
|
|
30
|
+
it("renders unordered lists with bullets", ()=>{
|
|
31
|
+
const out = markdownToTelegramHtml("- one\n- two\n- three");
|
|
32
|
+
expect(out).toContain("• one");
|
|
33
|
+
expect(out).toContain("• two");
|
|
34
|
+
expect(out).toContain("• three");
|
|
35
|
+
expect(out).not.toContain("<ul>");
|
|
36
|
+
});
|
|
37
|
+
it("renders nested lists without throwing", ()=>{
|
|
38
|
+
const out = markdownToTelegramHtml("- agent\n - Status");
|
|
39
|
+
expect(out).toContain("• agent");
|
|
40
|
+
expect(out).toContain("• Status");
|
|
41
|
+
expect(out).not.toContain("<ul>");
|
|
42
|
+
});
|
|
43
|
+
it("renders ordered lists with numbers", ()=>{
|
|
44
|
+
const out = markdownToTelegramHtml("1. one\n2. two");
|
|
45
|
+
expect(out).toContain("1. one");
|
|
46
|
+
expect(out).toContain("2. two");
|
|
47
|
+
expect(out).not.toContain("<ol>");
|
|
48
|
+
});
|
|
49
|
+
it("renders inline markup as HTML inside ordered tight lists", ()=>{
|
|
50
|
+
const out = markdownToTelegramHtml("1. **bold** `code` *italic*");
|
|
51
|
+
expect(out).toContain("1. <b>bold</b> <code>code</code> <i>italic</i>");
|
|
52
|
+
expect(out).not.toContain("<b>");
|
|
53
53
|
expect(out).not.toMatch(/\*\*|`/);
|
|
54
54
|
});
|
|
55
|
-
it(
|
|
56
|
-
const out = markdownToTelegramHtml(
|
|
57
|
-
expect(out).toContain(
|
|
55
|
+
it("renders inline markup as HTML inside unordered tight lists", ()=>{
|
|
56
|
+
const out = markdownToTelegramHtml("- **bold** `code` *italic*");
|
|
57
|
+
expect(out).toContain("• <b>bold</b> <code>code</code> <i>italic</i>");
|
|
58
58
|
expect(out).not.toMatch(/<(?:b|code|i)>/);
|
|
59
59
|
});
|
|
60
|
-
it(
|
|
61
|
-
const out = markdownToTelegramHtml(
|
|
62
|
-
expect(out).toContain(
|
|
60
|
+
it("renders inline markup in the middle of list item text", ()=>{
|
|
61
|
+
const out = markdownToTelegramHtml("- While editing, `/x` is a **literal** character.");
|
|
62
|
+
expect(out).toContain("• While editing, <code>/x</code> is a <b>literal</b> character.");
|
|
63
63
|
});
|
|
64
|
-
it(
|
|
65
|
-
const out = markdownToTelegramHtml(
|
|
66
|
-
expect(out).toContain(
|
|
67
|
-
expect(out).toContain(
|
|
68
|
-
expect(out).toContain(
|
|
64
|
+
it("renders inline markup in loose multi-paragraph lists", ()=>{
|
|
65
|
+
const out = markdownToTelegramHtml("- First **bold** paragraph.\n\n Second paragraph with *italic*.\n\n- `code` item.");
|
|
66
|
+
expect(out).toContain("• First <b>bold</b> paragraph.");
|
|
67
|
+
expect(out).toContain("Second paragraph with <i>italic</i>.");
|
|
68
|
+
expect(out).toContain("• <code>code</code> item.");
|
|
69
69
|
expect(out).not.toMatch(/<(?:b|code|i)>/);
|
|
70
70
|
});
|
|
71
|
-
it(
|
|
72
|
-
const out = markdownToTelegramHtml(
|
|
73
|
-
expect(out).toContain(
|
|
74
|
-
expect(out).toContain(
|
|
71
|
+
it("renders inline markup in nested list items", ()=>{
|
|
72
|
+
const out = markdownToTelegramHtml("- **parent**\n - child with `code`");
|
|
73
|
+
expect(out).toContain("• <b>parent</b>");
|
|
74
|
+
expect(out).toContain("• child with <code>code</code>");
|
|
75
75
|
});
|
|
76
|
-
it(
|
|
77
|
-
const out = markdownToTelegramHtml(
|
|
78
|
-
expect(out).toContain(
|
|
79
|
-
expect(out).not.toContain(
|
|
76
|
+
it("escapes raw HTML inside list items", ()=>{
|
|
77
|
+
const out = markdownToTelegramHtml("- literal <script>alert(1)</script> text");
|
|
78
|
+
expect(out).toContain("<script>");
|
|
79
|
+
expect(out).not.toContain("<script>");
|
|
80
80
|
});
|
|
81
|
-
it(
|
|
82
|
-
const out = markdownToTelegramHtml(
|
|
83
|
-
expect(out).toContain(
|
|
84
|
-
expect(out).toContain(
|
|
81
|
+
it("preserves ordered list start numbering with inline markup", ()=>{
|
|
82
|
+
const out = markdownToTelegramHtml("3. **three**\n4. *four*");
|
|
83
|
+
expect(out).toContain("3. <b>three</b>");
|
|
84
|
+
expect(out).toContain("4. <i>four</i>");
|
|
85
85
|
});
|
|
86
|
-
it(
|
|
87
|
-
const out = markdownToTelegramHtml(
|
|
86
|
+
it("renders links as HTML inside list items", ()=>{
|
|
87
|
+
const out = markdownToTelegramHtml("- See [docs](https://example.com?a=1&b=2).");
|
|
88
88
|
expect(out).toContain('• See <a href="https://example.com?a=1&b=2">docs</a>.');
|
|
89
|
-
expect(out).not.toContain(
|
|
89
|
+
expect(out).not.toContain("<a href=");
|
|
90
90
|
});
|
|
91
|
-
it(
|
|
92
|
-
const md =
|
|
91
|
+
it("renders tables as ASCII inside <pre>", ()=>{
|
|
92
|
+
const md = "| a | b |\n|---|---|\n| 1 | 2 |\n| 3 |";
|
|
93
93
|
const out = markdownToTelegramHtml(md);
|
|
94
|
-
expect(out.startsWith(
|
|
95
|
-
expect(out).toContain(
|
|
96
|
-
expect(out).toContain(
|
|
97
|
-
expect(out).toContain(
|
|
98
|
-
expect(out).toContain(
|
|
99
|
-
expect(out).toContain(
|
|
100
|
-
expect(out).not.toContain(
|
|
101
|
-
});
|
|
102
|
-
it(
|
|
103
|
-
const out = markdownToTelegramHtml(
|
|
104
|
-
expect(out).toContain(
|
|
105
|
-
expect(out).toContain(
|
|
106
|
-
expect(out).toContain(
|
|
107
|
-
});
|
|
108
|
-
it(
|
|
109
|
-
const out = markdownToTelegramHtml(
|
|
110
|
-
expect(out).toContain(
|
|
111
|
-
expect(out).toContain(
|
|
112
|
-
expect(out).toContain(
|
|
113
|
-
expect(out).not.toContain(
|
|
114
|
-
});
|
|
115
|
-
it(
|
|
116
|
-
const out = markdownToTelegramHtml(
|
|
117
|
-
expect(out).toContain(
|
|
118
|
-
});
|
|
119
|
-
it(
|
|
120
|
-
const out = markdownToTelegramHtml(
|
|
121
|
-
expect(out).not.toContain(
|
|
122
|
-
expect(out).toContain(
|
|
123
|
-
expect(out).toContain(
|
|
124
|
-
});
|
|
125
|
-
it(
|
|
126
|
-
const out = markdownToTelegramHtml(
|
|
127
|
-
expect(out).toContain(
|
|
128
|
-
expect(out).toContain(
|
|
129
|
-
expect(out).toContain(
|
|
130
|
-
});
|
|
131
|
-
it(
|
|
132
|
-
expect(markdownToTelegramHtml(
|
|
94
|
+
expect(out.startsWith("<pre>")).toBe(true);
|
|
95
|
+
expect(out).toContain("a");
|
|
96
|
+
expect(out).toContain("b");
|
|
97
|
+
expect(out).toContain("1");
|
|
98
|
+
expect(out).toContain("2");
|
|
99
|
+
expect(out).toContain("3");
|
|
100
|
+
expect(out).not.toContain("<table>");
|
|
101
|
+
});
|
|
102
|
+
it("uses <blockquote> for quotes", ()=>{
|
|
103
|
+
const out = markdownToTelegramHtml("> quoted");
|
|
104
|
+
expect(out).toContain("<blockquote>");
|
|
105
|
+
expect(out).toContain("quoted");
|
|
106
|
+
expect(out).toContain("</blockquote>");
|
|
107
|
+
});
|
|
108
|
+
it("escapes HTML special chars in plain text", ()=>{
|
|
109
|
+
const out = markdownToTelegramHtml("a < b && c > d");
|
|
110
|
+
expect(out).toContain("<");
|
|
111
|
+
expect(out).toContain("&");
|
|
112
|
+
expect(out).toContain(">");
|
|
113
|
+
expect(out).not.toContain(" < ");
|
|
114
|
+
});
|
|
115
|
+
it("escapes HTML special chars inside code", ()=>{
|
|
116
|
+
const out = markdownToTelegramHtml("`<script>`");
|
|
117
|
+
expect(out).toContain("<code><script></code>");
|
|
118
|
+
});
|
|
119
|
+
it("strips raw HTML blocks", ()=>{
|
|
120
|
+
const out = markdownToTelegramHtml("hello\n\n<div>raw</div>\n\nworld");
|
|
121
|
+
expect(out).not.toContain("<div>");
|
|
122
|
+
expect(out).toContain("hello");
|
|
123
|
+
expect(out).toContain("world");
|
|
124
|
+
});
|
|
125
|
+
it("renders horizontal rule as a divider", ()=>{
|
|
126
|
+
const out = markdownToTelegramHtml("above\n\n---\n\nbelow");
|
|
127
|
+
expect(out).toContain("above");
|
|
128
|
+
expect(out).toContain("———");
|
|
129
|
+
expect(out).toContain("below");
|
|
130
|
+
});
|
|
131
|
+
it("passes plain text through unchanged", ()=>{
|
|
132
|
+
expect(markdownToTelegramHtml("hello world")).toBe("hello world");
|
|
133
133
|
});
|
|
134
134
|
});
|
|
135
135
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/__tests__/adapters/telegram/telegramHtml.test.ts"],"sourcesContent":["import { markdownToTelegramHtml } from '../../../adapters/telegram/telegramHtml.js';\n\ndescribe('markdownToTelegramHtml', () => {\n it('renders bold, italic, strikethrough', () => {\n const out = markdownToTelegramHtml('**b** _i_ ~~s~~');\n expect(out).toContain('<b>b</b>');\n expect(out).toContain('<i>i</i>');\n expect(out).toContain('<s>s</s>');\n });\n\n it('renders inline code and fenced code with language', () => {\n const md = 'Run `npm test`\\n\\n```ts\\nconst x = 1;\\n```\\n\\n```\\nplain\\n```';\n const out = markdownToTelegramHtml(md);\n expect(out).toContain('<code>npm test</code>');\n expect(out).toContain('<pre><code class=\"language-ts\">const x = 1;</code></pre>');\n expect(out).toContain('<pre><code>plain</code></pre>');\n });\n\n it('renders links and converts headings to bold', () => {\n const md = '# Title\\n\\nSee [docs](https://x.com).';\n const out = markdownToTelegramHtml(md);\n expect(out).toContain('<b>Title</b>');\n expect(out).toContain('<a href=\"https://x.com\">docs</a>');\n });\n\n it('renders images as alt-text links', () => {\n const out = markdownToTelegramHtml('');\n expect(out).toBe('<a href=\"https://x.com/d.png\">diagram</a>');\n });\n\n it('falls back to URL when image has no alt text', () => {\n const out = markdownToTelegramHtml('');\n expect(out).toContain('<a href=\"https://x.com/d.png\">https://x.com/d.png</a>');\n });\n\n it('renders unordered lists with bullets', () => {\n const out = markdownToTelegramHtml('- one\\n- two\\n- three');\n expect(out).toContain('• one');\n expect(out).toContain('• two');\n expect(out).toContain('• three');\n expect(out).not.toContain('<ul>');\n });\n\n it('renders nested lists without throwing', () => {\n const out = markdownToTelegramHtml('- agent\\n - Status');\n\n expect(out).toContain('• agent');\n expect(out).toContain('• Status');\n expect(out).not.toContain('<ul>');\n });\n\n it('renders ordered lists with numbers', () => {\n const out = markdownToTelegramHtml('1. one\\n2. two');\n expect(out).toContain('1. one');\n expect(out).toContain('2. two');\n expect(out).not.toContain('<ol>');\n });\n\n it('renders inline markup as HTML inside ordered tight lists', () => {\n const out = markdownToTelegramHtml('1. **bold** `code` *italic*');\n\n expect(out).toContain('1. <b>bold</b> <code>code</code> <i>italic</i>');\n expect(out).not.toContain('<b>');\n expect(out).not.toMatch(/\\*\\*|`/);\n });\n\n it('renders inline markup as HTML inside unordered tight lists', () => {\n const out = markdownToTelegramHtml('- **bold** `code` *italic*');\n\n expect(out).toContain('• <b>bold</b> <code>code</code> <i>italic</i>');\n expect(out).not.toMatch(/<(?:b|code|i)>/);\n });\n\n it('renders inline markup in the middle of list item text', () => {\n const out = markdownToTelegramHtml(\n '- While editing, `/x` is a **literal** character.'\n );\n\n expect(out).toContain(\n '• While editing, <code>/x</code> is a <b>literal</b> character.'\n );\n });\n\n it('renders inline markup in loose multi-paragraph lists', () => {\n const out = markdownToTelegramHtml(\n '- First **bold** paragraph.\\n\\n Second paragraph with *italic*.\\n\\n- `code` item.'\n );\n\n expect(out).toContain('• First <b>bold</b> paragraph.');\n expect(out).toContain('Second paragraph with <i>italic</i>.');\n expect(out).toContain('• <code>code</code> item.');\n expect(out).not.toMatch(/<(?:b|code|i)>/);\n });\n\n it('renders inline markup in nested list items', () => {\n const out = markdownToTelegramHtml('- **parent**\\n - child with `code`');\n\n expect(out).toContain('• <b>parent</b>');\n expect(out).toContain('• child with <code>code</code>');\n });\n\n it('escapes raw HTML inside list items', () => {\n const out = markdownToTelegramHtml('- literal <script>alert(1)</script> text');\n\n expect(out).toContain('<script>');\n expect(out).not.toContain('<script>');\n });\n\n it('preserves ordered list start numbering with inline markup', () => {\n const out = markdownToTelegramHtml('3. **three**\\n4. *four*');\n\n expect(out).toContain('3. <b>three</b>');\n expect(out).toContain('4. <i>four</i>');\n });\n\n it('renders links as HTML inside list items', () => {\n const out = markdownToTelegramHtml('- See [docs](https://example.com?a=1&b=2).');\n\n expect(out).toContain(\n '• See <a href=\"https://example.com?a=1&b=2\">docs</a>.'\n );\n expect(out).not.toContain('<a href=');\n });\n\n it('renders tables as ASCII inside <pre>', () => {\n const md = '| a | b |\\n|---|---|\\n| 1 | 2 |\\n| 3 |';\n const out = markdownToTelegramHtml(md);\n expect(out.startsWith('<pre>')).toBe(true);\n expect(out).toContain('a');\n expect(out).toContain('b');\n expect(out).toContain('1');\n expect(out).toContain('2');\n expect(out).toContain('3');\n expect(out).not.toContain('<table>');\n });\n\n it('uses <blockquote> for quotes', () => {\n const out = markdownToTelegramHtml('> quoted');\n expect(out).toContain('<blockquote>');\n expect(out).toContain('quoted');\n expect(out).toContain('</blockquote>');\n });\n\n it('escapes HTML special chars in plain text', () => {\n const out = markdownToTelegramHtml('a < b && c > d');\n expect(out).toContain('<');\n expect(out).toContain('&');\n expect(out).toContain('>');\n expect(out).not.toContain(' < ');\n });\n\n it('escapes HTML special chars inside code', () => {\n const out = markdownToTelegramHtml('`<script>`');\n expect(out).toContain('<code><script></code>');\n });\n\n it('strips raw HTML blocks', () => {\n const out = markdownToTelegramHtml('hello\\n\\n<div>raw</div>\\n\\nworld');\n expect(out).not.toContain('<div>');\n expect(out).toContain('hello');\n expect(out).toContain('world');\n });\n\n it('renders horizontal rule as a divider', () => {\n const out = markdownToTelegramHtml('above\\n\\n---\\n\\nbelow');\n expect(out).toContain('above');\n expect(out).toContain('———');\n expect(out).toContain('below');\n });\n\n it('passes plain text through unchanged', () => {\n expect(markdownToTelegramHtml('hello world')).toBe('hello world');\n });\n});\n"],"names":["markdownToTelegramHtml","describe","it","out","expect","toContain","md","toBe","not","toMatch","startsWith"],"mappings":"AAAA,SAASA,sBAAsB,QAAQ,6CAA6C;AAEpFC,SAAS,0BAA0B;IAC/BC,GAAG,uCAAuC;QACtC,MAAMC,MAAMH,uBAAuB;QACnCI,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;IAC1B;IAEAH,GAAG,qDAAqD;QACpD,MAAMI,KAAK;QACX,MAAMH,MA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,CAACH,SAAS,CAAC;IAC9B;IAEAH,GAAG,gCAAgC;QAC/B,MAAMC,MAAMH,uBAAuB;QACnCI,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;IAC1B;IAEAH,GAAG,4CAA4C;QAC3C,MAAMC,MAAMH,uBAAuB;QACnCI,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKK,GAAG,CAACH,SAAS,CAAC;IAC9B;IAEAH,GAAG,0CAA0C;QACzC,MAAMC,MAAMH,uBAAuB;QACnCI,OAAOD,KAAKE,SAAS,CAAC;IAC1B;IAEAH,GAAG,0BAA0B;QACzB,MAAMC,MAAMH,uBAAuB;QACnCI,OAAOD,KAAKK,GAAG,CAACH,SAAS,CAAC;QAC1BD,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;IAC1B;IAEAH,GAAG,wCAAwC;QACvC,MAAMC,MAAMH,uBAAuB;QACnCI,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;IAC1B;IAEAH,GAAG,uCAAuC;QACtCE,OAAOJ,uBAAuB,gBAAgBO,IAAI,CAAC;IACvD;AACJ"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/__tests__/adapters/telegram/telegramHtml.test.ts"],"sourcesContent":["import { markdownToTelegramHtml } from \"../../../adapters/telegram/telegramHtml.js\";\n\ndescribe(\"markdownToTelegramHtml\", () => {\n it(\"renders bold, italic, strikethrough\", () => {\n const out = markdownToTelegramHtml(\"**b** _i_ ~~s~~\");\n expect(out).toContain(\"<b>b</b>\");\n expect(out).toContain(\"<i>i</i>\");\n expect(out).toContain(\"<s>s</s>\");\n });\n\n it(\"renders inline code and fenced code with language\", () => {\n const md = \"Run `npm test`\\n\\n```ts\\nconst x = 1;\\n```\\n\\n```\\nplain\\n```\";\n const out = markdownToTelegramHtml(md);\n expect(out).toContain(\"<code>npm test</code>\");\n expect(out).toContain('<pre><code class=\"language-ts\">const x = 1;</code></pre>');\n expect(out).toContain(\"<pre><code>plain</code></pre>\");\n });\n\n it(\"renders links and converts headings to bold\", () => {\n const md = \"# Title\\n\\nSee [docs](https://x.com).\";\n const out = markdownToTelegramHtml(md);\n expect(out).toContain(\"<b>Title</b>\");\n expect(out).toContain('<a href=\"https://x.com\">docs</a>');\n });\n\n it(\"renders images as alt-text links\", () => {\n const out = markdownToTelegramHtml(\"\");\n expect(out).toBe('<a href=\"https://x.com/d.png\">diagram</a>');\n });\n\n it(\"falls back to URL when image has no alt text\", () => {\n const out = markdownToTelegramHtml(\"\");\n expect(out).toContain('<a href=\"https://x.com/d.png\">https://x.com/d.png</a>');\n });\n\n it(\"renders unordered lists with bullets\", () => {\n const out = markdownToTelegramHtml(\"- one\\n- two\\n- three\");\n expect(out).toContain(\"• one\");\n expect(out).toContain(\"• two\");\n expect(out).toContain(\"• three\");\n expect(out).not.toContain(\"<ul>\");\n });\n\n it(\"renders nested lists without throwing\", () => {\n const out = markdownToTelegramHtml(\"- agent\\n - Status\");\n\n expect(out).toContain(\"• agent\");\n expect(out).toContain(\"• Status\");\n expect(out).not.toContain(\"<ul>\");\n });\n\n it(\"renders ordered lists with numbers\", () => {\n const out = markdownToTelegramHtml(\"1. one\\n2. two\");\n expect(out).toContain(\"1. one\");\n expect(out).toContain(\"2. two\");\n expect(out).not.toContain(\"<ol>\");\n });\n\n it(\"renders inline markup as HTML inside ordered tight lists\", () => {\n const out = markdownToTelegramHtml(\"1. **bold** `code` *italic*\");\n\n expect(out).toContain(\"1. <b>bold</b> <code>code</code> <i>italic</i>\");\n expect(out).not.toContain(\"<b>\");\n expect(out).not.toMatch(/\\*\\*|`/);\n });\n\n it(\"renders inline markup as HTML inside unordered tight lists\", () => {\n const out = markdownToTelegramHtml(\"- **bold** `code` *italic*\");\n\n expect(out).toContain(\"• <b>bold</b> <code>code</code> <i>italic</i>\");\n expect(out).not.toMatch(/<(?:b|code|i)>/);\n });\n\n it(\"renders inline markup in the middle of list item text\", () => {\n const out = markdownToTelegramHtml(\"- While editing, `/x` is a **literal** character.\");\n\n expect(out).toContain(\"• While editing, <code>/x</code> is a <b>literal</b> character.\");\n });\n\n it(\"renders inline markup in loose multi-paragraph lists\", () => {\n const out = markdownToTelegramHtml(\n \"- First **bold** paragraph.\\n\\n Second paragraph with *italic*.\\n\\n- `code` item.\",\n );\n\n expect(out).toContain(\"• First <b>bold</b> paragraph.\");\n expect(out).toContain(\"Second paragraph with <i>italic</i>.\");\n expect(out).toContain(\"• <code>code</code> item.\");\n expect(out).not.toMatch(/<(?:b|code|i)>/);\n });\n\n it(\"renders inline markup in nested list items\", () => {\n const out = markdownToTelegramHtml(\"- **parent**\\n - child with `code`\");\n\n expect(out).toContain(\"• <b>parent</b>\");\n expect(out).toContain(\"• child with <code>code</code>\");\n });\n\n it(\"escapes raw HTML inside list items\", () => {\n const out = markdownToTelegramHtml(\"- literal <script>alert(1)</script> text\");\n\n expect(out).toContain(\"<script>\");\n expect(out).not.toContain(\"<script>\");\n });\n\n it(\"preserves ordered list start numbering with inline markup\", () => {\n const out = markdownToTelegramHtml(\"3. **three**\\n4. *four*\");\n\n expect(out).toContain(\"3. <b>three</b>\");\n expect(out).toContain(\"4. <i>four</i>\");\n });\n\n it(\"renders links as HTML inside list items\", () => {\n const out = markdownToTelegramHtml(\"- See [docs](https://example.com?a=1&b=2).\");\n\n expect(out).toContain('• See <a href=\"https://example.com?a=1&b=2\">docs</a>.');\n expect(out).not.toContain(\"<a href=\");\n });\n\n it(\"renders tables as ASCII inside <pre>\", () => {\n const md = \"| a | b |\\n|---|---|\\n| 1 | 2 |\\n| 3 |\";\n const out = markdownToTelegramHtml(md);\n expect(out.startsWith(\"<pre>\")).toBe(true);\n expect(out).toContain(\"a\");\n expect(out).toContain(\"b\");\n expect(out).toContain(\"1\");\n expect(out).toContain(\"2\");\n expect(out).toContain(\"3\");\n expect(out).not.toContain(\"<table>\");\n });\n\n it(\"uses <blockquote> for quotes\", () => {\n const out = markdownToTelegramHtml(\"> quoted\");\n expect(out).toContain(\"<blockquote>\");\n expect(out).toContain(\"quoted\");\n expect(out).toContain(\"</blockquote>\");\n });\n\n it(\"escapes HTML special chars in plain text\", () => {\n const out = markdownToTelegramHtml(\"a < b && c > d\");\n expect(out).toContain(\"<\");\n expect(out).toContain(\"&\");\n expect(out).toContain(\">\");\n expect(out).not.toContain(\" < \");\n });\n\n it(\"escapes HTML special chars inside code\", () => {\n const out = markdownToTelegramHtml(\"`<script>`\");\n expect(out).toContain(\"<code><script></code>\");\n });\n\n it(\"strips raw HTML blocks\", () => {\n const out = markdownToTelegramHtml(\"hello\\n\\n<div>raw</div>\\n\\nworld\");\n expect(out).not.toContain(\"<div>\");\n expect(out).toContain(\"hello\");\n expect(out).toContain(\"world\");\n });\n\n it(\"renders horizontal rule as a divider\", () => {\n const out = markdownToTelegramHtml(\"above\\n\\n---\\n\\nbelow\");\n expect(out).toContain(\"above\");\n expect(out).toContain(\"———\");\n expect(out).toContain(\"below\");\n });\n\n it(\"passes plain text through unchanged\", () => {\n expect(markdownToTelegramHtml(\"hello world\")).toBe(\"hello world\");\n });\n});\n"],"names":["markdownToTelegramHtml","describe","it","out","expect","toContain","md","toBe","not","toMatch","startsWith"],"mappings":"AAAA,SAASA,sBAAsB,QAAQ,6CAA6C;AAEpFC,SAAS,0BAA0B;IACjCC,GAAG,uCAAuC;QACxC,MAAMC,MAAMH,uBAAuB;QACnCI,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;IACxB;IAEAH,GAAG,qDAAqD;QACtD,MAAMI,KAAK;QACX,MAAMH,MAAMH,uBAAuBM;QACnCF,OAAOD,KAAKE,SAAS,CAA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;QACjC,MAAMC,MAAMH,uBAAuB;QACnCI,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;IACxB;IAEAH,GAAG,4CAA4C;QAC7C,MAAMC,MAAMH,uBAAuB;QACnCI,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKK,GAAG,CAACH,SAAS,CAAC;IAC5B;IAEAH,GAAG,0CAA0C;QAC3C,MAAMC,MAAMH,uBAAuB;QACnCI,OAAOD,KAAKE,SAAS,CAAC;IACxB;IAEAH,GAAG,0BAA0B;QAC3B,MAAMC,MAAMH,uBAAuB;QACnCI,OAAOD,KAAKK,GAAG,CAACH,SAAS,CAAC;QAC1BD,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;IACxB;IAEAH,GAAG,wCAAwC;QACzC,MAAMC,MAAMH,uBAAuB;QACnCI,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;QACtBD,OAAOD,KAAKE,SAAS,CAAC;IACxB;IAEAH,GAAG,uCAAuC;QACxCE,OAAOJ,uBAAuB,gBAAgBO,IAAI,CAAC;IACrD;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChannelQuestion, IncomingInteraction, IncomingMessage, SendMessageOptions, SentMessage } from
|
|
1
|
+
import type { ChannelQuestion, IncomingInteraction, IncomingMessage, SendMessageOptions, SentMessage } from "../types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Interface for messaging platform adapters.
|
|
4
4
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChannelAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/ChannelAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":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ter(adapter) {
|
|
2
|
-
return
|
|
2
|
+
return "onInteraction" in adapter && "sendQuestion" in adapter && "finalizeInteraction" in adapter;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
//# sourceMappingURL=ChannelAdapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/adapters/ChannelAdapter.ts"],"sourcesContent":["import type {\n
|
|
1
|
+
{"version":3,"sources":["../../src/adapters/ChannelAdapter.ts"],"sourcesContent":["import type {\n ChannelQuestion,\n IncomingInteraction,\n IncomingMessage,\n SendMessageOptions,\n SentMessage,\n} from \"../types.js\";\n\n/**\n * Interface for messaging platform adapters.\n *\n * Implementations connect to a specific platform (Telegram, Slack, etc.)\n * and provide a generic send/receive abstraction.\n */\nexport interface ChannelAdapter {\n /** Identifier for this channel type (e.g., 'telegram') */\n readonly type: string;\n\n /** Start listening for incoming messages */\n start(): Promise<void>;\n\n /** Stop listening and clean up resources */\n stop(): Promise<void>;\n\n /**\n * Send a message to a specific chat.\n * Implementations should handle platform-specific limits\n * (e.g., chunking at 4096 chars for Telegram).\n */\n sendMessage(\n chatId: string,\n text: string,\n options?: SendMessageOptions,\n ): Promise<SentMessage | void>;\n\n /**\n * Register a handler for incoming text messages.\n * Fire-and-forget — handler returns void.\n * Responses are sent separately via sendMessage().\n */\n onMessage(handler: (msg: IncomingMessage) => Promise<void>): void;\n\n /** Check if the adapter is connected and healthy */\n isHealthy(): Promise<boolean>;\n}\n\nexport interface InteractiveChannelAdapter extends ChannelAdapter {\n onInteraction(handler: (interaction: IncomingInteraction) => Promise<void>): void;\n sendQuestion(chatId: string, question: ChannelQuestion): Promise<SentMessage>;\n finalizeInteraction(chatId: string, messageId: string): Promise<void>;\n}\n\nexport function isInteractiveChannelAdapter(\n adapter: ChannelAdapter,\n): adapter is InteractiveChannelAdapter {\n return (\n \"onInteraction\" in adapter && \"sendQuestion\" in adapter && \"finalizeInteraction\" in adapter\n );\n}\n"],"names":["isInteractiveChannelAdapter","adapter"],"mappings":"AAoDA,OAAO,SAASA,4BACdC,OAAuB;IAEvB,OACE,mBAAmBA,WAAW,kBAAkBA,WAAW,yBAAyBA;AAExF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { InteractiveChannelAdapter } from
|
|
2
|
-
import type { ChannelQuestion, IncomingInteraction, IncomingMessage, SentMessage, SlackConfig } from
|
|
1
|
+
import type { InteractiveChannelAdapter } from "../ChannelAdapter.js";
|
|
2
|
+
import type { ChannelQuestion, IncomingInteraction, IncomingMessage, SentMessage, SlackConfig } from "../../types.js";
|
|
3
3
|
export declare const SLACK_CHANNEL_TYPE = "slack";
|
|
4
4
|
interface SlackAuthClient {
|
|
5
5
|
authTest(): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SlackAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/slack/SlackAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"SlackAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/slack/SlackAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,WAAW,EACX,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAIxB,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAE1C,UAAU,eAAe;IACvB,QAAQ,IAAI,OAAO,CAAC;QAClB,EAAE,CAAC,EAAE,OAAO,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;CACJ;AAED,MAAM,WAAW,aAAa;IAC5B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