(ctx: DeleteSubscriptionContext)
| 178 | }, |
| 179 | |
| 180 | async deleteSubscription(ctx: DeleteSubscriptionContext): Promise<void> { |
| 181 | try { |
| 182 | const config = getProviderConfig(ctx.webhook) |
| 183 | const botToken = config.botToken as string | undefined |
| 184 | |
| 185 | if (!botToken) { |
| 186 | logger.warn( |
| 187 | `[${ctx.requestId}] Missing botToken for Telegram webhook deletion ${ctx.webhook.id}` |
| 188 | ) |
| 189 | if (ctx.strict) throw new Error('Missing Telegram botToken for webhook deletion') |
| 190 | return |
| 191 | } |
| 192 | |
| 193 | if (await activeTelegramWebhookUsesBot(ctx.webhook, botToken)) { |
| 194 | logger.info( |
| 195 | `[${ctx.requestId}] Skipping Telegram webhook deletion because an active deployment uses the same bot token`, |
| 196 | { webhookId: ctx.webhook.id } |
| 197 | ) |
| 198 | return |
| 199 | } |
| 200 | |
| 201 | const telegramApiUrl = `https://api.telegram.org/bot${botToken}/deleteWebhook` |
| 202 | const telegramResponse = await fetch(telegramApiUrl, { |
| 203 | method: 'POST', |
| 204 | headers: { 'Content-Type': 'application/json' }, |
| 205 | }) |
| 206 | |
| 207 | const responseBody = await telegramResponse.json() |
| 208 | if (!telegramResponse.ok || !responseBody.ok) { |
| 209 | const errorMessage = |
| 210 | responseBody.description || |
| 211 | `Failed to delete Telegram webhook. Status: ${telegramResponse.status}` |
| 212 | logger.error(`[${ctx.requestId}] ${errorMessage}`, { response: responseBody }) |
| 213 | if (ctx.strict) throw new Error(errorMessage) |
| 214 | } else { |
| 215 | logger.info( |
| 216 | `[${ctx.requestId}] Successfully deleted Telegram webhook for webhook ${ctx.webhook.id}` |
| 217 | ) |
| 218 | } |
| 219 | } catch (error) { |
| 220 | logger.error( |
| 221 | `[${ctx.requestId}] Error deleting Telegram webhook for webhook ${ctx.webhook.id}`, |
| 222 | error |
| 223 | ) |
| 224 | if (ctx.strict) throw error |
| 225 | } |
| 226 | }, |
| 227 | } |
| 228 | |
| 229 | async function activeTelegramWebhookUsesBot( |
nothing calls this directly
no test coverage detected