Skip to content

Commit a7a1e75

Browse files
committed
[Components] adhook #13804
Sources - New Post Created - New Post Updated Actions - Create Calendar Event - Create Or Update Post
1 parent 03b056d commit a7a1e75

File tree

12 files changed

+506
-480
lines changed

12 files changed

+506
-480
lines changed
Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,108 @@
11
import adhook from "../../adhook.app.mjs";
2-
import { axios } from "@pipedream/platform";
2+
import { parseObject } from "../../common/utils.mjs";
33

44
export default {
55
key: "adhook-create-calendar-event",
66
name: "Create Calendar Event",
77
description: "Generates a personalized calendar event in AdHook. [See the documentation](https://app.adhook.io/api-doc/)",
8-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
adhook,
12-
eventName: {
13-
propDefinition: [
14-
adhook,
15-
"eventName",
16-
],
12+
title: {
13+
type: "string",
14+
label: "Event Title",
15+
description: "The title of the calendar event",
16+
optional: true,
17+
},
18+
description: {
19+
type: "string",
20+
label: "Event Description",
21+
description: "The description of the calendar event",
22+
optional: true,
1723
},
18-
startDate: {
24+
externalId: {
1925
propDefinition: [
2026
adhook,
21-
"startDate",
27+
"externalId",
2228
],
29+
optional: true,
30+
},
31+
start: {
32+
type: "string",
33+
label: "Start Date",
34+
description: "Start date of the event. **Format: YYYY-MM-DDTHH:MM:SSZ**",
35+
optional: true,
36+
},
37+
end: {
38+
type: "string",
39+
label: "End Date",
40+
description: "End date of the event. **Format: YYYY-MM-DDTHH:MM:SSZ**",
41+
optional: true,
42+
},
43+
allDay: {
44+
type: "boolean",
45+
label: "All Day",
46+
description: "Whether the event lasts all day or not",
47+
optional: true,
48+
},
49+
color: {
50+
type: "string",
51+
label: "Color",
52+
description: "The color of the event",
53+
optional: true,
2354
},
24-
endDate: {
55+
subtenantId: {
2556
propDefinition: [
2657
adhook,
27-
"endDate",
58+
"subtenantId",
2859
],
60+
optional: true,
2961
},
30-
eventDescription: {
62+
tags: {
3163
propDefinition: [
3264
adhook,
33-
"eventDescription",
65+
"tags",
3466
],
3567
optional: true,
3668
},
37-
attendees: {
69+
topics: {
3870
propDefinition: [
3971
adhook,
40-
"attendees",
72+
"topics",
4173
],
4274
optional: true,
4375
},
4476
attachments: {
45-
propDefinition: [
46-
adhook,
47-
"attachments",
48-
],
77+
type: "string[]",
78+
label: "Attachments",
79+
description: "A list of objects of attachments for the event. **Format: {\"name\": \"Attachment name\", \"url\":\"https://attachment.com/file.pdf\", \"fileExtension\":\"pdf\"}**",
4980
optional: true,
5081
},
5182
},
5283
async run({ $ }) {
53-
const response = await this.adhook.createCalendarEvent({
84+
const {
85+
adhook,
86+
tags,
87+
topics,
88+
attachments,
89+
...data
90+
} = this;
91+
92+
const response = await adhook.createCalendarEvent({
93+
$,
5494
data: {
55-
eventName: this.eventName,
56-
startDate: this.startDate,
57-
endDate: this.endDate,
58-
eventDescription: this.eventDescription,
59-
attendees: this.attendees,
60-
attachments: this.attachments,
95+
type: "EVENT",
96+
...data,
97+
tags: parseObject(tags),
98+
topics: parseObject(topics)?.map((topic) => ({
99+
name: topic,
100+
})),
101+
attachments: parseObject(attachments),
61102
},
62103
});
63104

64-
$.export("$summary", `Successfully created calendar event: ${this.eventName}`);
105+
$.export("$summary", `Successfully created calendar event: ${response.id}`);
65106
return response;
66107
},
67108
};
Lines changed: 92 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import adhook from "../../adhook.app.mjs";
2-
import { axios } from "@pipedream/platform";
2+
import constants from "../../common/constants.mjs";
3+
import { parseObject } from "../../common/utils.mjs";
34

45
export default {
56
key: "adhook-create-update-post",
67
name: "Create or Update Post",
78
description: "Adds a new post or modifies an existing post in Adhook. [See the documentation](https://app.adhook.io/api-doc/)",
8-
version: "0.0.{{ts}}",
9+
version: "0.0.1",
910
type: "action",
1011
props: {
1112
adhook,
@@ -16,57 +17,122 @@ export default {
1617
],
1718
optional: true,
1819
},
19-
postContent: {
20+
name: {
21+
type: "string",
22+
label: "Name",
23+
description: "The name of the post",
24+
optional: true,
25+
},
26+
type: {
27+
type: "string",
28+
label: "Type",
29+
description: "The type of the post",
30+
optional: true,
31+
options: constants.TYPE_OPTIONS,
32+
},
33+
subtenantId: {
2034
propDefinition: [
2135
adhook,
22-
"postContent",
36+
"subtenantId",
2337
],
38+
optional: true,
2439
},
25-
visibility: {
40+
status: {
41+
type: "string",
42+
label: "Status",
43+
description: "The status of the post",
44+
optional: true,
45+
options: constants.STATUS_OPTIONS,
46+
},
47+
tags: {
2648
propDefinition: [
2749
adhook,
28-
"visibility",
50+
"tags",
2951
],
52+
optional: true,
3053
},
31-
postAttachments: {
54+
topics: {
3255
propDefinition: [
3356
adhook,
34-
"postAttachments",
57+
"topics",
3558
],
3659
optional: true,
3760
},
38-
mentionUsers: {
61+
schedule: {
62+
type: "string",
63+
label: "Schedule",
64+
description: "Whether you want to schedule or publish the post",
65+
optional: true,
66+
options: constants.SCHEDULE_OPTIONS,
67+
},
68+
message: {
69+
type: "string",
70+
label: "Message",
71+
description: "A message to send with the post",
72+
optional: true,
73+
},
74+
promotionType: {
75+
type: "string",
76+
label: "Promotion Type",
77+
description: "The type of the promotion in the post",
78+
optional: true,
79+
options: constants.PROMOTION_TYPE_OPTIONS,
80+
},
81+
campaignName: {
82+
type: "string",
83+
label: "Campaign Name",
84+
description: "The name of the campaign",
85+
optional: true,
86+
},
87+
externalId: {
3988
propDefinition: [
4089
adhook,
41-
"mentionUsers",
90+
"externalId",
4291
],
4392
optional: true,
4493
},
4594
},
4695
async run({ $ }) {
47-
const data = {
48-
postContent: this.postContent,
49-
visibility: this.visibility,
50-
postAttachments: this.postAttachments,
51-
mentionUsers: this.mentionUsers,
52-
};
96+
const {
97+
adhook,
98+
postId,
99+
tags,
100+
topics,
101+
...data
102+
} = this;
53103

54-
if (this.postId) {
55-
data.postId = this.postId;
104+
let postData = {};
105+
106+
if (postId) {
107+
const post = await adhook.getPost({
108+
postId,
109+
});
110+
postData = post;
56111
}
57112

58-
const response = await axios($, {
59-
method: "POST",
60-
url: `${this.adhook._baseUrl()}/posts`,
61-
headers: {
62-
Authorization: `Bearer ${this.adhook.$auth.oauth_access_token}`,
63-
},
64-
data,
113+
postData = {
114+
...postData,
115+
...data,
116+
tags: parseObject(tags) || postData.tags,
117+
topics: parseObject(topics)?.map((topic) => ({
118+
name: topic,
119+
})) || postData.topics,
120+
};
121+
122+
const fn = postId
123+
? adhook.updatePost
124+
: adhook.createPost;
125+
126+
const response = await fn({
127+
$,
128+
postId,
129+
data: postData,
65130
});
66131

67-
$.export("$summary", `Successfully ${this.postId
132+
$.export("$summary", `Successfully ${postId
68133
? "updated"
69134
: "created"} post`);
135+
70136
return response;
71137
},
72138
};

0 commit comments

Comments
 (0)