feat(telegram-bot): removed trigger phrase

feat(telegram-bot): removed trigger phrase
This commit is contained in:
Adam Gough
2025-06-06 13:36:26 -07:00
committed by GitHub
parent b0cc595434
commit 567f7a5e10
6 changed files with 149 additions and 61 deletions
+6 -9
View File
@@ -352,16 +352,13 @@ async function createTelegramWebhookSubscription(
) {
try {
const { path, providerConfig } = webhookData
const { botToken, triggerPhrase } = providerConfig || {}
const { botToken } = providerConfig || {}
if (!botToken || !triggerPhrase) {
logger.warn(
`[${requestId}] Missing botToken or triggerPhrase for Telegram webhook creation.`,
{
webhookId: webhookData.id,
}
)
return // Cannot proceed without botToken and triggerPhrase
if (!botToken) {
logger.warn(`[${requestId}] Missing botToken for Telegram webhook creation.`, {
webhookId: webhookData.id,
})
return // Cannot proceed without botToken
}
const requestOrigin = new URL(request.url).origin
+2 -4
View File
@@ -129,9 +129,8 @@ export async function GET(request: NextRequest) {
case 'telegram': {
const botToken = providerConfig.botToken
const triggerPhrase = providerConfig.triggerPhrase
if (!botToken || !triggerPhrase) {
if (!botToken) {
logger.warn(`[${requestId}] Telegram webhook missing configuration: ${webhookId}`)
return NextResponse.json(
{ success: false, error: 'Webhook has incomplete configuration' },
@@ -229,7 +228,6 @@ export async function GET(request: NextRequest) {
id: foundWebhook.id,
url: webhookUrl,
botToken: `${botToken.substring(0, 5)}...${botToken.substring(botToken.length - 5)}`, // Show partial token for security
triggerPhrase,
isActive: foundWebhook.isActive,
},
test: {
@@ -238,7 +236,7 @@ export async function GET(request: NextRequest) {
webhookInfo,
},
message: success
? 'Telegram webhook appears to be working. Your bot should now receive messages.'
? 'Telegram webhook appears to be working. Any message sent to your bot will trigger the workflow.'
: 'Telegram webhook test failed. Please check server logs for more details.',
curlCommand,
info: 'To fix issues with Telegram webhooks getting 403 Forbidden responses, ensure the webhook request includes a User-Agent header.',
@@ -8,8 +8,6 @@ import { TestResultDisplay as WebhookTestResult } from '../ui/test-result'
interface TelegramConfigProps {
botToken: string
setBotToken: (value: string) => void
triggerPhrase: string
setTriggerPhrase: (value: string) => void
isLoadingToken: boolean
testResult: any
copied: string | null
@@ -22,8 +20,6 @@ interface TelegramConfigProps {
export function TelegramConfig({
botToken,
setBotToken,
triggerPhrase,
setTriggerPhrase,
isLoadingToken,
testResult,
copied,
@@ -55,26 +51,6 @@ export function TelegramConfig({
/>
)}
</ConfigField>
<ConfigField
id='telegram-trigger-phrase'
label='Trigger Phrase *'
description='The phrase that will trigger the workflow when sent to the bot'
>
{isLoadingToken ? (
<Skeleton className='h-10 w-full' />
) : (
<Input
id='telegram-trigger-phrase'
value={triggerPhrase}
onChange={(e) => {
setTriggerPhrase(e.target.value)
}}
placeholder='/start_workflow'
required
/>
)}
</ConfigField>
</ConfigSection>
{testResult && (
@@ -104,8 +80,8 @@ export function TelegramConfig({
</a>{' '}
in Telegram to create a bot and copy its token.
</li>
<li>Enter your Bot Token and a trigger phrase above.</li>
<li>Save settings and send the trigger phrase to your bot to start the workflow.</li>
<li>Enter your Bot Token above.</li>
<li>Save settings and any message sent to your bot will trigger the workflow.</li>
</ol>
</InstructionsSection>
</div>
@@ -79,7 +79,6 @@ export function WebhookModal({
const [discordAvatarUrl, setDiscordAvatarUrl] = useState('')
const [slackSigningSecret, setSlackSigningSecret] = useState('')
const [telegramBotToken, setTelegramBotToken] = useState('')
const [telegramTriggerPhrase, setTelegramTriggerPhrase] = useState('')
// Airtable-specific state
const [airtableWebhookSecret, _setAirtableWebhookSecret] = useState('')
const [airtableBaseId, setAirtableBaseId] = useState('')
@@ -104,7 +103,6 @@ export function WebhookModal({
airtableTableId: '',
airtableIncludeCellValues: false,
telegramBotToken: '',
telegramTriggerPhrase: '',
selectedLabels: ['INBOX'] as string[],
labelFilterBehavior: 'INCLUDE',
markAsRead: false,
@@ -227,15 +225,12 @@ export function WebhookModal({
}))
} else if (webhookProvider === 'telegram') {
const botToken = config.botToken || ''
const triggerPhrase = config.triggerPhrase || ''
setTelegramBotToken(botToken)
setTelegramTriggerPhrase(triggerPhrase)
setOriginalValues((prev) => ({
...prev,
telegramBotToken: botToken,
telegramTriggerPhrase: triggerPhrase,
}))
} else if (webhookProvider === 'gmail') {
const labelIds = config.labelIds || []
@@ -292,9 +287,7 @@ export function WebhookModal({
airtableBaseId !== originalValues.airtableBaseId ||
airtableTableId !== originalValues.airtableTableId ||
airtableIncludeCellValues !== originalValues.airtableIncludeCellValues)) ||
(webhookProvider === 'telegram' &&
(telegramBotToken !== originalValues.telegramBotToken ||
telegramTriggerPhrase !== originalValues.telegramTriggerPhrase)) ||
(webhookProvider === 'telegram' && telegramBotToken !== originalValues.telegramBotToken) ||
(webhookProvider === 'gmail' &&
(!selectedLabels.every((label) => originalValues.selectedLabels.includes(label)) ||
!originalValues.selectedLabels.every((label) => selectedLabels.includes(label)) ||
@@ -319,7 +312,6 @@ export function WebhookModal({
airtableTableId,
airtableIncludeCellValues,
telegramBotToken,
telegramTriggerPhrase,
selectedLabels,
labelFilterBehavior,
markAsRead,
@@ -345,7 +337,7 @@ export function WebhookModal({
isValid = discordWebhookName.trim() !== ''
break
case 'telegram':
isValid = telegramBotToken.trim() !== '' && telegramTriggerPhrase.trim() !== ''
isValid = telegramBotToken.trim() !== ''
break
case 'gmail':
isValid = selectedLabels.length > 0
@@ -359,7 +351,6 @@ export function WebhookModal({
slackSigningSecret,
whatsappVerificationToken,
telegramBotToken,
telegramTriggerPhrase,
selectedLabels,
])
@@ -428,7 +419,6 @@ export function WebhookModal({
case 'telegram':
return {
botToken: telegramBotToken || undefined,
triggerPhrase: telegramTriggerPhrase || undefined,
}
default:
return {}
@@ -479,7 +469,6 @@ export function WebhookModal({
airtableTableId,
airtableIncludeCellValues,
telegramBotToken,
telegramTriggerPhrase,
selectedLabels,
labelFilterBehavior,
markAsRead,
@@ -713,8 +702,6 @@ export function WebhookModal({
<TelegramConfig
botToken={telegramBotToken}
setBotToken={setTelegramBotToken}
triggerPhrase={telegramTriggerPhrase}
setTriggerPhrase={setTelegramTriggerPhrase}
isLoadingToken={isLoadingToken}
testResult={testResult}
copied={copied}
@@ -83,7 +83,6 @@ export interface AirtableWebhookConfig {
export interface TelegramConfig {
botToken?: string
triggerPhrase?: string
}
// Union type for all provider configurations
@@ -273,12 +272,6 @@ export const WEBHOOK_PROVIDERS: { [key: string]: WebhookProvider } = {
placeholder: 'Enter your Telegram Bot Token',
description: 'The token for your Telegram bot.',
},
triggerPhrase: {
type: 'string',
label: 'Trigger Phrase',
placeholder: '/start_workflow',
description: 'The phrase that will trigger the workflow when sent to the bot.',
},
},
},
}
+137
View File
@@ -258,6 +258,143 @@ export function formatWebhookInput(
}
return null
}
if (foundWebhook.provider === 'telegram') {
// Telegram input formatting logic
const message =
body?.message || body?.edited_message || body?.channel_post || body?.edited_channel_post
if (message) {
// Extract message text with fallbacks for different content types
let input = ''
if (message.text) {
input = message.text
} else if (message.caption) {
input = message.caption
} else if (message.photo) {
input = 'Photo message'
} else if (message.document) {
input = `Document: ${message.document.file_name || 'file'}`
} else if (message.audio) {
input = `Audio: ${message.audio.title || 'audio file'}`
} else if (message.video) {
input = 'Video message'
} else if (message.voice) {
input = 'Voice message'
} else if (message.sticker) {
input = `Sticker: ${message.sticker.emoji || '🎭'}`
} else if (message.location) {
input = 'Location shared'
} else if (message.contact) {
input = `Contact: ${message.contact.first_name || 'contact'}`
} else if (message.poll) {
input = `Poll: ${message.poll.question}`
} else {
input = 'Message received'
}
return {
input, // Primary workflow input - the message content
telegram: {
message: {
id: message.message_id,
text: message.text,
caption: message.caption,
date: message.date,
messageType: message.photo
? 'photo'
: message.document
? 'document'
: message.audio
? 'audio'
: message.video
? 'video'
: message.voice
? 'voice'
: message.sticker
? 'sticker'
: message.location
? 'location'
: message.contact
? 'contact'
: message.poll
? 'poll'
: 'text',
raw: message,
},
sender: message.from
? {
id: message.from.id,
firstName: message.from.first_name,
lastName: message.from.last_name,
username: message.from.username,
languageCode: message.from.language_code,
isBot: message.from.is_bot,
}
: null,
chat: message.chat
? {
id: message.chat.id,
type: message.chat.type,
title: message.chat.title,
username: message.chat.username,
firstName: message.chat.first_name,
lastName: message.chat.last_name,
}
: null,
updateId: body.update_id,
updateType: body.message
? 'message'
: body.edited_message
? 'edited_message'
: body.channel_post
? 'channel_post'
: body.edited_channel_post
? 'edited_channel_post'
: 'unknown',
},
webhook: {
data: {
provider: 'telegram',
path: foundWebhook.path,
providerConfig: foundWebhook.providerConfig,
payload: body,
headers: Object.fromEntries(request.headers.entries()),
method: request.method,
},
},
workflowId: foundWorkflow.id,
}
}
// Fallback for unknown Telegram update types
logger.warn('Unknown Telegram update type', {
updateId: body.update_id,
bodyKeys: Object.keys(body || {}),
})
return {
input: 'Telegram update received',
telegram: {
updateId: body.update_id,
updateType: 'unknown',
raw: body,
},
webhook: {
data: {
provider: 'telegram',
path: foundWebhook.path,
providerConfig: foundWebhook.providerConfig,
payload: body,
headers: Object.fromEntries(request.headers.entries()),
method: request.method,
},
},
workflowId: foundWorkflow.id,
}
}
if (foundWebhook.provider === 'gmail') {
if (body && typeof body === 'object' && 'email' in body) {
return body // { email: {...}, timestamp: ... }