Skip to content

Commit

Permalink
New Components - adhook (#13935)
Browse files Browse the repository at this point in the history
* adhook init

* [Components] adhook #13804
Sources
 - New Post Created
 - New Post Updated

Actions
 - Create Calendar Event
 - Create Or Update Post

* pnpm update
  • Loading branch information
luancazarine authored Sep 17, 2024
1 parent ae48681 commit dea586c
Show file tree
Hide file tree
Showing 12 changed files with 664 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import adhook from "../../adhook.app.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "adhook-create-calendar-event",
name: "Create Calendar Event",
description: "Generates a personalized calendar event in AdHook. [See the documentation](https://app.adhook.io/api-doc/)",
version: "0.0.1",
type: "action",
props: {
adhook,
title: {
type: "string",
label: "Event Title",
description: "The title of the calendar event",
optional: true,
},
description: {
type: "string",
label: "Event Description",
description: "The description of the calendar event",
optional: true,
},
externalId: {
propDefinition: [
adhook,
"externalId",
],
optional: true,
},
start: {
type: "string",
label: "Start Date",
description: "Start date of the event. **Format: YYYY-MM-DDTHH:MM:SSZ**",
optional: true,
},
end: {
type: "string",
label: "End Date",
description: "End date of the event. **Format: YYYY-MM-DDTHH:MM:SSZ**",
optional: true,
},
allDay: {
type: "boolean",
label: "All Day",
description: "Whether the event lasts all day or not",
optional: true,
},
color: {
type: "string",
label: "Color",
description: "The color of the event",
optional: true,
},
subtenantId: {
propDefinition: [
adhook,
"subtenantId",
],
optional: true,
},
tags: {
propDefinition: [
adhook,
"tags",
],
optional: true,
},
topics: {
propDefinition: [
adhook,
"topics",
],
optional: true,
},
attachments: {
type: "string[]",
label: "Attachments",
description: "A list of objects of attachments for the event. **Format: {\"name\": \"Attachment name\", \"url\":\"https://attachment.com/file.pdf\", \"fileExtension\":\"pdf\"}**",
optional: true,
},
},
async run({ $ }) {
const {
adhook,
tags,
topics,
attachments,
...data
} = this;

const response = await adhook.createCalendarEvent({
$,
data: {
type: "EVENT",
...data,
tags: parseObject(tags),
topics: parseObject(topics)?.map((topic) => ({
name: topic,
})),
attachments: parseObject(attachments),
},
});

$.export("$summary", `Successfully created calendar event: ${response.id}`);
return response;
},
};
138 changes: 138 additions & 0 deletions components/adhook/actions/create-update-post/create-update-post.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import adhook from "../../adhook.app.mjs";
import constants from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "adhook-create-update-post",
name: "Create or Update Post",
description: "Adds a new post or modifies an existing post in Adhook. [See the documentation](https://app.adhook.io/api-doc/)",
version: "0.0.1",
type: "action",
props: {
adhook,
postId: {
propDefinition: [
adhook,
"postId",
],
optional: true,
},
name: {
type: "string",
label: "Name",
description: "The name of the post",
optional: true,
},
type: {
type: "string",
label: "Type",
description: "The type of the post",
optional: true,
options: constants.TYPE_OPTIONS,
},
subtenantId: {
propDefinition: [
adhook,
"subtenantId",
],
optional: true,
},
status: {
type: "string",
label: "Status",
description: "The status of the post",
optional: true,
options: constants.STATUS_OPTIONS,
},
tags: {
propDefinition: [
adhook,
"tags",
],
optional: true,
},
topics: {
propDefinition: [
adhook,
"topics",
],
optional: true,
},
schedule: {
type: "string",
label: "Schedule",
description: "Whether you want to schedule or publish the post",
optional: true,
options: constants.SCHEDULE_OPTIONS,
},
message: {
type: "string",
label: "Message",
description: "A message to send with the post",
optional: true,
},
promotionType: {
type: "string",
label: "Promotion Type",
description: "The type of the promotion in the post",
optional: true,
options: constants.PROMOTION_TYPE_OPTIONS,
},
campaignName: {
type: "string",
label: "Campaign Name",
description: "The name of the campaign",
optional: true,
},
externalId: {
propDefinition: [
adhook,
"externalId",
],
optional: true,
},
},
async run({ $ }) {
const {
adhook,
postId,
tags,
topics,
...data
} = this;

let postData = {};

if (postId) {
const post = await adhook.getPost({
postId,
});
postData = post;
}

postData = {
...postData,
...data,
tags: parseObject(tags) || postData.tags,
topics: parseObject(topics)?.map((topic) => ({
name: topic,
})) || postData.topics,
};

const fn = postId
? adhook.updatePost
: adhook.createPost;

const response = await fn({
$,
postId,
data: postData,
});

$.export("$summary", `Successfully ${postId
? "updated"
: "created"} post`);

return response;
},
};
127 changes: 122 additions & 5 deletions components/adhook/adhook.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,128 @@
import { axios } from "@pipedream/platform";
import constants from "./common/constants.mjs";

export default {
type: "app",
app: "adhook",
propDefinitions: {},
propDefinitions: {
subtenantId: {
type: "string",
label: "Subtenant Id",
description: "The id of the subtenant.",
async options() {
const data = await this.listSubtenants();

return data.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
postId: {
type: "string",
label: "Post ID",
description: "The ID of the post",
async options({ page }) {
const data = await this.listPosts({
params: {
limit: constants.LIMIT,
skip: constants.LIMIT * page,
},
});

return data.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
tags: {
type: "string[]",
label: "Tags",
description: "A list of tags.",
},
topics: {
type: "string[]",
label: "Topics",
description: "A list of topics.",
},
externalId: {
type: "string",
label: "External Id",
description: "An external Id to the event",
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://app.adhook.io/api/v1";
},
_headers() {
return {
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(),
...opts,
});
},
createCalendarEvent(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/customEvents",
...opts,
});
},
listPosts(opts = {}) {
return this._makeRequest({
path: "/posts",
...opts,
});
},
listSubtenants(opts = {}) {
return this._makeRequest({
path: "/subtenants",
...opts,
});
},
createPost(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/posts",
...opts,
});
},
getPost({ postId }) {
return this._makeRequest({
path: `/posts/${postId}`,
});
},
updatePost({
postId, ...opts
}) {
return this._makeRequest({
method: "PUT",
path: `/posts/${postId}`,
...opts,
});
},
listCreatedPosts() {
return this._makeRequest({
path: "/posts/recentlyCreated",
});
},
listUpdatedPosts() {
return this._makeRequest({
path: "/posts/recentlyUpdated",
});
},
},
};
};
Loading

0 comments on commit dea586c

Please sign in to comment.