{"record":{"id":"5b8d35397a95cffd","repo":"thedotmack/claude-mem","slug":"failed-to-send-telegram-notification","errorCode":null,"errorMessage":"Failed to send Telegram notification","messagePattern":"Failed to send Telegram notification","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/services/integrations/TelegramNotifier.ts","lineNumber":101,"sourceCode":"    return;\n  }\n\n  const { observations, observationIds, project, memorySessionId } = input;\n  for (let i = 0; i < observations.length; i++) {\n    const obs = observations[i];\n    const matchesType = triggerTypes.includes(obs.type);\n    const matchesConcept = obs.concepts.some(c => triggerConcepts.includes(c));\n    if (!matchesType && !matchesConcept) {\n      continue;\n    }\n\n    const observationId = observationIds[i];\n    try {\n      const text = formatMessage(obs, project, memorySessionId, observationId);\n      await postOne(botToken, chatId, text);\n    } catch (error) {\n      const err = error instanceof Error ? error : new Error(String(error));\n      logger.warn('TELEGRAM', 'Failed to send Telegram notification', {\n        observationId,\n        project,\n        memorySessionId,\n        type: obs.type,\n      }, err);\n    }\n  }\n}\n","sourceCodeStart":83,"sourceCodeEnd":110,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/e2d1df569a8f04075d40e92461128ece7cf04c82/src/services/integrations/TelegramNotifier.ts#L83-L110","documentation":"TelegramNotifier posts one message per matching observation via postOne (Telegram Bot API sendMessage). This warning fires when an individual send fails — network error, 400 for malformed text or a bad chat id, 401 for an invalid bot token, 403 when the bot was never started in the chat, or 429 rate limiting — and the loop continues with remaining observations. One failure never aborts the batch.","triggerScenarios":"await postOne(botToken, chatId, text) throws: invalid or revoked bot token, wrong chatId, message text exceeding Telegram's 4096-character limit, 429 rate limiting during bursts of observations, or no network egress to api.telegram.org.","commonSituations":"Revoked bot token; user never pressed Start in the chat (403 chat not found); corporate firewall blocking Telegram; a long observation blowing the length limit; bursts of observations tripping rate limits.","solutions":["Read the logged error: 401 → fix the bot token; 400/403 → verify chatId and that the bot was started in that chat; 429 → reduce notification frequency.","Truncate or split message text to stay under Telegram's 4096-character limit.","Verify credentials directly: curl 'https://api.telegram.org/bot<TOKEN>/sendMessage?chat_id=<ID>&text=ping'.","Allow egress to api.telegram.org if a firewall or proxy is blocking it."],"exampleFix":"// before: long observations exceed Telegram's 4096-char limit\nawait postOne(botToken, chatId, text);\n// after: clamp the payload before sending\nawait postOne(botToken, chatId, text.slice(0, 4096));","handlingStrategy":"retry","validationCode":"// verify credentials once before enabling Telegram notifications\nconst res = await fetch(`https://api.telegram.org/bot${botToken}/getMe`);\nif (!res.ok) throw new Error(`invalid bot token (HTTP ${res.status})`);\n// then confirm the chat accepts the bot\nconst send = await fetch(`https://api.telegram.org/bot${botToken}/sendMessage?chat_id=${chatId}&text=ping`);","typeGuard":null,"tryCatchPattern":"for (const obs of matching) {\n  try {\n    await postOne(botToken, chatId, clampMessage(formatMessage(obs)));\n  } catch (e) {\n    if ((e as Error).message.includes('429')) {\n      await sleep(retryAfterMs(e) ?? 1000); // honor retry_after, then retry once\n      await postOne(botToken, chatId, clampMessage(formatMessage(obs)));\n    }\n    // other errors: log and continue — never abort the batch\n  }\n}","preventionTips":["Call getMe at startup to fail fast on bad tokens.","Clamp message bodies to 4096 characters before sending.","Honor retry_after on 429 responses and space out bursts of notifications.","Ensure the user pressed Start in the chat before relying on it."],"tags":["telegram","notification","bot-api","integration"],"backgroundTag":"telegram-api-error","analyzedSha":"e2d1df569a8f04075d40e92461128ece7cf04c82","analyzedAt":"2026-08-20T23:58:13.836Z","contentChangedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}