Skip to content

Commit 855a266

Browse files
lcaresiamalexanderlim
authored andcommitted
[Components] liveswitch #13859 (#14427)
* Added actions * Fixing action name
1 parent 9a16df6 commit 855a266

File tree

6 files changed

+307
-59
lines changed

6 files changed

+307
-59
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import app from "../../liveswitch.app.mjs";
2+
3+
export default {
4+
key: "liveswitch-create-contact",
5+
name: "Create Contact",
6+
description: "Create a contact in LiveSwitch [See the documentation](https://developer.liveswitch.com/reference/post_v1-contacts)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
phone: {
12+
propDefinition: [
13+
app,
14+
"phone",
15+
],
16+
},
17+
firstName: {
18+
propDefinition: [
19+
app,
20+
"firstName",
21+
],
22+
},
23+
lastName: {
24+
propDefinition: [
25+
app,
26+
"lastName",
27+
],
28+
},
29+
email: {
30+
propDefinition: [
31+
app,
32+
"email",
33+
],
34+
},
35+
},
36+
37+
async run({ $ }) {
38+
const response = await this.app.createContact({
39+
$,
40+
data: {
41+
phone: this.phone,
42+
firstName: this.firstName,
43+
lastName: this.lastName,
44+
email: this.email,
45+
},
46+
});
47+
48+
$.export("$summary", `Successfully created Contact with ID: ${response.id}`);
49+
50+
return response;
51+
},
52+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import app from "../../liveswitch.app.mjs";
2+
3+
export default {
4+
key: "liveswitch-create-conversation",
5+
name: "Create Conversation",
6+
description: "Create a conversation in LiveSwitch [See the documentation](https://developer.liveswitch.com/reference/post_v1-conversations)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
contactId: {
12+
propDefinition: [
13+
app,
14+
"contactId",
15+
],
16+
},
17+
message: {
18+
propDefinition: [
19+
app,
20+
"message",
21+
],
22+
},
23+
},
24+
25+
async run({ $ }) {
26+
const response = await this.app.createConversation({
27+
$,
28+
data: {
29+
contactId: this.contactId,
30+
message: this.message,
31+
},
32+
});
33+
34+
$.export("$summary", `Successfully created Conversation with ID: ${response.id}`);
35+
36+
return response;
37+
},
38+
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import app from "../../liveswitch.app.mjs";
2+
3+
export default {
4+
key: "liveswitch-update-contact",
5+
name: "Update Contact",
6+
description: "Update a contact in LiveSwitch [See the documentation](https://developer.liveswitch.com/reference/post_v1-contacts)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
contactId: {
12+
propDefinition: [
13+
app,
14+
"contactId",
15+
],
16+
},
17+
phone: {
18+
propDefinition: [
19+
app,
20+
"phone",
21+
],
22+
},
23+
firstName: {
24+
propDefinition: [
25+
app,
26+
"firstName",
27+
],
28+
},
29+
lastName: {
30+
propDefinition: [
31+
app,
32+
"lastName",
33+
],
34+
},
35+
email: {
36+
propDefinition: [
37+
app,
38+
"email",
39+
],
40+
},
41+
},
42+
43+
async run({ $ }) {
44+
const response = await this.app.updateContact({
45+
$,
46+
contactId: this.contactId,
47+
data: {
48+
phone: this.phone,
49+
firstName: this.firstName,
50+
lastName: this.lastName,
51+
email: this.email,
52+
},
53+
});
54+
55+
$.export("$summary", `Successfully updated Contact with ID: ${this.contactId}`);
56+
57+
return response;
58+
},
59+
};
Lines changed: 98 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,104 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "liveswitch",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
firstName: {
8+
type: "string",
9+
label: "First Name",
10+
description: "Contact's first name",
11+
optional: true,
12+
},
13+
lastName: {
14+
type: "string",
15+
label: "Last Name",
16+
description: "Contact's last name",
17+
optional: true,
18+
},
19+
email: {
20+
type: "string",
21+
label: "Email",
22+
description: "Contact's email",
23+
optional: true,
24+
},
25+
phone: {
26+
type: "string",
27+
label: "Phone",
28+
description: "Contact's phone number, i.e.: `+1 407-982-1211`",
29+
},
30+
message: {
31+
type: "string",
32+
label: "Message",
33+
description: "The contents of the text message the user will receive",
34+
},
35+
contactId: {
36+
type: "string",
37+
label: "Contact ID",
38+
description: "Contact's ID",
39+
async options() {
40+
const response = await this.getContacts();
41+
return response.map(({
42+
id, firstName, lastName,
43+
}) => ({
44+
value: id,
45+
label: `${firstName} ${lastName}`,
46+
}));
47+
},
48+
},
49+
},
550
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
51+
_baseUrl() {
52+
return "https://public-api.production.liveswitch.com/v1";
53+
},
54+
async _makeRequest(opts = {}) {
55+
const {
56+
$ = this,
57+
path,
58+
headers,
59+
...otherOpts
60+
} = opts;
61+
return axios($, {
62+
...otherOpts,
63+
url: this._baseUrl() + path,
64+
headers: {
65+
...headers,
66+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
67+
},
68+
});
69+
},
70+
async createContact(args = {}) {
71+
return this._makeRequest({
72+
path: "/contacts",
73+
method: "post",
74+
...args,
75+
});
76+
},
77+
async updateContact({
78+
contactId, ...args
79+
}) {
80+
return this._makeRequest({
81+
path: `/contacts/${contactId}`,
82+
method: "put",
83+
...args,
84+
});
85+
},
86+
async createConversation(args = {}) {
87+
return this._makeRequest({
88+
path: "/conversations",
89+
method: "post",
90+
...args,
91+
});
92+
},
93+
async getContacts(args = {}) {
94+
return this._makeRequest({
95+
path: "/contacts",
96+
params: {
97+
page: 1,
98+
pageSize: 100,
99+
},
100+
...args,
101+
});
9102
},
10103
},
11-
};
104+
};

components/liveswitch/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/liveswitch",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream LiveSwitch Components",
55
"main": "liveswitch.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)