Skip to content

Commit c11fb49

Browse files
authored
Notion - Comments (#15200)
* new comment components * pnpm-lock.yaml
1 parent b752ef0 commit c11fb49

File tree

4 files changed

+125
-17
lines changed

4 files changed

+125
-17
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import notion from "../../notion.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
4+
export default {
5+
key: "notion-create-comment",
6+
name: "Create Comment",
7+
description: "Creates a comment in a page or existing discussion thread. [See the documentation](https://developers.notion.com/reference/create-a-comment)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
notion,
12+
pageId: {
13+
propDefinition: [
14+
notion,
15+
"pageId",
16+
],
17+
description: "Unique identifier of a page. Either this or a Discussion ID is required (not both)",
18+
optional: true,
19+
},
20+
discussionId: {
21+
type: "string",
22+
label: "Discussion ID",
23+
description: "A UUID identifier for a discussion thread. Either this or a Page ID is required (not both)",
24+
optional: true,
25+
},
26+
comment: {
27+
type: "string",
28+
label: "Comment",
29+
description: "The comment text",
30+
},
31+
},
32+
async run({ $ }) {
33+
if ((this.pageId && this.discussionId) || (!this.pageId && !this.discussionId)) {
34+
throw new ConfigurationError("Either a Page ID or a Discussion ID is required (not both)");
35+
}
36+
37+
const response = await this.notion._getNotionClient().comments.create({
38+
parent: this.pageId && {
39+
page_id: this.pageId,
40+
},
41+
discussion_id: this.discussionId,
42+
rich_text: [
43+
{
44+
text: {
45+
content: this.comment,
46+
},
47+
},
48+
],
49+
});
50+
$.export("$summary", `Successfully added comment with ID: ${response.id}`);
51+
return response;
52+
},
53+
};

components/notion/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/notion",
3-
"version": "0.2.7",
3+
"version": "0.3.0",
44
"description": "Pipedream Notion Components",
55
"main": "notion.app.mjs",
66
"keywords": [
@@ -11,6 +11,7 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"dependencies": {
1313
"@notionhq/client": "^2.2.3",
14+
"@pipedream/platform": "^3.0.3",
1415
"@tryfabric/martian": "^1.2.4",
1516
"asynckit": "^0.4.0",
1617
"combined-stream": "^1.0.8",
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import base from "../common/base.mjs";
2+
3+
export default {
4+
...base,
5+
key: "notion-new-comment-created",
6+
name: "New Comment Created",
7+
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)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
...base.props,
13+
pageId: {
14+
propDefinition: [
15+
base.props.notion,
16+
"pageId",
17+
],
18+
description: "Unique identifier of a page or block",
19+
},
20+
},
21+
methods: {
22+
...base.methods,
23+
generateMeta(comment) {
24+
return {
25+
id: comment.id,
26+
summary: `New Comment ID: ${comment.id}`,
27+
ts: comment.created_time,
28+
};
29+
},
30+
},
31+
async run() {
32+
const lastTs = this.getLastCreatedTimestamp();
33+
let maxTs = lastTs;
34+
let cursor;
35+
36+
do {
37+
const {
38+
results, next_cursor: next,
39+
} = await this.notion._getNotionClient().comments.list({
40+
block_id: this.pageId,
41+
start_cursor: cursor,
42+
page_size: 100,
43+
});
44+
if (!results?.length) {
45+
break;
46+
}
47+
for (const comment of results) {
48+
const ts = Date.parse(comment.created_time);
49+
if (ts >= lastTs) {
50+
maxTs = Math.max(ts, maxTs);
51+
this.$emit(comment, this.generateMeta(comment));
52+
}
53+
}
54+
cursor = next;
55+
} while (cursor);
56+
57+
this.setLastCreatedTimestamp(maxTs);
58+
},
59+
};

pnpm-lock.yaml

Lines changed: 11 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)