Skip to content

Commit 567f7a5

Browse files
authored
feat(telegram-bot): removed trigger phrase
feat(telegram-bot): removed trigger phrase
1 parent b0cc595 commit 567f7a5

File tree

6 files changed

+149
-61
lines changed

6 files changed

+149
-61
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,16 +352,13 @@ async function createTelegramWebhookSubscription(
352352
) {
353353
try {
354354
const { path, providerConfig } = webhookData
355-
const { botToken, triggerPhrase } = providerConfig || {}
355+
const { botToken } = providerConfig || {}
356356

357-
if (!botToken || !triggerPhrase) {
358-
logger.warn(
359-
`[${requestId}] Missing botToken or triggerPhrase for Telegram webhook creation.`,
360-
{
361-
webhookId: webhookData.id,
362-
}
363-
)
364-
return // Cannot proceed without botToken and triggerPhrase
357+
if (!botToken) {
358+
logger.warn(`[${requestId}] Missing botToken for Telegram webhook creation.`, {
359+
webhookId: webhookData.id,
360+
})
361+
return // Cannot proceed without botToken
365362
}
366363

367364
const requestOrigin = new URL(request.url).origin

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ export async function GET(request: NextRequest) {
129129

130130
case 'telegram': {
131131
const botToken = providerConfig.botToken
132-
const triggerPhrase = providerConfig.triggerPhrase
133132

134-
if (!botToken || !triggerPhrase) {
133+
if (!botToken) {
135134
logger.warn(`[${requestId}] Telegram webhook missing configuration: ${webhookId}`)
136135
return NextResponse.json(
137136
{ success: false, error: 'Webhook has incomplete configuration' },
@@ -229,7 +228,6 @@ export async function GET(request: NextRequest) {
229228
id: foundWebhook.id,
230229
url: webhookUrl,
231230
botToken: `${botToken.substring(0, 5)}...${botToken.substring(botToken.length - 5)}`, // Show partial token for security
232-
triggerPhrase,
233231
isActive: foundWebhook.isActive,
234232
},
235233
test: {
@@ -238,7 +236,7 @@ export async function GET(request: NextRequest) {
238236
webhookInfo,
239237
},
240238
message: success
241-
? 'Telegram webhook appears to be working. Your bot should now receive messages.'
239+
? 'Telegram webhook appears to be working. Any message sent to your bot will trigger the workflow.'
242240
: 'Telegram webhook test failed. Please check server logs for more details.',
243241
curlCommand,
244242
info: 'To fix issues with Telegram webhooks getting 403 Forbidden responses, ensure the webhook request includes a User-Agent header.',

apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/webhook/components/providers/telegram.tsx

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { TestResultDisplay as WebhookTestResult } from '../ui/test-result'
88
interface TelegramConfigProps {
99
botToken: string
1010
setBotToken: (value: string) => void
11-
triggerPhrase: string
12-
setTriggerPhrase: (value: string) => void
1311
isLoadingToken: boolean
1412
testResult: any
1513
copied: string | null
@@ -22,8 +20,6 @@ interface TelegramConfigProps {
2220
export function TelegramConfig({
2321
botToken,
2422
setBotToken,
25-
triggerPhrase,
26-
setTriggerPhrase,
2723
isLoadingToken,
2824
testResult,
2925
copied,
@@ -55,26 +51,6 @@ export function TelegramConfig({
5551
/>
5652
)}
5753
</ConfigField>
58-
59-
<ConfigField
60-
id='telegram-trigger-phrase'
61-
label='Trigger Phrase *'
62-
description='The phrase that will trigger the workflow when sent to the bot'
63-
>
64-
{isLoadingToken ? (
65-
<Skeleton className='h-10 w-full' />
66-
) : (
67-
<Input
68-
id='telegram-trigger-phrase'
69-
value={triggerPhrase}
70-
onChange={(e) => {
71-
setTriggerPhrase(e.target.value)
72-
}}
73-
placeholder='/start_workflow'
74-
required
75-
/>
76-
)}
77-
</ConfigField>
7854
</ConfigSection>
7955

8056
{testResult && (
@@ -104,8 +80,8 @@ export function TelegramConfig({
10480
</a>{' '}
10581
in Telegram to create a bot and copy its token.
10682
</li>
107-
<li>Enter your Bot Token and a trigger phrase above.</li>
108-
<li>Save settings and send the trigger phrase to your bot to start the workflow.</li>
83+
<li>Enter your Bot Token above.</li>
84+
<li>Save settings and any message sent to your bot will trigger the workflow.</li>
10985
</ol>
11086
</InstructionsSection>
11187
</div>

apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/webhook/components/webhook-modal.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ export function WebhookModal({
7979
const [discordAvatarUrl, setDiscordAvatarUrl] = useState('')
8080
const [slackSigningSecret, setSlackSigningSecret] = useState('')
8181
const [telegramBotToken, setTelegramBotToken] = useState('')
82-
const [telegramTriggerPhrase, setTelegramTriggerPhrase] = useState('')
8382
// Airtable-specific state
8483
const [airtableWebhookSecret, _setAirtableWebhookSecret] = useState('')
8584
const [airtableBaseId, setAirtableBaseId] = useState('')
@@ -104,7 +103,6 @@ export function WebhookModal({
104103
airtableTableId: '',
105104
airtableIncludeCellValues: false,
106105
telegramBotToken: '',
107-
telegramTriggerPhrase: '',
108106
selectedLabels: ['INBOX'] as string[],
109107
labelFilterBehavior: 'INCLUDE',
110108
markAsRead: false,
@@ -227,15 +225,12 @@ export function WebhookModal({
227225
}))
228226
} else if (webhookProvider === 'telegram') {
229227
const botToken = config.botToken || ''
230-
const triggerPhrase = config.triggerPhrase || ''
231228

232229
setTelegramBotToken(botToken)
233-
setTelegramTriggerPhrase(triggerPhrase)
234230

235231
setOriginalValues((prev) => ({
236232
...prev,
237233
telegramBotToken: botToken,
238-
telegramTriggerPhrase: triggerPhrase,
239234
}))
240235
} else if (webhookProvider === 'gmail') {
241236
const labelIds = config.labelIds || []
@@ -292,9 +287,7 @@ export function WebhookModal({
292287
airtableBaseId !== originalValues.airtableBaseId ||
293288
airtableTableId !== originalValues.airtableTableId ||
294289
airtableIncludeCellValues !== originalValues.airtableIncludeCellValues)) ||
295-
(webhookProvider === 'telegram' &&
296-
(telegramBotToken !== originalValues.telegramBotToken ||
297-
telegramTriggerPhrase !== originalValues.telegramTriggerPhrase)) ||
290+
(webhookProvider === 'telegram' && telegramBotToken !== originalValues.telegramBotToken) ||
298291
(webhookProvider === 'gmail' &&
299292
(!selectedLabels.every((label) => originalValues.selectedLabels.includes(label)) ||
300293
!originalValues.selectedLabels.every((label) => selectedLabels.includes(label)) ||
@@ -319,7 +312,6 @@ export function WebhookModal({
319312
airtableTableId,
320313
airtableIncludeCellValues,
321314
telegramBotToken,
322-
telegramTriggerPhrase,
323315
selectedLabels,
324316
labelFilterBehavior,
325317
markAsRead,
@@ -345,7 +337,7 @@ export function WebhookModal({
345337
isValid = discordWebhookName.trim() !== ''
346338
break
347339
case 'telegram':
348-
isValid = telegramBotToken.trim() !== '' && telegramTriggerPhrase.trim() !== ''
340+
isValid = telegramBotToken.trim() !== ''
349341
break
350342
case 'gmail':
351343
isValid = selectedLabels.length > 0
@@ -359,7 +351,6 @@ export function WebhookModal({
359351
slackSigningSecret,
360352
whatsappVerificationToken,
361353
telegramBotToken,
362-
telegramTriggerPhrase,
363354
selectedLabels,
364355
])
365356

@@ -428,7 +419,6 @@ export function WebhookModal({
428419
case 'telegram':
429420
return {
430421
botToken: telegramBotToken || undefined,
431-
triggerPhrase: telegramTriggerPhrase || undefined,
432422
}
433423
default:
434424
return {}
@@ -479,7 +469,6 @@ export function WebhookModal({
479469
airtableTableId,
480470
airtableIncludeCellValues,
481471
telegramBotToken,
482-
telegramTriggerPhrase,
483472
selectedLabels,
484473
labelFilterBehavior,
485474
markAsRead,
@@ -713,8 +702,6 @@ export function WebhookModal({
713702
<TelegramConfig
714703
botToken={telegramBotToken}
715704
setBotToken={setTelegramBotToken}
716-
triggerPhrase={telegramTriggerPhrase}
717-
setTriggerPhrase={setTelegramTriggerPhrase}
718705
isLoadingToken={isLoadingToken}
719706
testResult={testResult}
720707
copied={copied}

apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/webhook/webhook.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ export interface AirtableWebhookConfig {
8383

8484
export interface TelegramConfig {
8585
botToken?: string
86-
triggerPhrase?: string
8786
}
8887

8988
// Union type for all provider configurations
@@ -273,12 +272,6 @@ export const WEBHOOK_PROVIDERS: { [key: string]: WebhookProvider } = {
273272
placeholder: 'Enter your Telegram Bot Token',
274273
description: 'The token for your Telegram bot.',
275274
},
276-
triggerPhrase: {
277-
type: 'string',
278-
label: 'Trigger Phrase',
279-
placeholder: '/start_workflow',
280-
description: 'The phrase that will trigger the workflow when sent to the bot.',
281-
},
282275
},
283276
},
284277
}

apps/sim/lib/webhooks/utils.ts

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,143 @@ export function formatWebhookInput(
258258
}
259259
return null
260260
}
261+
262+
if (foundWebhook.provider === 'telegram') {
263+
// Telegram input formatting logic
264+
const message =
265+
body?.message || body?.edited_message || body?.channel_post || body?.edited_channel_post
266+
267+
if (message) {
268+
// Extract message text with fallbacks for different content types
269+
let input = ''
270+
271+
if (message.text) {
272+
input = message.text
273+
} else if (message.caption) {
274+
input = message.caption
275+
} else if (message.photo) {
276+
input = 'Photo message'
277+
} else if (message.document) {
278+
input = `Document: ${message.document.file_name || 'file'}`
279+
} else if (message.audio) {
280+
input = `Audio: ${message.audio.title || 'audio file'}`
281+
} else if (message.video) {
282+
input = 'Video message'
283+
} else if (message.voice) {
284+
input = 'Voice message'
285+
} else if (message.sticker) {
286+
input = `Sticker: ${message.sticker.emoji || '🎭'}`
287+
} else if (message.location) {
288+
input = 'Location shared'
289+
} else if (message.contact) {
290+
input = `Contact: ${message.contact.first_name || 'contact'}`
291+
} else if (message.poll) {
292+
input = `Poll: ${message.poll.question}`
293+
} else {
294+
input = 'Message received'
295+
}
296+
297+
return {
298+
input, // Primary workflow input - the message content
299+
telegram: {
300+
message: {
301+
id: message.message_id,
302+
text: message.text,
303+
caption: message.caption,
304+
date: message.date,
305+
messageType: message.photo
306+
? 'photo'
307+
: message.document
308+
? 'document'
309+
: message.audio
310+
? 'audio'
311+
: message.video
312+
? 'video'
313+
: message.voice
314+
? 'voice'
315+
: message.sticker
316+
? 'sticker'
317+
: message.location
318+
? 'location'
319+
: message.contact
320+
? 'contact'
321+
: message.poll
322+
? 'poll'
323+
: 'text',
324+
raw: message,
325+
},
326+
sender: message.from
327+
? {
328+
id: message.from.id,
329+
firstName: message.from.first_name,
330+
lastName: message.from.last_name,
331+
username: message.from.username,
332+
languageCode: message.from.language_code,
333+
isBot: message.from.is_bot,
334+
}
335+
: null,
336+
chat: message.chat
337+
? {
338+
id: message.chat.id,
339+
type: message.chat.type,
340+
title: message.chat.title,
341+
username: message.chat.username,
342+
firstName: message.chat.first_name,
343+
lastName: message.chat.last_name,
344+
}
345+
: null,
346+
updateId: body.update_id,
347+
updateType: body.message
348+
? 'message'
349+
: body.edited_message
350+
? 'edited_message'
351+
: body.channel_post
352+
? 'channel_post'
353+
: body.edited_channel_post
354+
? 'edited_channel_post'
355+
: 'unknown',
356+
},
357+
webhook: {
358+
data: {
359+
provider: 'telegram',
360+
path: foundWebhook.path,
361+
providerConfig: foundWebhook.providerConfig,
362+
payload: body,
363+
headers: Object.fromEntries(request.headers.entries()),
364+
method: request.method,
365+
},
366+
},
367+
workflowId: foundWorkflow.id,
368+
}
369+
}
370+
371+
// Fallback for unknown Telegram update types
372+
logger.warn('Unknown Telegram update type', {
373+
updateId: body.update_id,
374+
bodyKeys: Object.keys(body || {}),
375+
})
376+
377+
return {
378+
input: 'Telegram update received',
379+
telegram: {
380+
updateId: body.update_id,
381+
updateType: 'unknown',
382+
raw: body,
383+
},
384+
webhook: {
385+
data: {
386+
provider: 'telegram',
387+
path: foundWebhook.path,
388+
providerConfig: foundWebhook.providerConfig,
389+
payload: body,
390+
headers: Object.fromEntries(request.headers.entries()),
391+
method: request.method,
392+
},
393+
},
394+
workflowId: foundWorkflow.id,
395+
}
396+
}
397+
261398
if (foundWebhook.provider === 'gmail') {
262399
if (body && typeof body === 'object' && 'email' in body) {
263400
return body // { email: {...}, timestamp: ... }

0 commit comments

Comments
 (0)