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
50 changes: 48 additions & 2 deletions apps/sim/app/(landing)/integrations/data/integrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -8138,8 +8138,54 @@
"docsUrl": "https://docs.sim.ai/tools/notion",
"operations": [],
"operationCount": 0,
"triggers": [],
"triggerCount": 0,
"triggers": [
{
"id": "notion_page_created",
"name": "Notion Page Created",
"description": "Trigger workflow when a new page is created in Notion"
},
{
"id": "notion_page_properties_updated",
"name": "Notion Page Properties Updated",
"description": "Trigger workflow when page properties are modified in Notion"
},
{
"id": "notion_page_content_updated",
"name": "Notion Page Content Updated",
"description": "Trigger workflow when page content is changed in Notion"
},
{
"id": "notion_page_deleted",
"name": "Notion Page Deleted",
"description": "Trigger workflow when a page is deleted in Notion"
},
{
"id": "notion_database_created",
"name": "Notion Database Created",
"description": "Trigger workflow when a new database is created in Notion"
},
{
"id": "notion_database_schema_updated",
"name": "Notion Database Schema Updated",
"description": "Trigger workflow when a database schema is modified in Notion"
},
{
"id": "notion_database_deleted",
"name": "Notion Database Deleted",
"description": "Trigger workflow when a database is deleted in Notion"
},
{
"id": "notion_comment_created",
"name": "Notion Comment Created",
"description": "Trigger workflow when a comment or suggested edit is added in Notion"
},
{
"id": "notion_webhook",
"name": "Notion Webhook (All Events)",
"description": "Trigger workflow on any Notion webhook event"
}
],
"triggerCount": 9,
"authType": "oauth",
"category": "tools",
"integrationType": "documents",
Expand Down
30 changes: 29 additions & 1 deletion apps/sim/blocks/blocks/notion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { BlockConfig } from '@/blocks/types'
import { AuthMode, IntegrationType } from '@/blocks/types'
import { createVersionedToolSelector } from '@/blocks/utils'
import type { NotionResponse } from '@/tools/notion/types'
import { getTrigger } from '@/triggers'

