-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Notion - new sources #18202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Notion - new sources #18202
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import notion from "../../notion.app.mjs"; | ||
import { | ||
createHmac, timingSafeEqual, | ||
} from "crypto"; | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
|
||
export default { | ||
props: { | ||
notion, | ||
db: "$.service.db", | ||
http: "$.interface.http", | ||
info: { | ||
Check warning on line 12 in components/notion/sources/common/base-webhook.mjs
|
||
type: "alert", | ||
alertType: "info", | ||
content: `1. Create this Pipedream source and copy the Source Endpoint URL. | ||
2. In Notion, create a webhook subscription and paste the Source Endpoint URL as the webhook URL. See Notion's guide: https://developers.notion.com/reference/webhooks#step-1-creating-a-webhook-subscription | ||
3. After adding the subscription in Notion, you'll be prompted to verify the webhook using a secret. Open the Source Logs tab in this Pipedream source to find the verification secret (token) and enter it in Notion to complete verification.`, | ||
}, | ||
}, | ||
methods: { | ||
_getToken() { | ||
return this.db.get("token"); | ||
}, | ||
_setToken(token) { | ||
this.db.set("token", token); | ||
}, | ||
verifyWebhook(token, body, headers) { | ||
const calculatedSignature = `sha256=${createHmac("sha256", token).update(JSON.stringify(body)) | ||
.digest("hex")}`; | ||
return timingSafeEqual( | ||
Buffer.from(calculatedSignature), | ||
Buffer.from(headers["x-notion-signature"]), | ||
); | ||
}, | ||
processEvent() { | ||
throw new ConfigurationError("processEvent must be implemented in the source"); | ||
}, | ||
}, | ||
async run(event) { | ||
const { | ||
body, headers, | ||
} = event; | ||
if (!body) { | ||
return; | ||
} | ||
const token = this._getToken(); | ||
if (body.verification_token && !token) { | ||
this._setToken(body.verification_token); | ||
console.log(`Verification token: ${body.verification_token}. Enter this in your Notion webhook settings.`); | ||
return; | ||
} | ||
if (!this.verifyWebhook(token, body, headers)) { | ||
throw new Error("Invalid webhook signature"); | ||
} | ||
|
||
await this.processEvent(body); | ||
}, | ||
}; |
27 changes: 27 additions & 0 deletions
27
components/notion/sources/new-webhook-event-instant/new-webhook-event-instant.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import common from "../common/base-webhook.mjs"; | ||
import sampleEmit from "./test-event.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "notion-new-webhook-event-instant", | ||
name: "New Webhook Event (Instant)", | ||
description: "Emit new event each time a webhook event is received. Webhook must be setup in Notion. [See the documentation](https://developers.notion.com/reference/webhooks#step-1-creating-a-webhook-subscription)", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
methods: { | ||
...common.methods, | ||
_generateMeta(event) { | ||
return { | ||
id: event.id, | ||
summary: `Webhook event: ${event.type}`, | ||
ts: Date.now(), | ||
}; | ||
}, | ||
processEvent(event) { | ||
const meta = this._generateMeta(event); | ||
this.$emit(event, meta); | ||
}, | ||
}, | ||
sampleEmit, | ||
}; |
31 changes: 31 additions & 0 deletions
31
components/notion/sources/new-webhook-event-instant/test-event.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export default { | ||
"id": "555831bd-c1d6-400b-873e-42b10fb7f7e8", | ||
"timestamp": "2025-08-27T20:51:19.356Z", | ||
"workspace_id": "e0f732bd-e43f-4db3-b923-8a12ffdbfcce", | ||
"workspace_name": "Notion", | ||
"subscription_id": "25cd872b-594c-8181-982c-009998a96535", | ||
"integration_id": "1ded872b-594c-804e-88d9-0037511f15c1", | ||
"authors": [ | ||
{ | ||
"id": "22da95d5-0f61-4b51-963d-63c4cf51ae19", | ||
"type": "person" | ||
} | ||
], | ||
"attempt_number": 1, | ||
"api_version": "2022-06-28", | ||
"entity": { | ||
"id": "10773a03-a25e-8061-8256-f26813633a59", | ||
"type": "page" | ||
}, | ||
"type": "page.properties_updated", | ||
"data": { | ||
"parent": { | ||
"id": "9813bf8c-a429-4d63-b73b-f476783ff448", | ||
"type": "database", | ||
"data_source_id": "dabbe504-b5ff-48f1-a1fa-d5fea5ef9ac4" | ||
}, | ||
"updated_properties": [ | ||
"title" | ||
] | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...onents/notion/sources/page-properties-updated-instant/page-properties-updated-instant.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import common from "../common/base-webhook.mjs"; | ||
import sampleEmit from "./test-event.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "notion-page-properties-updated-instant", | ||
name: "Page Properties Updated (Instant)", | ||
description: "Emit new event each time a page property is updated in a database. For use with Page Properties Updated event type. Webhook must be set up in Notion. [See the documentation](https://developers.notion.com/reference/webhooks#step-1-creating-a-webhook-subscription)", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
...common.props, | ||
databaseId: { | ||
propDefinition: [ | ||
common.props.notion, | ||
"databaseId", | ||
], | ||
}, | ||
properties: { | ||
type: "string[]", | ||
label: "Properties", | ||
description: "Only emit events when one or more of the selected properties have changed", | ||
optional: true, | ||
async options() { | ||
try { | ||
const { properties } = await this.notion.retrieveDatabase(this.databaseId); | ||
const propEntries = Object.entries(properties); | ||
return propEntries.map((prop) => ({ | ||
label: prop[1].name, | ||
value: prop[1].id, | ||
})); | ||
} catch (error) { | ||
console.log(error); | ||
return []; | ||
} | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
...common.methods, | ||
_generateMeta(page) { | ||
const { id } = page; | ||
const title = this.notion.extractPageTitle(page); | ||
const ts = Date.now(); | ||
return { | ||
id: `${id}-${ts}`, | ||
summary: `Page updated: ${title}`, | ||
ts, | ||
}; | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
async processEvent(event) { | ||
if (event?.type !== "page.properties_updated") { | ||
console.log(`Skipping event type: ${event?.type}`); | ||
return; | ||
} | ||
|
||
if (event.data.parent.id !== this.databaseId) { | ||
console.log(`Skipping event for database: ${event.data.parent.id}`); | ||
return; | ||
} | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const updatedProperties = event.data.updated_properties; | ||
if (!updatedProperties?.length) { | ||
return; | ||
} | ||
|
||
let propertyHasChanged = false; | ||
for (const propertyName of updatedProperties) { | ||
if (!this.properties || this.properties.includes(propertyName)) { | ||
propertyHasChanged = true; | ||
} | ||
} | ||
|
||
if (!propertyHasChanged) { | ||
return; | ||
} | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const page = await this.notion.retrievePage(event.entity.id); | ||
|
||
const meta = this._generateMeta(page); | ||
this.$emit({ | ||
...event, | ||
page, | ||
}, meta); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
sampleEmit, | ||
}; |
37 changes: 37 additions & 0 deletions
37
components/notion/sources/page-properties-updated-instant/test-event.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export default { | ||
"id": "1782edd6-a853-4d4a-b02c-9c8c16f28e53", | ||
"timestamp": "2024-12-05T23:57:05.379Z", | ||
"workspace_id": "13950b26-c203-4f3b-b97d-93ec06319565", | ||
"workspace_name": "Quantify Labs", | ||
"subscription_id": "29d75c0d-5546-4414-8459-7b7a92f1fc4b", | ||
"integration_id": "0ef2e755-4912-8096-91c1-00376a88a5ca", | ||
"type": "page.properties_updated", | ||
"authors": [ | ||
{ | ||
"id": "c7c11cca-1d73-471d-9b6e-bdef51470190", | ||
"type": "person" | ||
} | ||
], | ||
"accessible_by": [ | ||
{ | ||
"id": "556a1abf-4f08-40c6-878a-75890d2a88ba", | ||
"type": "person" | ||
}, | ||
{ | ||
"id": "1edc05f6-2702-81b5-8408-00279347f034", | ||
"type": "bot" | ||
} | ||
], | ||
"attempt_number": 1, | ||
"entity": { | ||
"id": "153104cd-477e-809d-8dc4-ff2d96ae3090", | ||
"type": "page" | ||
}, | ||
"data": { | ||
"parent": { | ||
"id": "13950b26-c203-4f3b-b97d-93ec06319565", | ||
"type": "space" | ||
}, | ||
"updated_properties": ["XGe%40", "bDf%5B", "DbAu"] | ||
} | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.