File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed
Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 11import { eq } from 'drizzle-orm'
22import { type NextRequest , NextResponse } from 'next/server'
3+ import { env } from '@/lib/env'
34import { createLogger } from '@/lib/logs/console-logger'
45import { db } from '@/db'
56import { 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,
Original file line number Diff line number Diff line change 11import type { ToolConfig } from '../types'
22import 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+
421export 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
You can’t perform that action at this time.
0 commit comments