Skip to content

Commit a6fe706

Browse files
Adam GoughAdam Gough
authored andcommitted
fix: added proper markdown
1 parent 2d5ddf6 commit a6fe706

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

apps/sim/app/api/webhooks/test/route.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { eq } from 'drizzle-orm'
22
import { type NextRequest, NextResponse } from 'next/server'
3+
import { env } from '@/lib/env'
34
import { createLogger } from '@/lib/logs/console-logger'
45
import { db } from '@/db'
56
import { webhook } from '@/db/schema'
@@ -36,8 +37,19 @@ export async function GET(request: NextRequest) {
3637
const providerConfig = (foundWebhook.providerConfig as Record<string, any>) || {}
3738

3839
// Construct the webhook URL
39-
const baseUrl = new URL(request.url).origin
40-
const webhookUrl = `${baseUrl}/api/webhooks/trigger/${foundWebhook.path}`
40+
const requestOrigin = new URL(request.url).origin
41+
// Ensure origin does not point to localhost for external API calls
42+
const effectiveOrigin = requestOrigin.includes('localhost')
43+
? env.NEXT_PUBLIC_APP_URL || requestOrigin // Use env var if available, fallback to original
44+
: requestOrigin
45+
46+
const webhookUrl = `${effectiveOrigin}/api/webhooks/trigger/${foundWebhook.path}`
47+
48+
if (effectiveOrigin !== requestOrigin) {
49+
logger.debug(
50+
`[${requestId}] Remapped localhost origin to ${effectiveOrigin} for webhook testing`
51+
)
52+
}
4153

4254
logger.info(`[${requestId}] Testing webhook for provider: ${provider}`, {
4355
webhookId,

apps/sim/tools/telegram/message.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
import type { ToolConfig } from '../types'
22
import type { TelegramMessageParams, TelegramMessageResponse } from './types'
33

4+
// Helper function to convert basic markdown to HTML
5+
function convertMarkdownToHTML(text: string): string {
6+
return (
7+
text
8+
// Bold: **text** or __text__ -> <b>text</b>
9+
.replace(/\*\*(.*?)\*\*/g, '<b>$1</b>')
10+
.replace(/__(.*?)__/g, '<b>$1</b>')
11+
// Italic: *text* or _text_ -> <i>text</i>
12+
.replace(/\*(.*?)\*/g, '<i>$1</i>')
13+
.replace(/_(.*?)_/g, '<i>$1</i>')
14+
// Code: `text` -> <code>text</code>
15+
.replace(/`(.*?)`/g, '<code>$1</code>')
16+
// Links: [text](url) -> <a href="url">text</a>
17+
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>')
18+
)
19+
}
20+
421
export const telegramMessageTool: ToolConfig<TelegramMessageParams, TelegramMessageResponse> = {
522
id: 'telegram_message',
623
name: 'Telegram Message',
@@ -36,7 +53,8 @@ export const telegramMessageTool: ToolConfig<TelegramMessageParams, TelegramMess
3653
}),
3754
body: (params: TelegramMessageParams) => ({
3855
chat_id: params.chatId,
39-
text: params.text,
56+
text: convertMarkdownToHTML(params.text),
57+
parse_mode: 'HTML',
4058
}),
4159
},
4260

0 commit comments

Comments
 (0)