(ctx: SubscriptionContext)
| 12 | |
| 13 | export const fathomHandler: WebhookProviderHandler = { |
| 14 | async createSubscription(ctx: SubscriptionContext): Promise<SubscriptionResult | undefined> { |
| 15 | const { webhook, requestId } = ctx |
| 16 | try { |
| 17 | const providerConfig = getProviderConfig(webhook) |
| 18 | const apiKey = providerConfig.apiKey as string | undefined |
| 19 | const triggerId = providerConfig.triggerId as string | undefined |
| 20 | const triggeredFor = providerConfig.triggeredFor as string | undefined |
| 21 | const includeSummary = providerConfig.includeSummary as unknown |
| 22 | const includeTranscript = providerConfig.includeTranscript as unknown |
| 23 | const includeActionItems = providerConfig.includeActionItems as unknown |
| 24 | const includeCrmMatches = providerConfig.includeCrmMatches as unknown |
| 25 | |
| 26 | if (!apiKey) { |
| 27 | logger.warn(`[${requestId}] Missing apiKey for Fathom webhook creation.`, { |
| 28 | webhookId: webhook.id, |
| 29 | }) |
| 30 | throw new Error( |
| 31 | 'Fathom API Key is required. Please provide your API key in the trigger configuration.' |
| 32 | ) |
| 33 | } |
| 34 | |
| 35 | const notificationUrl = getNotificationUrl(webhook) |
| 36 | |
| 37 | const triggeredForValue = triggeredFor || 'my_recordings' |
| 38 | |
| 39 | const toBool = (val: unknown, fallback: boolean): boolean => { |
| 40 | if (val === undefined) return fallback |
| 41 | return val === true || val === 'true' |
| 42 | } |
| 43 | |
| 44 | const requestBody: Record<string, unknown> = { |
| 45 | destination_url: notificationUrl, |
| 46 | triggered_for: [triggeredForValue], |
| 47 | include_summary: toBool(includeSummary, true), |
| 48 | include_transcript: toBool(includeTranscript, false), |
| 49 | include_action_items: toBool(includeActionItems, false), |
| 50 | include_crm_matches: toBool(includeCrmMatches, false), |
| 51 | } |
| 52 | |
| 53 | logger.info(`[${requestId}] Creating Fathom webhook`, { |
| 54 | triggerId, |
| 55 | triggeredFor: triggeredForValue, |
| 56 | webhookId: webhook.id, |
| 57 | }) |
| 58 | |
| 59 | const fathomResponse = await fetch('https://api.fathom.ai/external/v1/webhooks', { |
| 60 | method: 'POST', |
| 61 | headers: { |
| 62 | 'X-Api-Key': apiKey, |
| 63 | 'Content-Type': 'application/json', |
| 64 | }, |
| 65 | body: JSON.stringify(requestBody), |
| 66 | }) |
| 67 | |
| 68 | const responseBody = (await fathomResponse.json().catch(() => ({}))) as Record< |
| 69 | string, |
| 70 | unknown |
| 71 | > |
nothing calls this directly
no test coverage detected