// Legacy block - hidden from toolbar
export const NotionBlock: BlockConfig<NotionResponse> = {
Expand Down Expand Up @@ -436,7 +437,34 @@ export const NotionV2Block: BlockConfig<any> = {
bgColor: '#181C1E',
icon: NotionIcon,
hideFromToolbar: false,
subBlocks: NotionBlock.subBlocks,
subBlocks: [
...NotionBlock.subBlocks,

// Trigger subBlocks
...getTrigger('notion_page_created').subBlocks,
...getTrigger('notion_page_properties_updated').subBlocks,
...getTrigger('notion_page_content_updated').subBlocks,
...getTrigger('notion_page_deleted').subBlocks,
...getTrigger('notion_database_created').subBlocks,
...getTrigger('notion_database_schema_updated').subBlocks,
...getTrigger('notion_database_deleted').subBlocks,
...getTrigger('notion_comment_created').subBlocks,
...getTrigger('notion_webhook').subBlocks,
],
triggers: {
enabled: true,
available: [
'notion_page_created',
'notion_page_properties_updated',
'notion_page_content_updated',
'notion_page_deleted',
'notion_database_created',
'notion_database_schema_updated',
'notion_database_deleted',
'notion_comment_created',
'notion_webhook',
],
},
tools: {
access: [
'notion_read_v2',
Expand Down
100 changes: 100 additions & 0 deletions apps/sim/lib/webhooks/providers/notion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import crypto from 'crypto'
import { createLogger } from '@sim/logger'
import { NextResponse } from 'next/server'
import { safeCompare } from '@/lib/core/security/encryption'
import type {
EventMatchContext,
FormatInputContext,
FormatInputResult,
WebhookProviderHandler,
} from '@/lib/webhooks/providers/types'
import { createHmacVerifier } from '@/lib/webhooks/providers/utils'

const logger = createLogger('WebhookProvider:Notion')

/**
* Validates a Notion webhook signature using HMAC SHA-256.
* Notion sends X-Notion-Signature as "sha256=<hex>".
*/
function validateNotionSignature(secret: string, signature: string, body: string): boolean {
try {
if (!secret || !signature || !body) {
logger.warn('Notion signature validation missing required fields', {
hasSecret: !!secret,
hasSignature: !!signature,
hasBody: !!body,
})
return false
}

const providedHash = signature.startsWith('sha256=') ? signature.slice(7) : signature
const computedHash = crypto.createHmac('sha256', secret).update(body, 'utf8').digest('hex')

logger.debug('Notion signature comparison', {
computedSignature: `${computedHash.substring(0, 10)}...`,
providedSignature: `${providedHash.substring(0, 10)}...`,
computedLength: computedHash.length,
providedLength: providedHash.length,
match: computedHash === providedHash,
})

return safeCompare(computedHash, providedHash)
} catch (error) {
logger.error('Error validating Notion signature:', error)
return false
}
}

export const notionHandler: WebhookProviderHandler = {
verifyAuth: createHmacVerifier({
configKey: 'webhookSecret',
headerName: 'X-Notion-Signature',
validateFn: validateNotionSignature,
providerLabel: 'Notion',
}),

async formatInput({ body }: FormatInputContext): Promise<FormatInputResult> {
const b = body as Record<string, unknown>
return {
input: {
id: b.id,
type: b.type,
timestamp: b.timestamp,
workspace_id: b.workspace_id,
workspace_name: b.workspace_name,
subscription_id: b.subscription_id,
integration_id: b.integration_id,
attempt_number: b.attempt_number,
authors: b.authors || [],
entity: b.entity || {},
data: b.data || {},
},
}
},

async matchEvent({ webhook, workflow, body, requestId, providerConfig }: EventMatchContext) {
const triggerId = providerConfig.triggerId as string | undefined
const obj = body as Record<string, unknown>

if (triggerId && triggerId !== 'notion_webhook') {
const { isNotionPayloadMatch } = await import('@/triggers/notion/utils')
if (!isNotionPayloadMatch(triggerId, obj)) {
const eventType = obj.type as string | undefined
logger.debug(
`[${requestId}] Notion event mismatch for trigger ${triggerId}. Event: ${eventType}. Skipping execution.`,
{
webhookId: webhook.id,
workflowId: workflow.id,
triggerId,
receivedEvent: eventType,
}
)
return NextResponse.json({
message: 'Event type does not match trigger configuration. Ignoring.',
})
}
}

return true
},
}
2 changes: 2 additions & 0 deletions apps/sim/lib/webhooks/providers/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { jiraHandler } from '@/lib/webhooks/providers/jira'
import { lemlistHandler } from '@/lib/webhooks/providers/lemlist'
import { linearHandler } from '@/lib/webhooks/providers/linear'
import { microsoftTeamsHandler } from '@/lib/webhooks/providers/microsoft-teams'
import { notionHandler } from '@/lib/webhooks/providers/notion'
import { outlookHandler } from '@/lib/webhooks/providers/outlook'
import { rssHandler } from '@/lib/webhooks/providers/rss'
import { slackHandler } from '@/lib/webhooks/providers/slack'
Expand Down Expand Up @@ -56,6 +57,7 @@ const PROVIDER_HANDLERS: Record<string, WebhookProviderHandler> = {
lemlist: lemlistHandler,
linear: linearHandler,
'microsoft-teams': microsoftTeamsHandler,
notion: notionHandler,
outlook: outlookHandler,
rss: rssHandler,
slack: slackHandler,
Expand Down
38 changes: 38 additions & 0 deletions apps/sim/triggers/notion/comment_created.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { NotionIcon } from '@/components/icons'
import { buildTriggerSubBlocks } from '@/triggers'
import {
buildCommentEventOutputs,
buildNotionExtraFields,
notionSetupInstructions,
notionTriggerOptions,
} from '@/triggers/notion/utils'
import type { TriggerConfig } from '@/triggers/types'

/**
* Notion Comment Created Trigger
*/
export const notionCommentCreatedTrigger: TriggerConfig = {
id: 'notion_comment_created',
name: 'Notion Comment Created',
provider: 'notion',
description: 'Trigger workflow when a comment or suggested edit is added in Notion',
version: '1.0.0',
icon: NotionIcon,

subBlocks: buildTriggerSubBlocks({
triggerId: 'notion_comment_created',
triggerOptions: notionTriggerOptions,
setupInstructions: notionSetupInstructions('comment.created'),
extraFields: buildNotionExtraFields('notion_comment_created'),
}),

outputs: buildCommentEventOutputs(),

webhook: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Notion-Signature': 'sha256=...',
},
},
}
38 changes: 38 additions & 0 deletions apps/sim/triggers/notion/database_created.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { NotionIcon } from '@/components/icons'
import { buildTriggerSubBlocks } from '@/triggers'
import {
buildDatabaseEventOutputs,
buildNotionExtraFields,
notionSetupInstructions,
notionTriggerOptions,
} from '@/triggers/notion/utils'
import type { TriggerConfig } from '@/triggers/types'

/**
* Notion Database Created Trigger
*/
export const notionDatabaseCreatedTrigger: TriggerConfig = {
id: 'notion_database_created',
name: 'Notion Database Created',
provider: 'notion',
description: 'Trigger workflow when a new database is created in Notion',
version: '1.0.0',
icon: NotionIcon,

subBlocks: buildTriggerSubBlocks({
triggerId: 'notion_database_created',
triggerOptions: notionTriggerOptions,
setupInstructions: notionSetupInstructions('database.created'),
extraFields: buildNotionExtraFields('notion_database_created'),
}),

outputs: buildDatabaseEventOutputs(),

webhook: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Notion-Signature': 'sha256=...',
},
},
}
38 changes: 38 additions & 0 deletions apps/sim/triggers/notion/database_deleted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { NotionIcon } from '@/components/icons'
import { buildTriggerSubBlocks } from '@/triggers'
import {
buildDatabaseEventOutputs,
buildNotionExtraFields,
notionSetupInstructions,
notionTriggerOptions,
} from '@/triggers/notion/utils'
import type { TriggerConfig } from '@/triggers/types'

/**
* Notion Database Deleted Trigger
*/
export const notionDatabaseDeletedTrigger: TriggerConfig = {
id: 'notion_database_deleted',
name: 'Notion Database Deleted',
provider: 'notion',
description: 'Trigger workflow when a database is deleted in Notion',
version: '1.0.0',
icon: NotionIcon,

subBlocks: buildTriggerSubBlocks({
triggerId: 'notion_database_deleted',
triggerOptions: notionTriggerOptions,
setupInstructions: notionSetupInstructions('database.deleted'),
extraFields: buildNotionExtraFields('notion_database_deleted'),
}),

outputs: buildDatabaseEventOutputs(),

webhook: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Notion-Signature': 'sha256=...',
},
},
}
40 changes: 40 additions & 0 deletions apps/sim/triggers/notion/database_schema_updated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { NotionIcon } from '@/components/icons'
import { buildTriggerSubBlocks } from '@/triggers'
import {
buildDatabaseEventOutputs,
buildNotionExtraFields,
notionSetupInstructions,
notionTriggerOptions,
} from '@/triggers/notion/utils'
import type { TriggerConfig } from '@/triggers/types'

