Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion apps/sim/tools/telegram/message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import type { ToolConfig } from '../types'
import type { TelegramMessageParams, TelegramMessageResponse } from './types'

// Helper function to convert basic markdown to HTML
function convertMarkdownToHTML(text: string): string {
return (
text
// Bold: **text** or __text__ -> <b>text</b>
.replace(/\*\*(.*?)\*\*/g, '<b>$1</b>')
.replace(/__(.*?)__/g, '<b>$1</b>')
// Italic: *text* or _text_ -> <i>text</i>
.replace(/\*(.*?)\*/g, '<i>$1</i>')
.replace(/_(.*?)_/g, '<i>$1</i>')
Comment on lines +12 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: The italic regex patterns will conflict with bold patterns since * is used for both. Consider processing bold before italic and using negative lookahead to prevent double processing.

// Code: `text` -> <code>text</code>
.replace(/`(.*?)`/g, '<code>$1</code>')
// Links: [text](url) -> <a href="url">text</a>
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>')
)
}

export const telegramMessageTool: ToolConfig<TelegramMessageParams, TelegramMessageResponse> = {
id: 'telegram_message',
name: 'Telegram Message',
Expand Down Expand Up @@ -36,7 +53,8 @@ export const telegramMessageTool: ToolConfig<TelegramMessageParams, TelegramMess
}),
body: (params: TelegramMessageParams) => ({
chat_id: params.chatId,
text: params.text,
text: convertMarkdownToHTML(params.text),
parse_mode: 'HTML',
}),
},

Expand Down