MCPcopy Index your code
hub / github.com/simstudioai/sim / deleteSubscription

Function deleteSubscription

apps/sim/lib/webhooks/providers/telegram.ts:180–226  ·  view source on GitHub ↗
(ctx: DeleteSubscriptionContext)

Source from the content-addressed store, hash-verified

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
229async function activeTelegramWebhookUsesBot(

Callers

nothing calls this directly

Calls 5

getProviderConfigFunction · 0.90
infoMethod · 0.80
errorMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected