Skip to content

Commit 03b056d

Browse files
committed
adhook init
1 parent d81cb68 commit 03b056d

File tree

7 files changed

+631
-4
lines changed

7 files changed

+631
-4
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import adhook from "../../adhook.app.mjs";
2+
import { axios } from "@pipedream/platform";
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.{{ts}}",
9+
type: "action",
10+
props: {
11+
adhook,
12+
eventName: {
13+
propDefinition: [
14+
adhook,
15+
"eventName",
16+
],
17+
},
18+
startDate: {
19+
propDefinition: [
20+
adhook,
21+
"startDate",
22+
],
23+
},
24+
endDate: {
25+
propDefinition: [
26+
adhook,
27+
"endDate",
28+
],
29+
},
30+
eventDescription: {
31+
propDefinition: [
32+
adhook,
33+
"eventDescription",
34+
],
35+
optional: true,
36+
},
37+
attendees: {
38+
propDefinition: [
39+
adhook,
40+
"attendees",
41+
],
42+
optional: true,
43+
},
44+
attachments: {
45+
propDefinition: [
46+
adhook,
47+
"attachments",
48+
],
49+
optional: true,
50+
},
51+
},
52+
async run({ $ }) {
53+
const response = await this.adhook.createCalendarEvent({
54+
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,
61+
},
62+
});
63+
64+
$.export("$summary", `Successfully created calendar event: ${this.eventName}`);
65+
return response;
66+
},
67+
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import adhook from "../../adhook.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "adhook-create-update-post",
6+
name: "Create or Update Post",
7+
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+
type: "action",
10+
props: {
11+
adhook,
12+
postId: {
13+
propDefinition: [
14+
adhook,
15+
"postId",
16+
],
17+
optional: true,
18+
},
19+
postContent: {
20+
propDefinition: [
21+
adhook,
22+
"postContent",
23+
],
24+
},
25+
visibility: {
26+
propDefinition: [
27+
adhook,
28+
"visibility",
29+
],
30+
},
31+
postAttachments: {
32+
propDefinition: [
33+
adhook,
34+
"postAttachments",
35+
],
36+
optional: true,
37+
},
38+
mentionUsers: {
39+
propDefinition: [
40+
adhook,
41+
"mentionUsers",
42+
],
43+
optional: true,
44+
},
45+
},
46+
async run({ $ }) {
47+
const data = {
48+
postContent: this.postContent,
49+
visibility: this.visibility,
50+
postAttachments: this.postAttachments,
51+
mentionUsers: this.mentionUsers,
52+
};
53+
54+
if (this.postId) {
55+
data.postId = this.postId;
56+
}
57+
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,
65+
});
66+
67+
$.export("$summary", `Successfully ${this.postId
68+
? "updated"
69+
: "created"} post`);
70+
return response;
71+
},
72+
};

components/adhook/adhook.app.mjs

