diff --git a/apps/docs/content/docs/integrations/fathom.mdx b/apps/docs/content/docs/integrations/fathom.mdx index 92ef1a1073f..79747e38a74 100644 --- a/apps/docs/content/docs/integrations/fathom.mdx +++ b/apps/docs/content/docs/integrations/fathom.mdx @@ -265,7 +265,9 @@ Trigger workflow when new meeting content is ready in Fathom | --------- | ---- | ----------- | | `title` | string | Meeting title | | `meeting_title` | string | Calendar event title | +| `meeting_type` | string | Meeting type name, or null when none is assigned | | `recording_id` | number | Unique recording ID | +| `meeting_url` | string | Underlying video call URL \(Zoom, Meet, Teams\), or null | | `url` | string | URL to view the meeting in Fathom | | `share_url` | string | Shareable URL for the meeting | | `created_at` | string | ISO 8601 creation timestamp | @@ -275,9 +277,12 @@ Trigger workflow when new meeting content is ready in Fathom | `recording_end_time` | string | Recording end time | | `transcript_language` | string | Language of the transcript | | `calendar_invitees_domains_type` | string | Domain type: only_internal or one_or_more_external | +| `shared_with` | string | Sharing scope: no_teams, single_team, multiple_teams, or all_teams | | `recorded_by` | object | Recorder details | | ↳ `name` | string | Name of the recorder | | ↳ `email` | string | Email of the recorder | +| ↳ `email_domain` | string | Email domain of the recorder | +| ↳ `team` | string | Recorder team name, or null | | `calendar_invitees` | array | Array of calendar invitees with name and email | | `default_summary` | object | Meeting summary | | ↳ `template_name` | string | Summary template name | @@ -311,7 +316,9 @@ Generic webhook trigger for all Fathom events | --------- | ---- | ----------- | | `title` | string | Meeting title | | `meeting_title` | string | Calendar event title | +| `meeting_type` | string | Meeting type name, or null when none is assigned | | `recording_id` | number | Unique recording ID | +| `meeting_url` | string | Underlying video call URL \(Zoom, Meet, Teams\), or null | | `url` | string | URL to view the meeting in Fathom | | `share_url` | string | Shareable URL for the meeting | | `created_at` | string | ISO 8601 creation timestamp | @@ -321,9 +328,12 @@ Generic webhook trigger for all Fathom events | `recording_end_time` | string | Recording end time | | `transcript_language` | string | Language of the transcript | | `calendar_invitees_domains_type` | string | Domain type: only_internal or one_or_more_external | +| `shared_with` | string | Sharing scope: no_teams, single_team, multiple_teams, or all_teams | | `recorded_by` | object | Recorder details | | ↳ `name` | string | Name of the recorder | | ↳ `email` | string | Email of the recorder | +| ↳ `email_domain` | string | Email domain of the recorder | +| ↳ `team` | string | Recorder team name, or null | | `calendar_invitees` | array | Array of calendar invitees with name and email | | `default_summary` | object | Meeting summary | | ↳ `template_name` | string | Summary template name | diff --git a/apps/docs/content/docs/integrations/fireflies.mdx b/apps/docs/content/docs/integrations/fireflies.mdx index 27cf424f2d7..eaf506513c7 100644 --- a/apps/docs/content/docs/integrations/fireflies.mdx +++ b/apps/docs/content/docs/integrations/fireflies.mdx @@ -303,6 +303,7 @@ Trigger workflow when a Fireflies meeting transcription is complete | `eventType` | string | The type of event \(e.g. Transcription completed, meeting.transcribed\) | | `clientReferenceId` | string | Custom reference ID if set during upload | | `timestamp` | number | Unix timestamp in milliseconds when the event was fired \(V2 webhooks\) | +| `reprocessedAt` | number | Unix timestamp in milliseconds of the transcript or summary change that caused a resend \(V2 webhooks; absent on a meeting's first delivery\) | diff --git a/apps/sim/lib/webhooks/providers/fathom.test.ts b/apps/sim/lib/webhooks/providers/fathom.test.ts new file mode 100644 index 00000000000..efb41a6ae78 --- /dev/null +++ b/apps/sim/lib/webhooks/providers/fathom.test.ts @@ -0,0 +1,117 @@ +import crypto from 'node:crypto' +import { NextRequest } from 'next/server' +import { beforeEach, describe, expect, it, vi } from 'vitest' +import { fathomHandler } from '@/lib/webhooks/providers/fathom' + +const SECRET_BYTES = Buffer.from('fathom-test-secret-key-padding!!!!!!') +const SIGNING_SECRET = `whsec_${SECRET_BYTES.toString('base64')}` + +function sign(msgId: string, timestamp: string, rawBody: string): string { + const sig = crypto + .createHmac('sha256', SECRET_BYTES) + .update(`${msgId}.${timestamp}.${rawBody}`, 'utf8') + .digest('base64') + return `v1,${sig}` +} + +function request(msgId: string, timestamp: string, signature: string): NextRequest { + return new NextRequest('http://localhost/test', { + headers: { + 'webhook-id': msgId, + 'webhook-timestamp': timestamp, + 'webhook-signature': signature, + }, + }) +} + +const nowSeconds = () => `${Math.floor(Date.now() / 1000)}` +const rawBody = JSON.stringify({ title: 'QBR', recording_id: 123 }) + +describe('Fathom webhook provider verifyAuth', () => { + it('rejects a forged delivery when the webhook has a signing secret', async () => { + const res = await fathomHandler.verifyAuth?.({ + webhook: {}, + workflow: {}, + request: request('msg_1', nowSeconds(), 'v1,Zm9yZ2Vk'), + rawBody, + requestId: 'fathom-t1', + providerConfig: { signingSecret: SIGNING_SECRET }, + }) + + expect(res?.status).toBe(401) + }) + + it('accepts a correctly signed delivery', async () => { + const ts = nowSeconds() + const res = await fathomHandler.verifyAuth?.({ + webhook: {}, + workflow: {}, + request: request('msg_1', ts, sign('msg_1', ts, rawBody)), + rawBody, + requestId: 'fathom-t2', + providerConfig: { signingSecret: SIGNING_SECRET }, + }) + + expect(res).toBeNull() + }) + + it('keeps accepting webhooks registered before the secret was stored', async () => { + const res = await fathomHandler.verifyAuth?.({ + webhook: {}, + workflow: {}, + request: request('msg_1', nowSeconds(), 'v1,Zm9yZ2Vk'), + rawBody, + requestId: 'fathom-t3', + providerConfig: {}, + }) + + expect(res ?? null).toBeNull() + }) +}) + +describe('Fathom webhook provider createSubscription', () => { + const fetchMock = vi.fn() + + beforeEach(() => { + fetchMock.mockReset() + vi.stubGlobal('fetch', fetchMock) + }) + + it('stores the signing secret Fathom returns', async () => { + fetchMock.mockResolvedValueOnce({ + ok: true, + status: 201, + json: async () => ({ id: 'ikEoQ4bVoq4JYUmc', secret: SIGNING_SECRET }), + }) + + const result = await fathomHandler.createSubscription?.({ + webhook: { id: 'wh_1', path: 'p1', providerConfig: { apiKey: 'fathom_key' } }, + requestId: 'fathom-sub1', + } as never) + + expect(result?.providerConfigUpdates).toEqual({ + externalId: 'ikEoQ4bVoq4JYUmc', + signingSecret: SIGNING_SECRET, + }) + }) + + it('deletes the webhook and fails when the response omits the signing secret', async () => { + fetchMock.mockResolvedValueOnce({ + ok: true, + status: 201, + json: async () => ({ id: 'ikEoQ4bVoq4JYUmc' }), + }) + fetchMock.mockResolvedValueOnce({ ok: true, status: 204 }) + + await expect( + fathomHandler.createSubscription?.({ + webhook: { id: 'wh_2', path: 'p2', providerConfig: { apiKey: 'fathom_key' } }, + requestId: 'fathom-sub2', + } as never) + ).rejects.toThrow(/signing secret/) + + const [url, init] = fetchMock.mock.calls[1] + expect(init.method).toBe('DELETE') + expect(url).toBe('https://api.fathom.ai/external/v1/webhooks/ikEoQ4bVoq4JYUmc') + }) +}) diff --git a/apps/sim/lib/webhooks/providers/fathom.ts b/apps/sim/lib/webhooks/providers/fathom.ts index e927b4d8fc2..92d944ea8a0 100644 --- a/apps/sim/lib/webhooks/providers/fathom.ts +++ b/apps/sim/lib/webhooks/providers/fathom.ts @@ -1,18 +1,65 @@ import { createLogger } from '@sim/logger' +import type { NextResponse } from 'next/server' import { outboundFetch } from '@/lib/core/network/outbound-fetch.server' import { validateAlphanumericId } from '@/lib/core/security/input-validation' import { getNotificationUrl, getProviderConfig } from '@/lib/webhooks/provider-subscription-utils' import { WebhookDeploymentConfigurationError } from '@/lib/webhooks/providers/errors' import type { + AuthContext, DeleteSubscriptionContext, SubscriptionContext, SubscriptionResult, WebhookProviderHandler, } from '@/lib/webhooks/providers/types' +import { verifyStandardWebhookRequest } from '@/lib/webhooks/providers/utils' const logger = createLogger('WebhookProvider:Fathom') +/** Best-effort removal of a webhook Sim registered but cannot keep, so it does not keep firing. */ +async function deleteOrphanedFathomWebhook( + apiKey: string, + fathomWebhookId: string, + requestId: string +): Promise { + if (!validateAlphanumericId(fathomWebhookId, 'Fathom webhook ID', 100).isValid) return + try { + const response = await outboundFetch( + `https://api.fathom.ai/external/v1/webhooks/${fathomWebhookId}`, + { method: 'DELETE', headers: { 'X-Api-Key': apiKey } } + ) + if (!response.ok && response.status !== 404) { + logger.warn('Failed to remove orphaned Fathom webhook; it may still be active', { + requestId, + status: response.status, + }) + } + } catch (error) { + logger.warn('Failed to remove orphaned Fathom webhook; it may still be active', error, { + requestId, + }) + } +} + export const fathomHandler: WebhookProviderHandler = { + /** + * Fathom signs deliveries with the Standard Webhooks scheme using the secret + * returned when Sim registers the webhook. Rows registered before Sim stored + * that secret have none and keep being accepted until the trigger's settings + * change or it is re-created, which registers a new webhook and stores its secret. + */ + verifyAuth({ request, rawBody, requestId, providerConfig }: AuthContext): NextResponse | null { + const signingSecret = providerConfig.signingSecret as string | undefined + if (!signingSecret?.trim()) return null + + return verifyStandardWebhookRequest({ + request, + rawBody, + requestId, + secret: signingSecret, + providerLabel: 'Fathom', + }) + }, + async createSubscription(ctx: SubscriptionContext): Promise { const { webhook, requestId } = ctx try { @@ -109,7 +156,20 @@ export const fathomHandler: WebhookProviderHandler = { fathomWebhookId: responseBody.id, }) - return { providerConfigUpdates: { externalId: responseBody.id } } + const signingSecret = + typeof responseBody.secret === 'string' ? responseBody.secret.trim() : '' + if (!signingSecret) { + logger.error('Fathom webhook creation returned no signing secret', { + requestId, + webhookId: webhook.id, + }) + await deleteOrphanedFathomWebhook(apiKey, String(responseBody.id), requestId) + throw new Error( + 'Fathom created the webhook but did not return a signing secret, so deliveries could not be verified. Please try again.' + ) + } + + return { providerConfigUpdates: { externalId: responseBody.id, signingSecret } } } catch (error: unknown) { if (error instanceof WebhookDeploymentConfigurationError) throw error const err = error as Error diff --git a/apps/sim/lib/webhooks/providers/fireflies.ts b/apps/sim/lib/webhooks/providers/fireflies.ts index e7e67da0599..ee13f09c34f 100644 --- a/apps/sim/lib/webhooks/providers/fireflies.ts +++ b/apps/sim/lib/webhooks/providers/fireflies.ts @@ -55,6 +55,10 @@ export const firefliesHandler: WebhookProviderHandler = { const clientReferenceId = ((isV2 ? b.client_reference_id : b.clientReferenceId) || '') as string const rawTimestamp = b.timestamp != null ? Number(b.timestamp) : null const timestamp = rawTimestamp !== null && Number.isFinite(rawTimestamp) ? rawTimestamp : null + const reprocessedAt = + isV2 && typeof b.reprocessed_at === 'number' && Number.isFinite(b.reprocessed_at) + ? b.reprocessed_at + : null return { input: { @@ -62,6 +66,7 @@ export const firefliesHandler: WebhookProviderHandler = { eventType, clientReferenceId, ...(timestamp !== null ? { timestamp } : {}), + ...(reprocessedAt !== null ? { reprocessedAt } : {}), }, } }, diff --git a/apps/sim/tools/grain/delete_hook.ts b/apps/sim/tools/grain/delete_hook.ts index 1d97272af35..46a453f7cc4 100644 --- a/apps/sim/tools/grain/delete_hook.ts +++ b/apps/sim/tools/grain/delete_hook.ts @@ -1,5 +1,6 @@ import type { GrainDeleteHookParams, GrainDeleteHookResponse } from '@/tools/grain/types' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const grainDeleteHookTool: ToolConfig = { id: 'grain_delete_hook', @@ -23,7 +24,8 @@ export const grainDeleteHookTool: ToolConfig `https://api.grain.com/_/public-api/hooks/${params.hookId}`, + url: (params) => + `https://api.grain.com/_/public-api/hooks/${safeUrlPathSegment(params.hookId, 'hookId')}`, method: 'DELETE', headers: (params) => ({ 'Content-Type': 'application/json', diff --git a/apps/sim/tools/grain/delete_hook_v2.ts b/apps/sim/tools/grain/delete_hook_v2.ts index 8ee8ae82c7b..76a0f960c80 100644 --- a/apps/sim/tools/grain/delete_hook_v2.ts +++ b/apps/sim/tools/grain/delete_hook_v2.ts @@ -1,6 +1,7 @@ import type { GrainDeleteHookV2Params, GrainDeleteHookV2Response } from '@/tools/grain/types' import { GRAIN_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const grainDeleteHookV2Tool: ToolConfig = { @@ -26,7 +27,8 @@ export const grainDeleteHookV2Tool: ToolConfig `https://api.grain.com/_/public-api/v2/hooks/${params.hookId.trim()}`, + url: (params) => + `https://api.grain.com/_/public-api/v2/hooks/${safeUrlPathSegment(params.hookId, 'hookId')}`, method: 'DELETE', headers: (params) => ({ 'Content-Type': 'application/json', diff --git a/apps/sim/tools/grain/get_recording.ts b/apps/sim/tools/grain/get_recording.ts index 524ff15a64d..da6d23b838d 100644 --- a/apps/sim/tools/grain/get_recording.ts +++ b/apps/sim/tools/grain/get_recording.ts @@ -1,6 +1,7 @@ import type { GrainGetRecordingParams, GrainGetRecordingResponse } from '@/tools/grain/types' import { GRAIN_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const grainGetRecordingTool: ToolConfig = { @@ -63,7 +64,7 @@ export const grainGetRecordingTool: ToolConfig - `https://api.grain.com/_/public-api/v2/recordings/${params.recordingId.trim()}`, + `https://api.grain.com/_/public-api/v2/recordings/${safeUrlPathSegment(params.recordingId, 'recordingId')}`, method: 'POST', headers: (params) => ({ 'Content-Type': 'application/json', diff --git a/apps/sim/tools/grain/get_transcript.ts b/apps/sim/tools/grain/get_transcript.ts index c29cee86cc9..9faac2011a4 100644 --- a/apps/sim/tools/grain/get_transcript.ts +++ b/apps/sim/tools/grain/get_transcript.ts @@ -1,6 +1,7 @@ import type { GrainGetTranscriptParams, GrainGetTranscriptResponse } from '@/tools/grain/types' import { GRAIN_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const grainGetTranscriptTool: ToolConfig< GrainGetTranscriptParams, @@ -29,7 +30,7 @@ export const grainGetTranscriptTool: ToolConfig< request: { url: (params) => - `https://api.grain.com/_/public-api/v2/recordings/${params.recordingId.trim()}/transcript`, + `https://api.grain.com/_/public-api/v2/recordings/${safeUrlPathSegment(params.recordingId, 'recordingId')}/transcript`, method: 'GET', headers: (params) => ({ 'Content-Type': 'application/json', diff --git a/apps/sim/tools/obsidian/patch_active.ts b/apps/sim/tools/obsidian/patch_active.ts index ae72a71218b..9c04a9d9da3 100644 --- a/apps/sim/tools/obsidian/patch_active.ts +++ b/apps/sim/tools/obsidian/patch_active.ts @@ -70,6 +70,7 @@ export const patchActiveTool: ToolConfig = { Authorization: `Bearer ${params.apiKey}`, 'Content-Type': 'text/markdown', + 'Markdown-Patch-Version': '1', Operation: params.operation, 'Target-Type': params.targetType, Target: encodeURIComponent(params.target), diff --git a/apps/sim/tools/obsidian/patch_note.ts b/apps/sim/tools/obsidian/patch_note.ts index 12013d8b77f..a2cebc4ccb6 100644 --- a/apps/sim/tools/obsidian/patch_note.ts +++ b/apps/sim/tools/obsidian/patch_note.ts @@ -76,6 +76,7 @@ export const patchNoteTool: ToolConfig = { Authorization: `Bearer ${params.apiKey}`, 'Content-Type': 'text/markdown', + 'Markdown-Patch-Version': '1', Operation: params.operation, 'Target-Type': params.targetType, Target: encodeURIComponent(params.target), diff --git a/apps/sim/triggers/fathom/utils.test.ts b/apps/sim/triggers/fathom/utils.test.ts new file mode 100644 index 00000000000..9814a2a6c90 --- /dev/null +++ b/apps/sim/triggers/fathom/utils.test.ts @@ -0,0 +1,18 @@ +import { describe, expect, it } from 'vitest' +import type { OutputSchema } from '@/executor/utils/block-reference' +import { isPathInSchema } from '@/executor/utils/block-reference' +import { buildMeetingOutputs } from '@/triggers/fathom/utils' + +describe('Fathom meeting trigger outputs', () => { + const schema = buildMeetingOutputs() as unknown as OutputSchema + + it('resolves the documented recorder and summary fields', () => { + expect(isPathInSchema(schema, ['recorded_by', 'team'])).toBe(true) + expect(isPathInSchema(schema, ['default_summary', 'markdown_formatted'])).toBe(true) + }) + + it('keeps accepting sub-paths saved before the fields were declared', () => { + expect(isPathInSchema(schema, ['recorded_by', 'id'])).toBe(true) + expect(isPathInSchema(schema, ['default_summary', 'sections'])).toBe(true) + }) +}) diff --git a/apps/sim/triggers/fathom/utils.ts b/apps/sim/triggers/fathom/utils.ts index b8b6bf750f4..6b9e949d618 100644 --- a/apps/sim/triggers/fathom/utils.ts +++ b/apps/sim/triggers/fathom/utils.ts @@ -42,10 +42,18 @@ export function buildMeetingOutputs(): Record { type: 'string', description: 'Calendar event title', }, + meeting_type: { + type: 'string', + description: 'Meeting type name, or null when none is assigned', + }, recording_id: { type: 'number', description: 'Unique recording ID', }, + meeting_url: { + type: 'string', + description: 'Underlying video call URL (Zoom, Meet, Teams), or null', + }, url: { type: 'string', description: 'URL to view the meeting in Fathom', @@ -82,11 +90,20 @@ export function buildMeetingOutputs(): Record { type: 'string', description: 'Domain type: only_internal or one_or_more_external', }, + shared_with: { + type: 'string', + description: 'Sharing scope: no_teams, single_team, multiple_teams, or all_teams', + }, recorded_by: { type: 'object', description: 'Recorder details', - name: { type: 'string', description: 'Name of the recorder' }, - email: { type: 'string', description: 'Email of the recorder' }, + open: true, + properties: { + name: { type: 'string', description: 'Name of the recorder' }, + email: { type: 'string', description: 'Email of the recorder' }, + email_domain: { type: 'string', description: 'Email domain of the recorder' }, + team: { type: 'string', description: 'Recorder team name, or null' }, + }, }, calendar_invitees: { type: 'array', @@ -95,8 +112,11 @@ export function buildMeetingOutputs(): Record { default_summary: { type: 'object', description: 'Meeting summary', - template_name: { type: 'string', description: 'Summary template name' }, - markdown_formatted: { type: 'string', description: 'Markdown-formatted summary' }, + open: true, + properties: { + template_name: { type: 'string', description: 'Summary template name' }, + markdown_formatted: { type: 'string', description: 'Markdown-formatted summary' }, + }, }, transcript: { type: 'array', diff --git a/apps/sim/triggers/fireflies/transcription_complete.ts b/apps/sim/triggers/fireflies/transcription_complete.ts index 49d3e1fe52a..f8dce4cb10c 100644 --- a/apps/sim/triggers/fireflies/transcription_complete.ts +++ b/apps/sim/triggers/fireflies/transcription_complete.ts @@ -69,6 +69,11 @@ export const firefliesTranscriptionCompleteTrigger: TriggerConfig = { type: 'number', description: 'Unix timestamp in milliseconds when the event was fired (V2 webhooks)', }, + reprocessedAt: { + type: 'number', + description: + "Unix timestamp in milliseconds of the transcript or summary change that caused a resend (V2 webhooks; absent on a meeting's first delivery)", + }, }, webhook: {