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
53 changes: 53 additions & 0 deletions components/notion/actions/create-comment/create-comment.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import notion from "../../notion.app.mjs";
import { ConfigurationError } from "@pipedream/platform";

export default {
key: "notion-create-comment",
name: "Create Comment",
description: "Creates a comment in a page or existing discussion thread. [See the documentation](https://developers.notion.com/reference/create-a-comment)",
version: "0.0.1",
type: "action",
props: {
notion,
pageId: {
propDefinition: [
notion,
"pageId",
],
description: "Unique identifier of a page. Either this or a Discussion ID is required (not both)",
optional: true,
},
discussionId: {
type: "string",
label: "Discussion ID",
description: "A UUID identifier for a discussion thread. Either this or a Page ID is required (not both)",
optional: true,
},
comment: {
type: "string",
label: "Comment",
description: "The comment text",
},
},
async run({ $ }) {
if ((this.pageId && this.discussionId) || (!this.pageId && !this.discussionId)) {
throw new ConfigurationError("Either a Page ID or a Discussion ID is required (not both)");
}

const response = await this.notion._getNotionClient().comments.create({
parent: this.pageId && {
page_id: this.pageId,
},
discussion_id: this.discussionId,
rich_text: [
{
text: {
content: this.comment,
},
},
],
});
$.export("$summary", `Successfully added comment with ID: ${response.id}`);
return response;
},
};
3 changes: 2 additions & 1 deletion components/notion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/notion",
"version": "0.2.7",
"version": "0.3.0",
"description": "Pipedream Notion Components",
"main": "notion.app.mjs",
"keywords": [
Expand All @@ -11,6 +11,7 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"dependencies": {
"@notionhq/client": "^2.2.3",
"@pipedream/platform": "^3.0.3",
"@tryfabric/martian": "^1.2.4",
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import base from "../common/base.mjs";

export default {
...base,
key: "notion-new-comment-created",
name: "New Comment Created",
description: "Emit new event when a new comment is created in a page or block. [See the documentation](https://developers.notion.com/reference/retrieve-a-comment)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
...base.props,
pageId: {
propDefinition: [
base.props.notion,
"pageId",
],
description: "Unique identifier of a page or block",
},
},
methods: {
...base.methods,
generateMeta(comment) {
return {
id: comment.id,
summary: `New Comment ID: ${comment.id}`,
ts: comment.created_time,
};
},
},
async run() {
const lastTs = this.getLastCreatedTimestamp();
let maxTs = lastTs;
let cursor;

do {
const {
results, next_cursor: next,
} = await this.notion._getNotionClient().comments.list({
block_id: this.pageId,
start_cursor: cursor,
page_size: 100,
});
if (!results?.length) {
break;
}
for (const comment of results) {
const ts = Date.parse(comment.created_time);
if (ts >= lastTs) {
maxTs = Math.max(ts, maxTs);
this.$emit(comment, this.generateMeta(comment));
}
}
cursor = next;
} while (cursor);

this.setLastCreatedTimestamp(maxTs);
},
};
35 changes: 15 additions & 20 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading