Skip to content

Commit 04ae144

Browse files
committed
[Components] textline - new components
1 parent 0193d17 commit 04ae144

File tree

7 files changed

+430
-7
lines changed

7 files changed

+430
-7
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import app from "../../textline.app.mjs";
2+
3+
export default {
4+
key: "textline-create-update-contact",
5+
name: "Create Or Update Contact",
6+
description: "Create or update a contact in the Textline address book. [See the documentation](https://textline.docs.apiary.io/#reference/customers/customers/create-a-customer).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
phoneNumber: {
12+
propDefinition: [
13+
app,
14+
"phoneNumber",
15+
],
16+
},
17+
email: {
18+
type: "string",
19+
label: "Email",
20+
description: "The email of the contact.",
21+
optional: true,
22+
},
23+
name: {
24+
type: "string",
25+
label: "Name",
26+
description: "The name of the contact.",
27+
optional: true,
28+
},
29+
notes: {
30+
type: "string",
31+
label: "Notes",
32+
description: "Notes about the contact.",
33+
optional: true,
34+
},
35+
tags: {
36+
type: "string[]",
37+
label: "Tags",
38+
description: "Tags associated with the contact.",
39+
optional: true,
40+
},
41+
},
42+
methods: {
43+
updateCustomer({
44+
uuid, ...args
45+
} = {}) {
46+
return this.app.put({
47+
path: `/customer/${uuid}`,
48+
...args,
49+
});
50+
},
51+
createCustomer(args = {}) {
52+
return this.app.post({
53+
path: "/customers",
54+
...args,
55+
});
56+
},
57+
},
58+
async run({ $ }) {
59+
const {
60+
app,
61+
updateCustomer,
62+
createCustomer,
63+
phoneNumber,
64+
email,
65+
name,
66+
notes,
67+
tags,
68+
} = this;
69+
70+
let response;
71+
let uuid;
72+
73+
try {
74+
response = await createCustomer({
75+
$,
76+
data: {
77+
customer: {
78+
phone_number: phoneNumber,
79+
email,
80+
name,
81+
notes,
82+
tags,
83+
},
84+
},
85+
});
86+
} catch (error) {
87+
if (error.response.status === 400 && error.response.data?.errors?.phone_number[0] === "Already in use") {
88+
89+
({ customer: { uuid } } = await app.getCustomerByPhoneNumber({
90+
$,
91+
params: {
92+
phone_number: phoneNumber,
93+
},
94+
}));
95+
96+
} else {
97+
throw error;
98+
}
99+
}
100+
101+
if (!uuid) {
102+
$.export("$summary", `Successfully created the contact with uuid \`${response.customer.uuid}\`.`);
103+
return response;
104+
}
105+
106+
response = await updateCustomer({
107+
$,
108+
uuid,
109+
data: {
110+
customer: {
111+
email,
112+
name,
113+
notes,
114+
tags,
115+
},
116+
},
117+
});
118+
119+
$.export("$summary", `Successfully updated the contact with uuid \`${uuid}\`.`);
120+
return response;
121+
},
122+
};
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import app from "../../textline.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "textline-send-announcement",
6+
name: "Send Announcement",
7+
description: "Send an announcement to a group of contacts. [See the documentation](https://textline.docs.apiary.io/#reference/messaging-tools/announcements/send-an-announcement).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
massTextGroupUuid: {
13+
label: "Mass Text Group UUID",
14+
description: "The UUID of the mass text group.",
15+
propDefinition: [
16+
app,
17+
"groupUuid",
18+
],
19+
},
20+
massTextCommentBody: {
21+
type: "string",
22+
label: "Mass Text Comment Body",
23+
description: "The content of the message to send.",
24+
},
25+
massTextTitle: {
26+
type: "string",
27+
label: "Mass Text Title",
28+
description: "The title of the message.",
29+
},
30+
selectionType: {
31+
type: "string",
32+
label: "Selection Type",
33+
description: "The type of the selection for the announcement.",
34+
reloadProps: true,
35+
options: Object.values(constants.SELECTION_TYPE),
36+
},
37+
},
38+
additionalProps() {
39+
const { selectionType } = this;
40+
41+
if (selectionType === constants.SELECTION_TYPE.TAGS.value) {
42+
return {
43+
tag: {
44+
type: "string",
45+
label: "Tag",
46+
description: "Send to all contacts with this tag.",
47+
},
48+
};
49+
}
50+
51+
if (selectionType === constants.SELECTION_TYPE.PHONE_NUMBERS.value) {
52+
return {
53+
phoneNumbers: {
54+
type: "string[]",
55+
label: "Phone Numbers",
56+
description: "The phone numbers to send the announcement to.",
57+
useQuery: true,
58+
options: async ({
59+
page, query,
60+
}) => {
61+
const { customers } = await this.app.listCustomers({
62+
params: {
63+
page,
64+
page_size: 30,
65+
query: query || "",
66+
},
67+
});
68+
return customers.map(({
69+
name: label, phone_number: value,
70+
}) => ({
71+
label,
72+
value,
73+
}));
74+
},
75+
},
76+
};
77+
}
78+
79+
return {};
80+
},
81+
methods: {
82+
sendAnnouncement(args = {}) {
83+
return this.app.post({
84+
path: "/announcements",
85+
...args,
86+
});
87+
},
88+
},
89+
async run({ $ }) {
90+
const {
91+
sendAnnouncement,
92+
selectionType,
93+
massTextGroupUuid,
94+
massTextCommentBody,
95+
massTextTitle,
96+
tag,
97+
phoneNumbers,
98+
} = this;
99+
100+
const response = await sendAnnouncement({
101+
$,
102+
data: {
103+
selection_type: selectionType,
104+
recipients: {
105+
tag,
106+
phone_numbers: phoneNumbers,
107+
},
108+
mass_text: {
109+
group_uuid: massTextGroupUuid,
110+
comment_body: massTextCommentBody,
111+
title: massTextTitle,
112+
},
113+
},
114+
});
115+
116+
$.export("$summary", "Successfully sent the announcement.");
117+
return response;
118+
},
119+
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import app from "../../textline.app.mjs";
2+
3+
export default {
4+
key: "textline-send-message",
5+
name: "Send Message",
6+
description: "Send a new message directly to a contact. [See the documentation](https://textline.docs.apiary.io/#reference/conversations/group-conversations/message-a-phone-number).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
phoneNumber: {
12+
propDefinition: [
13+
app,
14+
"phoneNumber",
15+
],
16+
},
17+
comment: {
18+
type: "string",
19+
label: "Message",
20+
description: "The content of the message to send.",
21+
},
22+
},
23+
methods: {
24+
sendMessage(args = {}) {
25+
return this.app.post({
26+
path: "/conversations",
27+
...args,
28+
});
29+
},
30+
},
31+
async run({ $ }) {
32+
const {
33+
sendMessage,
34+
phoneNumber,
35+
comment,
36+
} = this;
37+
const response = await sendMessage({
38+
$,
39+
data: {
40+
phone_number: phoneNumber,
41+
comment: {
42+
body: comment,
43+
},
44+
resolve: "1",
45+
},
46+
});
47+
48+
$.export("$summary", `Successfully sent message to ${phoneNumber}.`);
49+
return response;
50+
},
51+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const BASE_URL = "https://application.textline.com";
2+
const VERSION_PATH = "/api";
3+
const DEFAULT_LIMIT = 30;
4+
5+
const SELECTION_TYPE = {
6+
TAGS: {
7+
label: "Tags",
8+
value: "tags",
9+
},
10+
PHONE_NUMBERS: {
11+
label: "Phone Numbers",
12+
value: "phone_numbers",
13+
},
14+
};
15+
16+
export default {
17+
BASE_URL,
18+
VERSION_PATH,
19+
DEFAULT_LIMIT,
20+
SELECTION_TYPE,
21+
};

components/textline/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/textline",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Textline Components",
55
"main": "textline.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)