Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Go Dial

* Added actions and sources

* Package.json new line

* Fixed

* Fixed bug on select teams

* Fixed bug on select teams
  • Loading branch information
lcaresia authored Apr 15, 2023
1 parent ae2ed71 commit 18436e6
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 21 deletions.
3 changes: 0 additions & 3 deletions components/godial/.gitignore

This file was deleted.

52 changes: 52 additions & 0 deletions components/godial/action/add-contact/add-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import godial from "../../app/godial.app.mjs";

export default {
name: "Add Contact",
version: "0.0.1",
key: "godial-add-contact",
description: "Adds a contact. [See docs here](https://godial.stoplight.io/docs/godial/b3A6MzAzMTY2Mg-contact-add)",
type: "action",
props: {
godial,
listId: {
propDefinition: [
godial,
"listId",
],
},
phone: {
type: "string",
label: "Phone",
description: "The phone of the contact to add",
},
name: {
type: "string",
label: "Name",
description: "The name of the contact to add",
optional: true,
},
email: {
type: "string",
label: "Email",
description: "The email of the contact to add",
optional: true,
},
},
async run({ $ }) {
const response = await this.godial.addContact({
$,
data: {
listId: this.listId,
name: this.name,
email: this.email,
phone: this.phone,
},
});

if (response) {
$.export("$summary", `Successfully added contact with ID ${response.id}`);
}

return response;
},
};
78 changes: 78 additions & 0 deletions components/godial/action/add-member/add-member.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { ConfigurationError } from "@pipedream/platform";
import godial from "../../app/godial.app.mjs";
import constants from "../common/constants.mjs";

export default {
name: "Add Member",
version: "0.0.1",
key: "godial-add-member",
description: "Adds a member. [See docs here](https://godial.stoplight.io/docs/godial/b3A6MzAzMTY1Ng-accounts-add)",
type: "action",
props: {
godial,
teamsId: {
label: "Teams ID",
type: "string[]",
propDefinition: [
godial,
"teamId",
],
},
name: {
type: "string",
label: "Name",
description: "The name of the member to add",
},
email: {
type: "string",
label: "Email",
description: "The email of the member to add",
optional: true,
},
username: {
type: "string",
label: "Username",
description: "The username of the member to add",
},
password: {
type: "string",
label: "Password",
description: "The password of the member to add",
secret: true,
},
role: {
type: "string",
label: "Role",
description: "The role of the member to add",
options: constants.ROLES,
},
},
async run({ $ }) {
console.log(this.teamsId);
this.teamsId = typeof this.teamsId === "string"
? JSON.parse(this.teamsId)
: this.teamsId;

if (!this.teamsId || !this.teamsId?.length) {
throw new ConfigurationError("TeamsId is required");
}

const response = await this.godial.addMember({
$,
data: {
teamsId: this.teamsId,
name: this.name,
email: this.email,
username: this.username,
password: this.password,
role: this.role,
},
});

if (response) {
$.export("$summary", `Successfully added member with ID ${response.id}`);
}

return response;
},
};
7 changes: 7 additions & 0 deletions components/godial/action/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
ROLES: [
"Manager",
"SubManager",
"Agent",
],
};
95 changes: 95 additions & 0 deletions components/godial/app/godial.app.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "godial",
propDefinitions: {
teamId: {
label: "Team ID",
description: "The team ID",
type: "string",
async options() {
const teams = await this.getTeams();

return teams.map((team) => ({
value: team.id,
label: team.name,
}));
},
},
listId: {
label: "List ID",
description: "The list ID",
type: "string",
async options() {
const lists = await this.getLists();

return lists.map((list) => ({
value: list.id,
label: list.name,
}));
},
},
},
methods: {
_apiToken() {
return this.$auth.api_token;
},
_apiUrl() {
return "https://enterprise.godial.cc/meta/api";
},
async _makeRequest({
$ = this, path, ...args
}) {
return axios($, {
url: `${this._apiUrl()}${path}`,
...args,
params: {
...args.params,
access_token: this._apiToken(),
},
});
},
async addList(args = {}) {
return this._makeRequest({
path: "/externals/lists/add",
method: "post",
...args,
});
},
async addContact(args = {}) {
return this._makeRequest({
path: "/externals/contact/add",
method: "post",
...args,
});
},
async addMember(args = {}) {
return this._makeRequest({
path: "/externals/accounts/add",
method: "post",
...args,
});
},
async getTeams(args = {}) {
return this._makeRequest({
path: "/externals/team/list",
...args,
});
},
async getLists(args = {}) {
return this._makeRequest({
path: "/externals/lists/list",
...args,
});
},
async getContacts({
listId, ...args
}) {
return this._makeRequest({
path: `/externals/contact/list/${listId}`,
...args,
});
},
},
};
13 changes: 0 additions & 13 deletions components/godial/app/godial.app.ts

This file was deleted.

7 changes: 2 additions & 5 deletions components/godial/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
{
"name": "@pipedream/godial",
"version": "0.0.3",
"version": "0.0.4",
"description": "Pipedream GoDial Components",
"main": "dist/app/godial.app.mjs",
"main": "app/godial.app.mjs",
"keywords": [
"pipedream",
"godial"
],
"files": [
"dist"
],
"homepage": "https://pipedream.com/apps/godial",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import godial from "../../app/godial.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
name: "New Updated Contact",
version: "0.0.3",
key: "godial-new-updated-contact",
description: "Emit new event on a contact is updated.",
type: "source",
dedupe: "unique",
props: {
godial,
db: "$.service.db",
timer: {
type: "$.interface.timer",
static: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
listId: {
propDefinition: [
godial,
"listId",
],
},
},
methods: {
emitEvent(data) {
if (!data.modifiedOn) {
return;
}

this.$emit(data, {
id: `${data.id} - ${data.modifiedOn}`,
summary: `New contact updated with ID ${data.id}`,
ts: Date.parse(data.modifiedOn),
});
},
},
async run() {
const contacts = await this.godial.getContacts({
listId: this.listId,
});

contacts.reverse().forEach(this.emitEvent);
},
};

0 comments on commit 18436e6

Please sign in to comment.