Skip to content

Commit 88c121a

Browse files
committed
daktela init
1 parent 8019f7e commit 88c121a

File tree

8 files changed

+513
-6
lines changed

8 files changed

+513
-6
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import daktela from "../../daktela.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "daktela-create-account",
6+
name: "Create Account",
7+
description: "Creates a new account on Daktela. [See the documentation](https://customer.daktela.com/apihelp/v6/global/general-information)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
daktela,
12+
user: {
13+
propDefinition: [
14+
daktela,
15+
"user",
16+
],
17+
optional: true,
18+
},
19+
sla: {
20+
propDefinition: [
21+
daktela,
22+
"sla",
23+
],
24+
optional: true,
25+
},
26+
survey: {
27+
propDefinition: [
28+
daktela,
29+
"survey",
30+
],
31+
optional: true,
32+
},
33+
name: {
34+
propDefinition: [
35+
daktela,
36+
"name",
37+
],
38+
optional: true,
39+
},
40+
title: {
41+
propDefinition: [
42+
daktela,
43+
"title",
44+
],
45+
optional: true,
46+
},
47+
description: {
48+
propDefinition: [
49+
daktela,
50+
"description",
51+
],
52+
optional: true,
53+
},
54+
},
55+
async run({ $ }) {
56+
const params = {
57+
user: this.user,
58+
sla: this.sla,
59+
survey: this.survey,
60+
name: this.name,
61+
title: this.title,
62+
description: this.description,
63+
};
64+
65+
const response = await this.daktela.createAccount(params);
66+
67+
$.export("$summary", `Successfully created account: ${response.title}`);
68+
return response;
69+
},
70+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import daktela from "../../daktela.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "daktela-make-call",
6+
name: "Initiate Phone Call",
7+
description: "Initiates a phone call via Daktela. [See the documentation](https://customer.daktela.com/apihelp/v6/working-with/call-activities)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
daktela,
12+
phoneNumber: {
13+
propDefinition: [
14+
daktela,
15+
"phoneNumber",
16+
],
17+
},
18+
callerNumber: {
19+
propDefinition: [
20+
daktela,
21+
"callerNumber",
22+
],
23+
optional: true,
24+
},
25+
callingTime: {
26+
propDefinition: [
27+
daktela,
28+
"callingTime",
29+
],
30+
optional: true,
31+
},
32+
},
33+
async run({ $ }) {
34+
const params = {
35+
phoneNumber: this.phoneNumber,
36+
callerNumber: this.callerNumber,
37+
callingTime: this.callingTime,
38+
};
39+
40+
const response = await this.daktela.initiateCall(params);
41+
$.export("$summary", `Successfully initiated call to ${this.phoneNumber}`);
42+
return response;
43+
},
44+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import daktela from "../../daktela.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "daktela-send-sms",
6+
name: "Send SMS",
7+
description: "Sends an SMS from the Daktela platform. [See the documentation](https://customer.daktela.com/apihelp/v6/working-with/sms-chat-activities)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
daktela,
12+
receiverNumber: {
13+
propDefinition: [
14+
daktela,
15+
"receiverNumber",
16+
],
17+
},
18+
textContent: {
19+
propDefinition: [
20+
daktela,
21+
"textContent",
22+
],
23+
},
24+
senderName: {
25+
propDefinition: [
26+
daktela,
27+
"senderName",
28+
],
29+
optional: true,
30+
},
31+
},
32+
async run({ $ }) {
33+
const params = {
34+
to: this.receiverNumber,
35+
text: this.textContent,
36+
from: this.senderName,
37+
};
38+
39+
const response = await this.daktela.sendSms(params);
40+
41+
$.export("$summary", `Successfully sent SMS to ${this.receiverNumber}`);
42+
return response;
43+
},
44+
};

components/daktela/daktela.app.mjs