Lines changed: 178 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,186 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "adhook",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
postType: {
8+
type: "string",
9+
label: "Post Type",
10+
description: "The type of the post",
11+
optional: true,
12+
},
13+
postAuthor: {
14+
type: "string",
15+
label: "Post Author",
16+
description: "The author of the post",
17+
optional: true,
18+
},
19+
postTags: {
20+
type: "string[]",
21+
label: "Post Tags",
22+
description: "Tags associated with the post",
23+
optional: true,
24+
},
25+
postId: {
26+
type: "string",
27+
label: "Post ID",
28+
description: "The ID of the post",
29+
},
30+
isNew: {
31+
type: "boolean",
32+
label: "Is New",
33+
description: "Indicates if the post is new",
34+
optional: true,
35+
},
36+
updateType: {
37+
type: "string",
38+
label: "Update Type",
39+
description: "Type of update made to the post",
40+
optional: true,
41+
},
42+
eventName: {
43+
type: "string",
44+
label: "Event Name",
45+
description: "Name of the calendar event",
46+
},
47+
startDate: {
48+
type: "string",
49+
label: "Start Date",
50+
description: "Start date of the event",
51+
},
52+
endDate: {
53+
type: "string",
54+
label: "End Date",
55+
description: "End date of the event",
56+
},
57+
eventDescription: {
58+
type: "string",
59+
label: "Event Description",
60+
description: "Description of the event",
61+
optional: true,
62+
},
63+
attendees: {
64+
type: "string[]",
65+
label: "Attendees",
66+
description: "List of attendees for the event",
67+
optional: true,
68+
},
69+
attachments: {
70+
type: "string[]",
71+
label: "Attachments",
72+
description: "Attachments for the event",
73+
optional: true,
74+
},
75+
postContent: {
76+
type: "string",
77+
label: "Post Content",
78+
description: "Content of the post",
79+
},
80+
visibility: {
81+
type: "string",
82+
label: "Visibility",
83+
description: "Visibility setting of the post",
84+
},
85+
postAttachments: {
86+
type: "string[]",
87+
label: "Post Attachments",
88+
description: "Attachments for the post",
89+
optional: true,
90+
},
91+
mentionUsers: {
92+
type: "string[]",
93+
label: "Mention Users",
94+
description: "Users to mention in the post",
95+
optional: true,
96+
},
97+
},
598
methods: {
6-
// this.$auth contains connected account data
99+
_baseUrl() {
100+
return "https://app.adhook.io/api";
101+
},
102+
async _makeRequest(opts = {}) {
103+
const {
104+
$ = this, method = "GET", path = "/", headers, ...otherOpts
105+
} = opts;
106+
return axios($, {
107+
...otherOpts,
108+
method,
109+
url: this._baseUrl() + path,
110+
headers: {
111+
...headers,
112+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
113+
},
114+
});
115+
},
116+
async emitNewPostEvent(opts = {}) {
117+
return this._makeRequest({
118+
method: "POST",
119+
path: "/events/new_post",
120+
data: {
121+
postType: this.postType,
122+
postAuthor: this.postAuthor,
123+
postTags: this.postTags,
124+
},
125+
...opts,
126+
});
127+
},
128+
async emitPostCreatedOrUpdatedEvent(opts = {}) {
129+
return this._makeRequest({
130+
method: "POST",
131+
path: "/events/post_created_or_updated",
132+
data: {
133+
postId: this.postId,
134+
postAuthor: this.postAuthor,
135+
postTags: this.postTags,
136+
isNew: this.isNew,
137+
},
138+
...opts,
139+
});
140+
},
141+
async emitPostUpdatedEvent(opts = {}) {
142+
return this._makeRequest({
143+
method: "POST",
144+
path: "/events/post_updated",
145+
data: {
146+
postId: this.postId,
147+
postAuthor: this.postAuthor,
148+
postTags: this.postTags,
149+
updateType: this.updateType,
150+
},
151+
...opts,
152+
});
153+
},
154+
async createCalendarEvent(opts = {}) {
155+
return this._makeRequest({
156+
method: "POST",
157+
path: "/events/calendar",
158+
data: {
159+
eventName: this.eventName,
160+
startDate: this.startDate,
161+
endDate: this.endDate,
162+
eventDescription: this.eventDescription,
163+
attendees: this.attendees,
164+
attachments: this.attachments,
165+
},
166+
...opts,
167+
});
168+
},
169+
async addOrUpdatePost(opts = {}) {
170+
return this._makeRequest({
171+
method: "POST",
172+
path: "/posts",
173+
data: {
174+
postContent: this.postContent,
175+
visibility: this.visibility,
176+
postAttachments: this.postAttachments,
177+
mentionUsers: this.mentionUsers,
178+
},
179+
...opts,
180+
});
181+
},
7182
authKeys() {
8183
console.log(Object.keys(this.$auth));
9184
},
10185
},
11-
};
186+
};

components/adhook/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)