kaneo (minimalist kanban) fork to experiment adding a tangled integration github.com/usekaneo/kaneo
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at cd7cada2f86b4e866a15b4323bb8d6d7ab5bba8b 57 lines 1.4 kB view raw
1type TelegramMessage = { 2 chat_id: string; 3 text: string; 4 parse_mode?: "HTML"; 5 disable_web_page_preview?: boolean; 6 message_thread_id?: number; 7}; 8 9const TELEGRAM_TIMEOUT_MS = 10_000; 10 11export async function postToTelegram( 12 botToken: string, 13 message: TelegramMessage, 14): Promise<void> { 15 const controller = new AbortController(); 16 const timeoutId = setTimeout(() => controller.abort(), TELEGRAM_TIMEOUT_MS); 17 18 try { 19 const response = await fetch( 20 `https://api.telegram.org/bot${botToken}/sendMessage`, 21 { 22 method: "POST", 23 headers: { 24 "Content-Type": "application/json", 25 }, 26 body: JSON.stringify(message), 27 signal: controller.signal, 28 }, 29 ); 30 31 if (!response.ok) { 32 const errorText = await response.text(); 33 throw new Error( 34 `Telegram request failed (${response.status}): ${errorText}`, 35 ); 36 } 37 38 const result = (await response.json()) as { 39 ok?: boolean; 40 description?: string; 41 }; 42 43 if (!result.ok) { 44 throw new Error(result.description || "Telegram API request failed"); 45 } 46 } catch (error) { 47 if (error instanceof Error && error.name === "AbortError") { 48 throw new Error( 49 `Telegram request timed out after ${TELEGRAM_TIMEOUT_MS}ms`, 50 ); 51 } 52 53 throw error; 54 } finally { 55 clearTimeout(timeoutId); 56 } 57}