Skip to content

Commit dea586c

Browse files
authored
New Components - adhook (#13935)
* adhook init * [Components] adhook #13804 Sources - New Post Created - New Post Updated Actions - Create Calendar Event - Create Or Update Post * pnpm update
1 parent ae48681 commit dea586c

File tree

12 files changed

+664
-8
lines changed

12 files changed

+664
-8
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import adhook from "../../adhook.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "adhook-create-calendar-event",
6+
name: "Create Calendar Event",
7+
description: "Generates a personalized calendar event in AdHook. [See the documentation](https://app.adhook.io/api-doc/)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
adhook,
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,
23+
},
24+
externalId: {
25+
propDefinition: [
26+
adhook,
27+
"externalId",
28+
],
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,
54+
},
55+
subtenantId: {
56+
propDefinition: [
57+
adhook,
58+
"subtenantId",
59+
],
60+
optional: true,
61+
},
62+
tags: {
63+
propDefinition: [
64+
adhook,
65+
"tags",
66+
],
67+
optional: true,
68+
},
69+
topics: {
70+
propDefinition: [
71+
adhook,
72+
"topics",
73+
],
74+
optional: true,
75+
},
76+
attachments: {
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\"}**",
80+
optional: true,
81+
},
82+
},
83+
async run({ $ }) {
84+
const {
85+
adhook,
86+
tags,
87+
topics,
88+
attachments,
89+
...data
90+
} = this;
91+
92+
const response = await adhook.createCalendarEvent({
93+
$,
94+
data: {
95+
type: "EVENT",
96+
...data,
97+
tags: parseObject(tags),
98+
topics: parseObject(topics)?.map((topic) => ({
99+
name: topic,
100+
})),
101+
attachments: parseObject(attachments),
102+
},
103+
});
104+
105+
$.export("$summary", `Successfully created calendar event: ${response.id}`);
106+
return response;
107+
},
108+
};
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import adhook from "../../adhook.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
import { parseObject } from "../../common/utils.mjs";
4+
5+
export default {
6+
key: "adhook-create-update-post",
7+
name: "Create or Update Post",
8+
description: "Adds a new post or modifies an existing post in Adhook. [See the documentation](https://app.adhook.io/api-doc/)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
adhook,
13+
postId: {
14+
propDefinition: [
15+
adhook,
16+
"postId",
17+
],
18+
optional: true,
19+
},
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: {
34+
propDefinition: [
35+
adhook,
36+
"subtenantId",
37+
],
38+
optional: true,
39+
},
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: {
48+
propDefinition: [
49+
adhook,
50+
"tags",
51+
],
52+
optional: true,
53+
},
54+
topics: {
55+
propDefinition: [
56+
adhook,
57+
"topics",
58+
],
59+
optional: true,
60+
},
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: {
88+
propDefinition: [
89+
adhook,
90+
"externalId",
91+
],
92+
optional: true,
93+
},
94+
},
95+
async run({ $ }) {
96+
const {
97+
adhook,
98+
postId,
99+
tags,
100+
topics,
101+
...data
102+
} = this;
103+
104+
let postData = {};
105+
106+
if (postId) {
107+
const post = await adhook.getPost({
108+
postId,
109+
});
110+
postData = post;
111+
}
112+
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,
130+
});
131+
132+
$.export("$summary", `Successfully ${postId
133+
? "updated"
134+
: "created"} post`);
135+
136+
return response;
137+
},
138+
};

components/adhook/adhook.app.mjs

Lines changed: 122 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,128 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "adhook",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
subtenantId: {
9+
type: "string",
10+
label: "Subtenant Id",
11+
description: "The id of the subtenant.",
12+
async options() {
13+
const data = await this.listSubtenants();
14+
15+
return data.map(({
16+
id: value, name: label,
17+
}) => ({
18+
label,
19+
value,
20+
}));
21+
},
22+
},
23+
postId: {
24+
type: "string",
25+
label: "Post ID",
26+
description: "The ID of the post",
27+
async options({ page }) {
28+
const data = await this.listPosts({
29+
params: {
30+
limit: constants.LIMIT,
31+
skip: constants.LIMIT * page,
32+
},
33+
});
34+
35+
return data.map(({
36+
id: value, name: label,
37+
}) => ({
38+
label,
39+
value,
40+
}));
41+
},
42+
},
43+
tags: {
44+
type: "string[]",
45+
label: "Tags",
46+
description: "A list of tags.",
47+
},
48+
topics: {
49+
type: "string[]",
50+
label: "Topics",
51+
description: "A list of topics.",
52+
},
53+
externalId: {
54+
type: "string",
55+
label: "External Id",
56+
description: "An external Id to the event",
57+
},
58+
},
559
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
60+
_baseUrl() {
61+
return "https://app.adhook.io/api/v1";
62+
},
63+
_headers() {
64+
return {
65+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
66+
};
67+
},
68+
_makeRequest({
69+
$ = this, path, ...opts
70+
}) {
71+
return axios($, {
72+
url: this._baseUrl() + path,
73+
headers: this._headers(),
74+
...opts,
75+
});
76+
},
77+
createCalendarEvent(opts = {}) {
78+
return this._makeRequest({
79+
method: "POST",
80+
path: "/customEvents",
81+
...opts,
82+
});
83+
},
84+
listPosts(opts = {}) {
85+
return this._makeRequest({
86+
path: "/posts",
87+
...opts,
88+
});
89+
},
90+
listSubtenants(opts = {}) {
91+
return this._makeRequest({
92+
path: "/subtenants",
93+
...opts,
94+
});
95+
},
96+
createPost(opts = {}) {
97+
return this._makeRequest({
98+
method: "POST",
99+
path: "/posts",
100+
...opts,
101+
});
102+
},
103+
getPost({ postId }) {
104+
return this._makeRequest({
105+
path: `/posts/${postId}`,
106+
});
107+
},
108+
updatePost({
109+
postId, ...opts
110+
}) {
111+
return this._makeRequest({
112+
method: "PUT",
113+
path: `/posts/${postId}`,
114+
...opts,
115+
});
116+
},
117+
listCreatedPosts() {
118+
return this._makeRequest({
119+
path: "/posts/recentlyCreated",
120+
});
121+
},
122+
listUpdatedPosts() {
123+
return this._makeRequest({
124+
path: "/posts/recentlyUpdated",
125+
});
9126
},
10127
},
11-
};
128+
};

0 commit comments

Comments
 (0)