MCPcopy Create free account
hub / github.com/CreminiAI/skillpack / sendWithRetry

Method sendWithRetry

src/runtime/adapters/telegram.ts:273–302  ·  view source on GitHub ↗

* Send a message with automatic retry on 429 (rate limit).

(
    chatId: number,
    text: string,
    maxRetries = 3,
  )

Source from the content-addressed store, hash-verified

271 * Send a message with automatic retry on 429 (rate limit).
272 */
273 private async sendWithRetry(
274 chatId: number,
275 text: string,
276 maxRetries = 3,
277 ): Promise<void> {
278 for (let attempt = 0; attempt <= maxRetries; attempt++) {
279 try {
280 await this.bot!.sendMessage(chatId, formatTelegramMessage(text), {
281 parse_mode: "HTML",
282 });
283 return;
284 } catch (err: any) {
285 if (
286 err?.response?.statusCode === 429 &&
287 attempt < maxRetries
288 ) {
289 const retryAfter =
290 err.response?.body?.parameters?.retry_after || 5;
291 console.log(
292 `[Telegram] Rate limited, retrying after ${retryAfter}s...`,
293 );
294 await new Promise((resolve) =>
295 setTimeout(resolve, retryAfter * 1000),
296 );
297 continue;
298 }
299 throw err;
300 }
301 }
302 }
303
304 /**
305 * Safe send that catches and logs errors.

Callers 2

sendLongMessageMethod · 0.95
sendSafeMethod · 0.95

Calls 2

formatTelegramMessageFunction · 0.85
sendMessageMethod · 0.65

Tested by

no test coverage detected