Skip to content

Commit

Permalink
adhook init
Browse files Browse the repository at this point in the history
  • Loading branch information
luancazarine committed Sep 12, 2024
1 parent d81cb68 commit 03b056d
Show file tree
Hide file tree
Showing 7 changed files with 631 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import adhook from "../../adhook.app.mjs";
import { axios } from "@pipedream/platform";

Check failure on line 2 in components/adhook/actions/create-calendar-event/create-calendar-event.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'axios' is defined but never used

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.{{ts}}",
type: "action",
props: {
adhook,
eventName: {
propDefinition: [
adhook,
"eventName",
],
},
startDate: {
propDefinition: [
adhook,
"startDate",
],
},
endDate: {
propDefinition: [
adhook,
"endDate",
],
},
eventDescription: {
propDefinition: [
adhook,
"eventDescription",
],
optional: true,
},
attendees: {
propDefinition: [
adhook,
"attendees",
],
optional: true,
},
attachments: {
propDefinition: [
adhook,
"attachments",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.adhook.createCalendarEvent({
data: {
eventName: this.eventName,
startDate: this.startDate,
endDate: this.endDate,
eventDescription: this.eventDescription,
attendees: this.attendees,
attachments: this.attachments,
},
});

$.export("$summary", `Successfully created calendar event: ${this.eventName}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import adhook from "../../adhook.app.mjs";
import { axios } from "@pipedream/platform";

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.{{ts}}",
type: "action",
props: {
adhook,
postId: {
propDefinition: [
adhook,
"postId",
],
optional: true,
},
postContent: {
propDefinition: [
adhook,
"postContent",
],
},
visibility: {
propDefinition: [
adhook,
"visibility",
],
},
postAttachments: {
propDefinition: [
adhook,
"postAttachments",
],
optional: true,
},
mentionUsers: {
propDefinition: [
adhook,
"mentionUsers",
],
optional: true,
},
},
async run({ $ }) {
const data = {
postContent: this.postContent,
visibility: this.visibility,
postAttachments: this.postAttachments,
mentionUsers: this.mentionUsers,
};

if (this.postId) {
data.postId = this.postId;
}

const response = await axios($, {
method: "POST",
url: `${this.adhook._baseUrl()}/posts`,
headers: {
Authorization: `Bearer ${this.adhook.$auth.oauth_access_token}`,
},
data,
});

$.export("$summary", `Successfully ${this.postId
? "updated"
: "created"} post`);
return response;
},
};
181 changes: 178 additions & 3 deletions components/adhook/adhook.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,186 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "adhook",
propDefinitions: {},
propDefinitions: {
postType: {
type: "string",
label: "Post Type",
description: "The type of the post",
optional: true,
},
postAuthor: {
type: "string",
label: "Post Author",
description: "The author of the post",
optional: true,
},
postTags: {
type: "string[]",
label: "Post Tags",
description: "Tags associated with the post",
optional: true,
},
postId: {
type: "string",
label: "Post ID",
description: "The ID of the post",
},
isNew: {
type: "boolean",
label: "Is New",
description: "Indicates if the post is new",
optional: true,
},
updateType: {
type: "string",
label: "Update Type",
description: "Type of update made to the post",
optional: true,
},
eventName: {
type: "string",
label: "Event Name",
description: "Name of the calendar event",
},
startDate: {
type: "string",
label: "Start Date",
description: "Start date of the event",
},
endDate: {
type: "string",
label: "End Date",
description: "End date of the event",
},
eventDescription: {
type: "string",
label: "Event Description",
description: "Description of the event",
optional: true,
},
attendees: {
type: "string[]",
label: "Attendees",
description: "List of attendees for the event",
optional: true,
},
attachments: {
type: "string[]",
label: "Attachments",
description: "Attachments for the event",
optional: true,
},
postContent: {
type: "string",
label: "Post Content",
description: "Content of the post",
},
visibility: {
type: "string",
label: "Visibility",
description: "Visibility setting of the post",
},
postAttachments: {
type: "string[]",
label: "Post Attachments",
description: "Attachments for the post",
optional: true,
},
mentionUsers: {
type: "string[]",
label: "Mention Users",
description: "Users to mention in the post",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
_baseUrl() {
return "https://app.adhook.io/api";
},
async _makeRequest(opts = {}) {
const {
$ = this, method = "GET", path = "/", headers, ...otherOpts
} = opts;
return axios($, {
...otherOpts,
method,
url: this._baseUrl() + path,
headers: {
...headers,
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
},
});
},
async emitNewPostEvent(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/events/new_post",
data: {
postType: this.postType,
postAuthor: this.postAuthor,
postTags: this.postTags,
},
...opts,
});
},
async emitPostCreatedOrUpdatedEvent(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/events/post_created_or_updated",
data: {
postId: this.postId,
postAuthor: this.postAuthor,
postTags: this.postTags,
isNew: this.isNew,
},
...opts,
});
},
async emitPostUpdatedEvent(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/events/post_updated",
data: {
postId: this.postId,
postAuthor: this.postAuthor,
postTags: this.postTags,
updateType: this.updateType,
},
...opts,
});
},
async createCalendarEvent(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/events/calendar",
data: {
eventName: this.eventName,
startDate: this.startDate,
endDate: this.endDate,
eventDescription: this.eventDescription,
attendees: this.attendees,
attachments: this.attachments,
},
...opts,
});
},
async addOrUpdatePost(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/posts",
data: {
postContent: this.postContent,
visibility: this.visibility,
postAttachments: this.postAttachments,
mentionUsers: this.mentionUsers,
},
...opts,
});
},
authKeys() {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/adhook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"publishConfig": {
"access": "public"
}
}
}
Loading

0 comments on commit 03b056d

Please sign in to comment.