({
webhook,
workflow,
requestId,
strict,
}: DeleteSubscriptionContext)
| 709 | }, |
| 710 | |
| 711 | async deleteSubscription({ |
| 712 | webhook, |
| 713 | workflow, |
| 714 | requestId, |
| 715 | strict, |
| 716 | }: DeleteSubscriptionContext): Promise<void> { |
| 717 | try { |
| 718 | const config = getProviderConfig(webhook) |
| 719 | |
| 720 | if (config.triggerId !== 'microsoftteams_chat_subscription') { |
| 721 | return |
| 722 | } |
| 723 | |
| 724 | const externalSubscriptionId = config.externalSubscriptionId as string | undefined |
| 725 | const credentialId = config.credentialId as string | undefined |
| 726 | |
| 727 | if (!externalSubscriptionId || !credentialId) { |
| 728 | logger.info(`[${requestId}] No external subscription to delete for webhook ${webhook.id}`) |
| 729 | if (strict) throw new Error('Missing Teams subscription cleanup configuration') |
| 730 | return |
| 731 | } |
| 732 | |
| 733 | const credentialOwner = await getCredentialOwner(credentialId, requestId) |
| 734 | const accessToken = credentialOwner |
| 735 | ? await refreshAccessTokenIfNeeded( |
| 736 | credentialOwner.accountId, |
| 737 | credentialOwner.userId, |
| 738 | requestId |
| 739 | ) |
| 740 | : null |
| 741 | if (!accessToken) { |
| 742 | logger.warn( |
| 743 | `[${requestId}] Could not get access token to delete Teams subscription for webhook ${webhook.id}` |
| 744 | ) |
| 745 | if (strict) throw new Error('Missing Teams access token for subscription deletion') |
| 746 | return |
| 747 | } |
| 748 | |
| 749 | const res = await fetch( |
| 750 | `https://graph.microsoft.com/v1.0/subscriptions/${externalSubscriptionId}`, |
| 751 | { |
| 752 | method: 'DELETE', |
| 753 | headers: { Authorization: `Bearer ${accessToken}` }, |
| 754 | } |
| 755 | ) |
| 756 | |
| 757 | if (res.ok || res.status === 404) { |
| 758 | logger.info( |
| 759 | `[${requestId}] Successfully deleted Teams subscription ${externalSubscriptionId} for webhook ${webhook.id}` |
| 760 | ) |
| 761 | } else { |
| 762 | const errorBody = await res.text() |
| 763 | logger.warn( |
| 764 | `[${requestId}] Failed to delete Teams subscription ${externalSubscriptionId} for webhook ${webhook.id}. Status: ${res.status}` |
| 765 | ) |
| 766 | if (strict) throw new Error(`Failed to delete Teams subscription: ${res.status}`) |
| 767 | } |
| 768 | } catch (error) { |
nothing calls this directly
no test coverage detected