Lines changed: 157 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,163 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "daktela",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
user: {
8+
type: "string",
9+
label: "User",
10+
description: "The user associated with the account",
11+
async options() {
12+
const users = await this.getUsers();
13+
return users.map((user) => ({
14+
label: user.name,
15+
value: user.id,
16+
}));
17+
},
18+
},
19+
sla: {
20+
type: "integer",
21+
label: "SLA",
22+
description: "The SLA ID for the account",
23+
optional: true,
24+
},
25+
survey: {
26+
type: "boolean",
27+
label: "Survey",
28+
description: "Indicate if a survey should be sent",
29+
optional: true,
30+
},
31+
name: {
32+
type: "string",
33+
label: "Name",
34+
description: "Unique identification for the account",
35+
optional: true,
36+
},
37+
title: {
38+
type: "string",
39+
label: "Title",
40+
description: "Display name for the account",
41+
optional: true,
42+
},
43+
description: {
44+
type: "string",
45+
label: "Description",
46+
description: "Optional description for the account",
47+
optional: true,
48+
},
49+
receiverNumber: {
50+
type: "string",
51+
label: "Receiver's Number",
52+
description: "The phone number to send the SMS to",
53+
},
54+
textContent: {
55+
type: "string",
56+
label: "Text Content",
57+
description: "The content of the SMS",
58+
},
59+
senderName: {
60+
type: "string",
61+
label: "Sender's Name",
62+
description: "Optional sender's name for the SMS",
63+
optional: true,
64+
},
65+
phoneNumber: {
66+
type: "string",
67+
label: "Phone Number to Call",
68+
description: "The phone number to initiate the call",
69+
},
70+
callerNumber: {
71+
type: "string",
72+
label: "Caller’s Number",
73+
description: "The number being used to make the call",
74+
optional: true,
75+
},
76+
callingTime: {
77+
type: "string",
78+
label: "Calling Time",
79+
description: "Time to initiate the call",
80+
optional: true,
81+
},
82+
},
583
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
84+
_baseUrl() {
85+
return "https://customer.daktela.com/api/v6";
86+
},
87+
async _makeRequest(opts = {}) {
88+
const {
89+
$ = this, method = "GET", path = "/", headers, ...otherOpts
90+
} = opts;
91+
return axios($, {
92+
...otherOpts,
93+
method,
94+
url: this._baseUrl() + path,
95+
headers: {
96+
...headers,
97+
"Content-Type": "application/json",
98+
"Authorization": `Bearer ${this.$auth.access_token}`,
99+
},
100+
});
101+
},
102+
async createAccount(params) {
103+
return this._makeRequest({
104+
method: "POST",
105+
path: "/accounts",
106+
data: params,
107+
});
108+
},
109+
async sendSms(params) {
110+
return this._makeRequest({
111+
method: "POST",
112+
path: "/sms_activities",
113+
data: params,
114+
});
115+
},
116+
async initiateCall(params) {
117+
return this._makeRequest({
118+
method: "POST",
119+
path: "/call_activities",
120+
data: params,
121+
});
122+
},
123+
async getUsers(opts = {}) {
124+
return this._makeRequest({
125+
path: "/users",
126+
...opts,
127+
});
128+
},
129+
async emitNewAccountCreated() {
130+
const accounts = await this._makeRequest({
131+
path: "/accounts",
132+
});
133+
accounts.forEach((account) => {
134+
this.$emit(account, {
135+
summary: `New account created: ${account.title}`,
136+
id: account.account,
137+
});
138+
});
139+
},
140+
async emitTicketUpdated() {
141+
const tickets = await this._makeRequest({
142+
path: "/tickets",
143+
});
144+
tickets.forEach((ticket) => {
145+
this.$emit(ticket, {
146+
summary: `Ticket updated: ${ticket.title}`,
147+
id: ticket.ticket,
148+
});
149+
});
150+
},
151+
async emitNewContactAdded() {
152+
const contacts = await this._makeRequest({
153+
path: "/contacts",
154+
});
155+
contacts.forEach((contact) => {
156+
this.$emit(contact, {
157+
summary: `New contact added: ${contact.firstname} ${contact.lastname}`,
158+
id: contact.contact,
159+
});
160+
});
9161
},
10162
},
11-
};
163+
};

components/daktela/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)