/**
* Notion Database Schema Updated Trigger
*
* Fires when a database schema (properties/columns) is modified.
*/
export const notionDatabaseSchemaUpdatedTrigger: TriggerConfig = {
id: 'notion_database_schema_updated',
name: 'Notion Database Schema Updated',
provider: 'notion',
description: 'Trigger workflow when a database schema is modified in Notion',
version: '1.0.0',
icon: NotionIcon,

subBlocks: buildTriggerSubBlocks({
triggerId: 'notion_database_schema_updated',
triggerOptions: notionTriggerOptions,
setupInstructions: notionSetupInstructions('database.schema_updated'),
extraFields: buildNotionExtraFields('notion_database_schema_updated'),
}),

outputs: buildDatabaseEventOutputs(),

webhook: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Notion-Signature': 'sha256=...',
},
},
}
9 changes: 9 additions & 0 deletions apps/sim/triggers/notion/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export { notionCommentCreatedTrigger } from './comment_created'
export { notionDatabaseCreatedTrigger } from './database_created'
export { notionDatabaseDeletedTrigger } from './database_deleted'
export { notionDatabaseSchemaUpdatedTrigger } from './database_schema_updated'
export { notionPageContentUpdatedTrigger } from './page_content_updated'
export { notionPageCreatedTrigger } from './page_created'
export { notionPageDeletedTrigger } from './page_deleted'
export { notionPagePropertiesUpdatedTrigger } from './page_properties_updated'
export { notionWebhookTrigger } from './webhook'
Loading
Loading