Skip to content

Commit 26d7e36

Browse files
committed
[Components] smstools #14370
Sources - New Inbound Message Actions - Add Contact - Add Contact Opt Out - Send SMS
1 parent 3429bf6 commit 26d7e36

File tree

7 files changed

+191
-276
lines changed

7 files changed

+191
-276
lines changed
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1+
import { ConfigurationError } from "@pipedream/platform";
12
import smstools from "../../smstools.app.mjs";
2-
import { axios } from "@pipedream/platform";
33

44
export default {
55
key: "smstools-add-contact-opt-out",
66
name: "Add Contact to Opt-Out List",
77
description: "Adds a selected contact to the opt-out list, stopping further communications. [See the documentation](https://www.smstools.com/en/sms-gateway-api/add_optout)",
8-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
smstools,
12-
contact: {
12+
contactNumber: {
1313
propDefinition: [
1414
smstools,
15-
"contact",
15+
"contactNumber",
1616
],
1717
},
1818
},
1919
async run({ $ }) {
20-
const response = await this.smstools.addOptOut({
21-
contactid: this.contact,
22-
});
20+
try {
21+
const response = await this.smstools.addOptOut({
22+
$,
23+
data: {
24+
number: this.contactNumber,
25+
},
26+
});
2327

24-
$.export("$summary", `Successfully added contact with ID ${this.contact} to the opt-out list.`);
25-
return response;
28+
$.export("$summary", `Successfully added contact number ${this.contactNumber} to the opt-out list.`);
29+
return response;
30+
} catch (e) {
31+
throw new ConfigurationError("The number is already opted-out or does not exist in the database.");
32+
}
2633
},
2734
};

components/smstools/actions/add-contact/add-contact.mjs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1+
import { ConfigurationError } from "@pipedream/platform";
12
import smstools from "../../smstools.app.mjs";
2-
import { axios } from "@pipedream/platform";
33

44
export default {
55
key: "smstools-add-contact",
66
name: "Add Contact to Group",
77
description: "Adds a new contact to an existing contact list. [See the documentation](https://www.smstools.com/en/sms-gateway-api/add_contact)",
8-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
smstools,
1212
phone: {
13-
propDefinition: [
14-
smstools,
15-
"phone",
16-
],
13+
type: "string",
14+
label: "Phone Number",
15+
description: "The phone number of the contact.",
1716
},
18-
groupId: {
17+
groupid: {
1918
propDefinition: [
2019
smstools,
2120
"groupId",
@@ -36,7 +35,7 @@ export default {
3635
birthday: {
3736
type: "string",
3837
label: "Birthday",
39-
description: "Birthday of the contact.",
38+
description: "Birthday of the contact. **Format: YYYY-MM-DD**.",
4039
optional: true,
4140
},
4241
extra1: {
@@ -95,24 +94,21 @@ export default {
9594
},
9695
},
9796
async run({ $ }) {
98-
const response = await this.smstools.addContactToGroup({
99-
phone: this.phone,
100-
groupId: this.groupId,
101-
firstname: this.firstName,
102-
lastname: this.lastName,
103-
birthday: this.birthday,
104-
extra1: this.extra1,
105-
extra2: this.extra2,
106-
extra3: this.extra3,
107-
extra4: this.extra4,
108-
extra5: this.extra5,
109-
extra6: this.extra6,
110-
extra7: this.extra7,
111-
extra8: this.extra8,
112-
unsubscribed: this.unsubscribed,
113-
});
97+
try {
98+
const {
99+
smstools,
100+
...data
101+
} = this;
102+
103+
const response = await smstools.addContact({
104+
$,
105+
data,
106+
});
114107

115-
$.export("$summary", `Successfully added contact with phone number ${this.phone}`);
116-
return response;
108+
$.export("$summary", `Successfully added contact with ID: ${response.ID}`);
109+
return response;
110+
} catch (e) {
111+
throw new ConfigurationError(e.response.data.errorMsg);
112+
}
117113
},
118114
};

components/smstools/actions/send-sms/send-sms.mjs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import smstools from "../../smstools.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "smstools-send-sms",
@@ -17,8 +16,10 @@ export default {
1716
to: {
1817
propDefinition: [
1918
smstools,
20-
"to",
19+
"contactNumber",
2120
],
21+
type: "string[]",
22+
description: "The contact(s) to send the message to.",
2223
},
2324
sender: {
2425
propDefinition: [
@@ -27,24 +28,21 @@ export default {
2728
],
2829
},
2930
date: {
30-
propDefinition: [
31-
smstools,
32-
"date",
33-
],
31+
type: "string",
32+
label: "Scheduled Date",
33+
description: "The date to send the message. **Format: yyyy-MM-dd HH:mm**. If not provided, the message will be sent as soon as possible.",
3434
optional: true,
3535
},
3636
reference: {
37-
propDefinition: [
38-
smstools,
39-
"reference",
40-
],
37+
type: "string",
38+
label: "Reference",
39+
description: "Reference for the message.",
4140
optional: true,
4241
},
4342
test: {
44-
propDefinition: [
45-
smstools,
46-
"test",
47-
],
43+
type: "boolean",
44+
label: "Test",
45+
description: "Test mode for the message.",
4846
optional: true,
4947
},
5048
subId: {
@@ -57,13 +55,16 @@ export default {
5755
},
5856
async run({ $ }) {
5957
const response = await this.smstools.sendMessage({
60-
message: this.message,
61-
to: this.to,
62-
sender: this.sender,
63-
date: this.date,
64-
reference: this.reference,
65-
test: this.test,
66-
subId: this.subId,
58+
$,
59+
data: {
60+
message: this.message,
61+
to: this.to,
62+
sender: this.sender,
63+
date: this.date,
64+
reference: this.reference,
65+
test: this.test,
66+
subId: this.subId,
67+
},
6768
});
6869
$.export("$summary", `Message sent successfully with ID: ${response.messageid}`);
6970
return response;

components/smstools/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/smstools",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream SMSTools Components",
55
"main": "smstools.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
}
1518
}

0 commit comments

Comments
 (0)