{"record":{"id":"4d0fda387b240ef3","repo":"diegosouzapw/OmniRoute","slug":"invalid-telegram-bot-token-format-expected-id","errorCode":null,"errorMessage":"Invalid Telegram bot token format (expected <id>:<secret>)","messagePattern":"Invalid Telegram bot token format \\(expected <id>:<secret>\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/webhooks/integrations/telegram.ts","lineNumber":22,"sourceCode":"\nexport interface TelegramSendMessagePayload {\n  chat_id: string;\n  text: string;\n  parse_mode: \"Markdown\";\n}\n\nfunction escapeMd(s: string): string {\n  // Escape Telegram Markdown v1 special chars: _ * [ ] `\n  // Hyphens and parentheses are safe in Markdown v1\n  return s.replace(/[_*[\\]`]/g, (c) => `\\\\${c}`);\n}\n\n// Telegram bot token format: <numeric_id>:<alphanumeric_secret> (min 35 chars after colon)\nconst BOT_TOKEN_RE = /^\\d+:[A-Za-z0-9_-]{35,}$/;\n\nexport function buildTelegramUrl(botToken: string): string {\n  if (!BOT_TOKEN_RE.test(botToken)) {\n    throw new Error(\"Invalid Telegram bot token format (expected <id>:<secret>)\");\n  }\n  return `https://api.telegram.org/bot${botToken}/sendMessage`;\n}\n\nexport function buildTelegramPayload(\n  event: WebhookEvent,\n  data: Record<string, unknown>,\n  chatId: string\n): TelegramSendMessagePayload {\n  const desc = EVENT_DESCRIPTIONS[event];\n  const model = typeof data.model === \"string\" ? escapeMd(data.model) : null;\n  const error = typeof data.error === \"string\" ? escapeMd(data.error) : null;\n  const provider = typeof data.provider === \"string\" ? escapeMd(data.provider) : null;\n  const combo = typeof data.combo === \"string\" ? escapeMd(data.combo) : null;\n  const account =\n    typeof data.account === \"string\" && data.account.trim().length > 0\n      ? escapeMd(data.account)\n      : null;","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/webhooks/integrations/telegram.ts#L4-L40","documentation":"Format guard in buildTelegramUrl: the bot token failed the BOT_TOKEN_RE regex (^\\d+:[A-Za-z0-9_-]{35,}$) — Telegram tokens are <numeric_id>:<secret> with at least 35 secret chars. Means the stored/entered token is malformed (wrong paste, truncated, or a Bot API revocation string), so no API URL can be built for it. The token value at fault is the integration's configured botToken.","triggerScenarios":"Thrown at src/lib/webhooks/integrations/telegram.ts:22 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-copy the token from @BotFather and re-save the Telegram integration settings","Check for leading/trailing whitespace or a truncated paste","Verify the token has the <id>:<secret> shape before saving"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}