Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/docs/content/docs/integrations/fathom.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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 |
Expand Down Expand Up @@ -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 |
Expand All @@ -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 |
Expand Down
1 change: 1 addition & 0 deletions apps/docs/content/docs/integrations/fireflies.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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\) |

</ReferenceDetails>

117 changes: 117 additions & 0 deletions apps/sim/lib/webhooks/providers/fathom.test.ts
Original file line number Diff line number Diff line change
@@ -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')
})
})
62 changes: 61 additions & 1 deletion apps/sim/lib/webhooks/providers/fathom.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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<SubscriptionResult | undefined> {
const { webhook, requestId } = ctx
try {
Expand Down Expand Up @@ -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 } }
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
} catch (error: unknown) {
if (error instanceof WebhookDeploymentConfigurationError) throw error
const err = error as Error
Expand Down
5 changes: 5 additions & 0 deletions apps/sim/lib/webhooks/providers/fireflies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,18 @@ 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: {
meetingId,
eventType,
clientReferenceId,
...(timestamp !== null ? { timestamp } : {}),
...(reprocessedAt !== null ? { reprocessedAt } : {}),
},
}
},
Expand Down
4 changes: 3 additions & 1 deletion apps/sim/tools/grain/delete_hook.ts
Original file line number Diff line number Diff line change
@@ -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<GrainDeleteHookParams, GrainDeleteHookResponse> = {
id: 'grain_delete_hook',
Expand All @@ -23,7 +24,8 @@ export const grainDeleteHookTool: ToolConfig<GrainDeleteHookParams, GrainDeleteH
},

request: {
url: (params) => `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',
Expand Down
4 changes: 3 additions & 1 deletion apps/sim/tools/grain/delete_hook_v2.ts
Original file line number Diff line number Diff line change
@@ -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<GrainDeleteHookV2Params, GrainDeleteHookV2Response> =
{
Expand All @@ -26,7 +27,8 @@ export const grainDeleteHookV2Tool: ToolConfig<GrainDeleteHookV2Params, GrainDel
},

request: {
url: (params) => `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',
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/grain/get_recording.ts
Original file line number Diff line number Diff line change
@@ -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<GrainGetRecordingParams, GrainGetRecordingResponse> =
{
Expand Down Expand Up @@ -63,7 +64,7 @@ export const grainGetRecordingTool: ToolConfig<GrainGetRecordingParams, GrainGet

request: {
url: (params) =>
`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',
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/grain/get_transcript.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions apps/sim/tools/obsidian/patch_active.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const patchActiveTool: ToolConfig<ObsidianPatchActiveParams, ObsidianPatc
const headers: Record<string, string> = {
Authorization: `Bearer ${params.apiKey}`,
'Content-Type': 'text/markdown',
'Markdown-Patch-Version': '1',
Operation: params.operation,
'Target-Type': params.targetType,
Target: encodeURIComponent(params.target),
Expand Down
1 change: 1 addition & 0 deletions apps/sim/tools/obsidian/patch_note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const patchNoteTool: ToolConfig<ObsidianPatchNoteParams, ObsidianPatchNot
const headers: Record<string, string> = {
Authorization: `Bearer ${params.apiKey}`,
'Content-Type': 'text/markdown',
'Markdown-Patch-Version': '1',
Operation: params.operation,
'Target-Type': params.targetType,
Target: encodeURIComponent(params.target),
Expand Down
18 changes: 18 additions & 0 deletions apps/sim/triggers/fathom/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
Loading
Loading