@pipedream/twilio 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/actions/delete-call/delete-call.mjs +1 -1
- package/actions/delete-message/delete-message.mjs +1 -1
- package/actions/download-recording-media/download-recording-media.mjs +1 -1
- package/actions/get-call/get-call.mjs +3 -2
- package/actions/get-message/get-message.mjs +3 -2
- package/actions/list-calls/list-calls.mjs +2 -2
- package/actions/list-message-media/list-message-media.mjs +2 -2
- package/actions/list-messages/list-messages.mjs +3 -3
- package/actions/list-recording-transcriptions/list-recording-transcriptions.mjs +2 -2
- package/actions/make-phone-call/make-phone-call.mjs +4 -4
- package/actions/send-mms/send-mms.mjs +4 -4
- package/actions/send-sms/send-sms.mjs +4 -4
- package/common/constants.mjs +13 -0
- package/{utils.mjs → common/utils.mjs} +0 -3
- package/package.json +2 -1
- package/sources/common-webhook.mjs +30 -33
- package/sources/new-call/new-call.mjs +5 -5
- package/sources/new-incoming-sms/new-incoming-sms.mjs +7 -6
- package/sources/new-phone-number/new-phone-number.mjs +2 -2
- package/sources/new-recording/new-recording.mjs +3 -3
- package/sources/new-transcription/new-transcription.mjs +2 -2
- package/twilio.app.mjs +55 -60
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Overview
|
|
2
|
+
|
|
3
|
+
With the Twilio API, you can build telephone applications that make and receive
|
|
4
|
+
phone calls, as well astext messaging applications that send and receive text
|
|
5
|
+
messages.
|
|
6
|
+
|
|
7
|
+
Some examples of applications you could build include:
|
|
8
|
+
|
|
9
|
+
- A phone call application that allows you to make and receive phone calls over
|
|
10
|
+
the internet
|
|
11
|
+
- A text messaging application that allows you to send and receive text
|
|
12
|
+
messages over the internet
|
|
13
|
+
- A voicemail application that allows you to leave and receive voicemails over
|
|
14
|
+
the internet
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "twilio-delete-call",
|
|
5
5
|
name: "Delete Call",
|
|
6
6
|
description: "Remove a call record from your account. [See the docs](https://www.twilio.com/docs/voice/api/call-resource#delete-a-call-resource) for more information",
|
|
7
|
-
version: "0.0
|
|
7
|
+
version: "0.1.0",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
twilio,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "twilio-delete-message",
|
|
5
5
|
name: "Delete Message",
|
|
6
6
|
description: "Delete a message record from your account. [See the docs](https://www.twilio.com/docs/sms/api/message-resource#delete-a-message-resource) for more information",
|
|
7
|
-
version: "0.0
|
|
7
|
+
version: "0.1.0",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
twilio,
|
|
@@ -8,7 +8,7 @@ export default {
|
|
|
8
8
|
key: "twilio-download-recording-media",
|
|
9
9
|
name: "Download Recording Media",
|
|
10
10
|
description: "Download a recording media file. [See the docs](https://www.twilio.com/docs/voice/api/recording#fetch-a-recording-media-file) for more information",
|
|
11
|
-
version: "0.0
|
|
11
|
+
version: "0.1.0",
|
|
12
12
|
type: "action",
|
|
13
13
|
props: {
|
|
14
14
|
twilio,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import twilio from "../../twilio.app.mjs";
|
|
2
|
+
import { callToString } from "../../common/utils.mjs";
|
|
2
3
|
|
|
3
4
|
export default {
|
|
4
5
|
key: "twilio-get-call",
|
|
5
6
|
name: "Get Call",
|
|
6
7
|
description: "Return call resource of an individual call. [See the docs](https://www.twilio.com/docs/voice/api/call-resource#fetch-a-call-resource) for more information",
|
|
7
|
-
version: "0.0
|
|
8
|
+
version: "0.1.0",
|
|
8
9
|
type: "action",
|
|
9
10
|
props: {
|
|
10
11
|
twilio,
|
|
@@ -17,7 +18,7 @@ export default {
|
|
|
17
18
|
},
|
|
18
19
|
async run({ $ }) {
|
|
19
20
|
const resp = await this.twilio.getCall(this.sid);
|
|
20
|
-
$.export("$summary", `Successfully fetched the call, "${
|
|
21
|
+
$.export("$summary", `Successfully fetched the call, "${callToString(resp)}"`);
|
|
21
22
|
return resp;
|
|
22
23
|
},
|
|
23
24
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import twilio from "../../twilio.app.mjs";
|
|
2
|
+
import { messageToString } from "../../common/utils.mjs";
|
|
2
3
|
|
|
3
4
|
export default {
|
|
4
5
|
key: "twilio-get-message",
|
|
5
6
|
name: "Get Message",
|
|
6
7
|
description: "Return details of a message. [See the docs](https://www.twilio.com/docs/sms/api/message-resource#fetch-a-message-resource) for more information",
|
|
7
|
-
version: "0.0
|
|
8
|
+
version: "0.1.0",
|
|
8
9
|
type: "action",
|
|
9
10
|
props: {
|
|
10
11
|
twilio,
|
|
@@ -17,7 +18,7 @@ export default {
|
|
|
17
18
|
},
|
|
18
19
|
async run({ $ }) {
|
|
19
20
|
const resp = await this.twilio.getMessage(this.messageId);
|
|
20
|
-
$.export("$summary", `Successfully fetched the message, "${
|
|
21
|
+
$.export("$summary", `Successfully fetched the message, "${messageToString(resp)}"`);
|
|
21
22
|
return resp;
|
|
22
23
|
},
|
|
23
24
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import twilio from "../../twilio.app.mjs";
|
|
2
|
-
import { omitEmptyStringValues } from "../../utils.mjs";
|
|
2
|
+
import { omitEmptyStringValues } from "../../common/utils.mjs";
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
key: "twilio-list-calls",
|
|
6
6
|
name: "List Calls",
|
|
7
7
|
description: "Return a list of calls associated with your account. [See the docs](https://www.twilio.com/docs/voice/api/call-resource#read-multiple-call-resources) for more information",
|
|
8
|
-
version: "0.0
|
|
8
|
+
version: "0.1.0",
|
|
9
9
|
type: "action",
|
|
10
10
|
props: {
|
|
11
11
|
twilio,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import twilio from "../../twilio.app.mjs";
|
|
2
|
-
import { omitEmptyStringValues } from "../../utils.mjs";
|
|
2
|
+
import { omitEmptyStringValues } from "../../common/utils.mjs";
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
key: "twilio-list-message-media",
|
|
6
6
|
name: "List Message Media",
|
|
7
7
|
description: "Return a list of media associated with your message. [See the docs](https://www.twilio.com/docs/sms/api/media-resource#read-multiple-media-resources) for more information",
|
|
8
|
-
version: "0.0
|
|
8
|
+
version: "0.1.0",
|
|
9
9
|
type: "action",
|
|
10
10
|
props: {
|
|
11
11
|
twilio,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import twilio from "../../twilio.app.mjs";
|
|
2
1
|
import { phone } from "phone";
|
|
3
|
-
import
|
|
2
|
+
import twilio from "../../twilio.app.mjs";
|
|
3
|
+
import { omitEmptyStringValues } from "../../common/utils.mjs";
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
6
|
key: "twilio-list-messages",
|
|
7
7
|
name: "List Messages",
|
|
8
8
|
description: "Return a list of messages associated with your account. [See the docs](https://www.twilio.com/docs/sms/api/message-resource#read-multiple-message-resources) for more information",
|
|
9
|
-
version: "0.0
|
|
9
|
+
version: "0.1.0",
|
|
10
10
|
type: "action",
|
|
11
11
|
props: {
|
|
12
12
|
twilio,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import twilio from "../../twilio.app.mjs";
|
|
2
|
-
import { omitEmptyStringValues } from "../../utils.mjs";
|
|
2
|
+
import { omitEmptyStringValues } from "../../common/utils.mjs";
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
key: "twilio-list-recording-transcriptions",
|
|
6
6
|
name: "List Recording Transcriptions",
|
|
7
7
|
description: "Return a set of transcriptions available for a recording. [See the docs](https://www.twilio.com/docs/voice/api/recording#fetch-a-recordings-transcriptions) for more information",
|
|
8
|
-
version: "0.0
|
|
8
|
+
version: "0.1.0",
|
|
9
9
|
type: "action",
|
|
10
10
|
props: {
|
|
11
11
|
twilio,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
// Read the Twilio docs at https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource
|
|
2
|
-
import twilio from "../../twilio.app.mjs";
|
|
3
1
|
import { phone } from "phone";
|
|
2
|
+
import twilio from "../../twilio.app.mjs";
|
|
3
|
+
import { callToString } from "../../common/utils.mjs";
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
6
|
key: "twilio-make-phone-call",
|
|
7
7
|
name: "Make a Phone Call",
|
|
8
8
|
description: "Make a phone call, passing text that Twilio will speak to the recipient of the call. [See the docs](https://www.twilio.com/docs/voice/api/call-resource#create-a-call-resource) for more information",
|
|
9
|
-
version: "0.0
|
|
9
|
+
version: "0.1.0",
|
|
10
10
|
type: "action",
|
|
11
11
|
props: {
|
|
12
12
|
twilio,
|
|
@@ -46,7 +46,7 @@ export default {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
const resp = await this.twilio.getClient().calls.create(data);
|
|
49
|
-
$.export("$summary", `Successfully made a new phone call, "${
|
|
49
|
+
$.export("$summary", `Successfully made a new phone call, "${callToString(resp)}"`);
|
|
50
50
|
return resp;
|
|
51
51
|
},
|
|
52
52
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
// Read the Twilio docs at https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource
|
|
2
|
-
import twilio from "../../twilio.app.mjs";
|
|
3
1
|
import { phone } from "phone";
|
|
2
|
+
import twilio from "../../twilio.app.mjs";
|
|
3
|
+
import { messageToString } from "../../common/utils.mjs";
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
6
|
key: "twilio-send-mms",
|
|
7
7
|
name: "Send MMS",
|
|
8
8
|
description: "Send an SMS with text and media files. [See the docs](https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource) for more information",
|
|
9
9
|
type: "action",
|
|
10
|
-
version: "0.0
|
|
10
|
+
version: "0.1.0",
|
|
11
11
|
props: {
|
|
12
12
|
twilio,
|
|
13
13
|
from: {
|
|
@@ -53,7 +53,7 @@ export default {
|
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
const resp = await this.twilio.getClient().messages.create(data);
|
|
56
|
-
$.export("$summary", `Successfully sent a new MMS, "${
|
|
56
|
+
$.export("$summary", `Successfully sent a new MMS, "${messageToString(resp)}"`);
|
|
57
57
|
return resp;
|
|
58
58
|
},
|
|
59
59
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
// Read the Twilio docs at https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource
|
|
2
|
-
import twilio from "../../twilio.app.mjs";
|
|
3
1
|
import { phone } from "phone";
|
|
2
|
+
import twilio from "../../twilio.app.mjs";
|
|
3
|
+
import { messageToString } from "../../common/utils.mjs";
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
6
|
key: "twilio-send-sms",
|
|
7
7
|
name: "Send SMS",
|
|
8
8
|
description: "Send a simple text-only SMS. [See the docs](https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource) for more information",
|
|
9
9
|
type: "action",
|
|
10
|
-
version: "0.0
|
|
10
|
+
version: "0.1.0",
|
|
11
11
|
props: {
|
|
12
12
|
twilio,
|
|
13
13
|
from: {
|
|
@@ -46,7 +46,7 @@ export default {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
const resp = await this.twilio.getClient().messages.create(data);
|
|
49
|
-
$.export("$summary", `Successfully sent a new SMS, "${
|
|
49
|
+
$.export("$summary", `Successfully sent a new SMS, "${messageToString(resp)}"`);
|
|
50
50
|
return resp;
|
|
51
51
|
},
|
|
52
52
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipedream/twilio",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "Pipedream Twilio Components",
|
|
5
5
|
"main": "twilio.app.mjs",
|
|
6
6
|
"keywords": [
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"dependencies": {
|
|
14
|
+
"phone": "^3.1.29",
|
|
14
15
|
"twilio": "^3.54.2"
|
|
15
16
|
},
|
|
16
17
|
"gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import twilio from "../twilio.app.mjs";
|
|
2
|
-
import twilioClient from "twilio";
|
|
3
2
|
|
|
4
3
|
export default {
|
|
5
4
|
props: {
|
|
@@ -10,12 +9,6 @@ export default {
|
|
|
10
9
|
"incomingPhoneNumber",
|
|
11
10
|
],
|
|
12
11
|
},
|
|
13
|
-
authToken: {
|
|
14
|
-
propDefinition: [
|
|
15
|
-
twilio,
|
|
16
|
-
"authToken",
|
|
17
|
-
],
|
|
18
|
-
},
|
|
19
12
|
http: {
|
|
20
13
|
label: "HTTP Responder",
|
|
21
14
|
description: "Exposes a `respond()` method that lets the source issue HTTP responses",
|
|
@@ -25,43 +18,33 @@ export default {
|
|
|
25
18
|
},
|
|
26
19
|
hooks: {
|
|
27
20
|
async activate() {
|
|
28
|
-
const createWebhookResp = await this.
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
31
|
-
|
|
21
|
+
const createWebhookResp = await this.twilio.setWebhookURL({
|
|
22
|
+
serviceType: this.getServiceType(),
|
|
23
|
+
phoneNumberSid: this.incomingPhoneNumber,
|
|
24
|
+
url: this.http.endpoint,
|
|
25
|
+
});
|
|
32
26
|
console.log(createWebhookResp);
|
|
33
27
|
},
|
|
34
28
|
async deactivate() {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
// remove the webhook URL if url prop is not set
|
|
30
|
+
const deleteWebhookResp = await this.twilio.setWebhookURL({
|
|
31
|
+
serviceType: this.getServiceType(),
|
|
32
|
+
phoneNumberSid: this.incomingPhoneNumber,
|
|
33
|
+
url: "",
|
|
34
|
+
});
|
|
39
35
|
console.log(deleteWebhookResp);
|
|
40
36
|
},
|
|
41
37
|
},
|
|
42
38
|
methods: {
|
|
39
|
+
getServiceType() {
|
|
40
|
+
throw new Error("getServiceType() is not implemented!");
|
|
41
|
+
},
|
|
43
42
|
getResponseBody() {
|
|
44
43
|
return null;
|
|
45
44
|
},
|
|
46
45
|
isRelevant() {
|
|
47
46
|
return true;
|
|
48
47
|
},
|
|
49
|
-
validateRequest(body, headers) {
|
|
50
|
-
const twilioSignature = headers["x-twilio-signature"];
|
|
51
|
-
if (!twilioSignature) {
|
|
52
|
-
console.log("No x-twilio-signature header in request. Exiting.");
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** See https://www.twilio.com/docs/usage/webhooks/webhooks-security */
|
|
57
|
-
return twilioClient.validateRequest(
|
|
58
|
-
this.authToken,
|
|
59
|
-
twilioSignature,
|
|
60
|
-
/** This must match the incoming URL exactly, which contains a / */
|
|
61
|
-
`${this.http.endpoint}/`,
|
|
62
|
-
body,
|
|
63
|
-
);
|
|
64
|
-
},
|
|
65
48
|
emitEvent(body, headers) {
|
|
66
49
|
const meta = this.generateMeta(body, headers);
|
|
67
50
|
this.$emit(body, meta);
|
|
@@ -84,15 +67,29 @@ export default {
|
|
|
84
67
|
});
|
|
85
68
|
}
|
|
86
69
|
|
|
87
|
-
if (typeof body !== "object")
|
|
70
|
+
if (typeof body !== "object") {
|
|
88
71
|
body = Object.fromEntries(new URLSearchParams(body));
|
|
72
|
+
}
|
|
89
73
|
|
|
90
74
|
if (!this.isRelevant(body)) {
|
|
91
75
|
console.log("Event not relevant. Skipping...");
|
|
92
76
|
return;
|
|
93
77
|
}
|
|
94
78
|
|
|
95
|
-
|
|
79
|
+
const signature = headers["x-twilio-signature"];
|
|
80
|
+
if (!signature) {
|
|
81
|
+
console.log("No x-twilio-signature header in request. Exiting.");
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// The url must match the incoming URL exactly, which contains a `/` at the end
|
|
86
|
+
const isRequestValid = this.twilio.validateRequest({
|
|
87
|
+
signature,
|
|
88
|
+
url: `${this.http.endpoint}/`,
|
|
89
|
+
params: body,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (!isRequestValid) {
|
|
96
93
|
console.log("Event could not be validated. Skipping...");
|
|
97
94
|
return;
|
|
98
95
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import common from "../common-webhook.mjs";
|
|
2
|
+
import constants from "../../common/constants.mjs";
|
|
2
3
|
|
|
3
4
|
export default {
|
|
4
5
|
...common,
|
|
5
6
|
key: "twilio-new-call",
|
|
6
7
|
name: "New Call (Instant)",
|
|
7
|
-
description:
|
|
8
|
-
|
|
9
|
-
version: "0.0.3",
|
|
8
|
+
description: "Emit new event each time a call to the phone number is completed. Configures a webhook in Twilio, tied to a phone number.",
|
|
9
|
+
version: "0.1.0",
|
|
10
10
|
type: "source",
|
|
11
11
|
dedupe: "unique",
|
|
12
12
|
methods: {
|
|
13
13
|
...common.methods,
|
|
14
|
-
|
|
15
|
-
return
|
|
14
|
+
getServiceType() {
|
|
15
|
+
return constants.SERVICE_TYPE.VOICE;
|
|
16
16
|
},
|
|
17
17
|
generateMeta(body, headers) {
|
|
18
18
|
return {
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import common from "../common-webhook.mjs";
|
|
2
1
|
import twilio from "twilio";
|
|
2
|
+
import common from "../common-webhook.mjs";
|
|
3
|
+
import constants from "../../common/constants.mjs";
|
|
4
|
+
|
|
3
5
|
const MessagingResponse = twilio.twiml.MessagingResponse;
|
|
4
6
|
|
|
5
7
|
export default {
|
|
6
8
|
...common,
|
|
7
9
|
key: "twilio-new-incoming-sms",
|
|
8
10
|
name: "New Incoming SMS (Instant)",
|
|
9
|
-
description:
|
|
10
|
-
|
|
11
|
-
version: "0.0.7",
|
|
11
|
+
description: "Emit new event every time an SMS is sent to the phone number set. Configures a webhook in Twilio, tied to an incoming phone number.",
|
|
12
|
+
version: "0.1.0",
|
|
12
13
|
type: "source",
|
|
13
14
|
dedupe: "unique",
|
|
14
15
|
props: {
|
|
@@ -22,8 +23,8 @@ export default {
|
|
|
22
23
|
},
|
|
23
24
|
methods: {
|
|
24
25
|
...common.methods,
|
|
25
|
-
|
|
26
|
-
return
|
|
26
|
+
getServiceType() {
|
|
27
|
+
return constants.SERVICE_TYPE.SMS;
|
|
27
28
|
},
|
|
28
29
|
getResponseBody() {
|
|
29
30
|
const twiml = new MessagingResponse();
|
|
@@ -4,8 +4,8 @@ export default {
|
|
|
4
4
|
...common,
|
|
5
5
|
key: "twilio-new-phone-number",
|
|
6
6
|
name: "New Phone Number",
|
|
7
|
-
description: "
|
|
8
|
-
version: "0.0
|
|
7
|
+
description: "Emit new event when you add a new phone number to your account",
|
|
8
|
+
version: "0.1.0",
|
|
9
9
|
type: "source",
|
|
10
10
|
dedupe: "unique",
|
|
11
11
|
methods: {
|
|
@@ -2,10 +2,10 @@ import common from "../common-polling.mjs";
|
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
4
|
...common,
|
|
5
|
-
key: "twilio-new-
|
|
5
|
+
key: "twilio-new-recording",
|
|
6
6
|
name: "New Recording",
|
|
7
|
-
description: "
|
|
8
|
-
version: "0.0
|
|
7
|
+
description: "Emit new event when a new call recording is created",
|
|
8
|
+
version: "0.1.0",
|
|
9
9
|
type: "source",
|
|
10
10
|
dedupe: "unique",
|
|
11
11
|
methods: {
|
|
@@ -4,8 +4,8 @@ export default {
|
|
|
4
4
|
...common,
|
|
5
5
|
key: "twilio-new-transcription",
|
|
6
6
|
name: "New Transcription",
|
|
7
|
-
description: "
|
|
8
|
-
version: "0.0
|
|
7
|
+
description: "Emit new event when a new call transcription is created",
|
|
8
|
+
version: "0.1.0",
|
|
9
9
|
type: "source",
|
|
10
10
|
dedupe: "unique",
|
|
11
11
|
methods: {
|
package/twilio.app.mjs
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import twilio from "twilio";
|
|
2
2
|
import {
|
|
3
3
|
callToString,
|
|
4
4
|
messageToString,
|
|
5
5
|
recordingToString,
|
|
6
|
-
} from "./utils.mjs";
|
|
6
|
+
} from "./common/utils.mjs";
|
|
7
|
+
import constants from "./common/constants.mjs";
|
|
7
8
|
|
|
8
9
|
export default {
|
|
9
10
|
type: "app",
|
|
10
11
|
app: "twilio",
|
|
11
12
|
propDefinitions: {
|
|
12
|
-
authToken: {
|
|
13
|
-
type: "string",
|
|
14
|
-
secret: true,
|
|
15
|
-
label: "Twilio Auth Token",
|
|
16
|
-
description:
|
|
17
|
-
"Your Twilio auth token, found [in your Twilio console](https://www.twilio.com/console). Required for validating Twilio events.",
|
|
18
|
-
},
|
|
19
13
|
body: {
|
|
20
14
|
type: "string",
|
|
21
15
|
label: "Message Body",
|
|
@@ -84,7 +78,7 @@ export default {
|
|
|
84
78
|
const messages = await this.listMessages();
|
|
85
79
|
return messages.map((message) => {
|
|
86
80
|
return {
|
|
87
|
-
label:
|
|
81
|
+
label: messageToString(message),
|
|
88
82
|
value: message.sid,
|
|
89
83
|
};
|
|
90
84
|
});
|
|
@@ -116,7 +110,7 @@ export default {
|
|
|
116
110
|
const recordings = await this.listRecordings();
|
|
117
111
|
return recordings.map((recording) => {
|
|
118
112
|
return {
|
|
119
|
-
label:
|
|
113
|
+
label: recordingToString(recording),
|
|
120
114
|
value: recording.sid,
|
|
121
115
|
};});
|
|
122
116
|
},
|
|
@@ -155,33 +149,34 @@ export default {
|
|
|
155
149
|
},
|
|
156
150
|
},
|
|
157
151
|
methods: {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
152
|
+
validateRequest({
|
|
153
|
+
signature, url, params,
|
|
154
|
+
} = {}) {
|
|
155
|
+
// See https://www.twilio.com/docs/usage/webhooks/webhooks-security
|
|
156
|
+
return twilio.validateRequest(
|
|
157
|
+
this.$auth.authToken,
|
|
158
|
+
signature,
|
|
159
|
+
url,
|
|
160
|
+
params,
|
|
161
|
+
);
|
|
162
|
+
},
|
|
163
163
|
getClient() {
|
|
164
|
-
return
|
|
165
|
-
accountSid: this.$auth.AccountSid,
|
|
166
|
-
});
|
|
164
|
+
return twilio(this.$auth.accountSid, this.$auth.authToken);
|
|
167
165
|
},
|
|
168
|
-
|
|
166
|
+
setWebhookURL({
|
|
167
|
+
serviceType = constants.SERVICE_TYPE.SMS, phoneNumberSid, url,
|
|
168
|
+
} = {}) {
|
|
169
|
+
const opts = serviceType === constants.SERVICE_TYPE.SMS
|
|
170
|
+
? {
|
|
171
|
+
smsMethod: constants.HTTP_METHOD.POST,
|
|
172
|
+
smsUrl: url,
|
|
173
|
+
}
|
|
174
|
+
: {
|
|
175
|
+
statusCallbackMethod: constants.HTTP_METHOD.POST,
|
|
176
|
+
statusCallback: url,
|
|
177
|
+
};
|
|
169
178
|
const client = this.getClient();
|
|
170
|
-
return
|
|
171
|
-
},
|
|
172
|
-
async setIncomingSMSWebhookURL(phoneNumberSid, url) {
|
|
173
|
-
const params = {
|
|
174
|
-
smsMethod: "POST",
|
|
175
|
-
smsUrl: url,
|
|
176
|
-
};
|
|
177
|
-
return await this.setWebhookURL(phoneNumberSid, params);
|
|
178
|
-
},
|
|
179
|
-
async setIncomingCallWebhookURL(phoneNumberSid, url) {
|
|
180
|
-
const params = {
|
|
181
|
-
statusCallbackMethod: "POST",
|
|
182
|
-
statusCallback: url,
|
|
183
|
-
};
|
|
184
|
-
return await this.setWebhookURL(phoneNumberSid, params);
|
|
179
|
+
return client.incomingPhoneNumbers(phoneNumberSid).update(opts);
|
|
185
180
|
},
|
|
186
181
|
/**
|
|
187
182
|
* Returns a IncomingPhoneNumber list resource representing an account's
|
|
@@ -192,9 +187,9 @@ export default {
|
|
|
192
187
|
*
|
|
193
188
|
* @returns the IncomingPhoneNumber list
|
|
194
189
|
*/
|
|
195
|
-
|
|
190
|
+
listIncomingPhoneNumbers(params) {
|
|
196
191
|
const client = this.getClient();
|
|
197
|
-
return
|
|
192
|
+
return client.incomingPhoneNumbers.list(params);
|
|
198
193
|
},
|
|
199
194
|
/**
|
|
200
195
|
* Returns a list of Recordings, each representing a recording generated
|
|
@@ -205,9 +200,9 @@ export default {
|
|
|
205
200
|
*
|
|
206
201
|
* @returns the list of recordings
|
|
207
202
|
*/
|
|
208
|
-
|
|
203
|
+
listRecordings(params) {
|
|
209
204
|
const client = this.getClient();
|
|
210
|
-
return
|
|
205
|
+
return client.recordings.list(params);
|
|
211
206
|
},
|
|
212
207
|
/**
|
|
213
208
|
* Returns a list of Transcriptions generated from all recordings in an
|
|
@@ -218,9 +213,9 @@ export default {
|
|
|
218
213
|
*
|
|
219
214
|
* @returns the list of transcriptions
|
|
220
215
|
*/
|
|
221
|
-
|
|
216
|
+
listTranscriptions(params) {
|
|
222
217
|
const client = this.getClient();
|
|
223
|
-
return
|
|
218
|
+
return client.transcriptions.list(params);
|
|
224
219
|
},
|
|
225
220
|
/**
|
|
226
221
|
* Returns a list of messages associated with your account. When getting the
|
|
@@ -232,9 +227,9 @@ export default {
|
|
|
232
227
|
*
|
|
233
228
|
* @returns the list of messages
|
|
234
229
|
*/
|
|
235
|
-
|
|
230
|
+
listMessages(params) {
|
|
236
231
|
const client = this.getClient();
|
|
237
|
-
return
|
|
232
|
+
return client.messages.list(params);
|
|
238
233
|
},
|
|
239
234
|
/**
|
|
240
235
|
* Returns a single message specified by the provided Message `sid`
|
|
@@ -244,9 +239,9 @@ export default {
|
|
|
244
239
|
*
|
|
245
240
|
* @returns the message
|
|
246
241
|
*/
|
|
247
|
-
|
|
242
|
+
getMessage(sid) {
|
|
248
243
|
const client = this.getClient();
|
|
249
|
-
return
|
|
244
|
+
return client.messages(sid).fetch();
|
|
250
245
|
},
|
|
251
246
|
/**
|
|
252
247
|
* Deletes a message record from your account. Once the record is deleted,
|
|
@@ -256,9 +251,9 @@ export default {
|
|
|
256
251
|
* the Message resource to delete
|
|
257
252
|
* @returns `true` on success
|
|
258
253
|
*/
|
|
259
|
-
|
|
254
|
+
deleteMessage(sid) {
|
|
260
255
|
const client = this.getClient();
|
|
261
|
-
return
|
|
256
|
+
return client.messages(sid).remove();
|
|
262
257
|
},
|
|
263
258
|
/**
|
|
264
259
|
* Returns a list of media associated with your message
|
|
@@ -268,9 +263,9 @@ export default {
|
|
|
268
263
|
* @param {Object} [params] - an object containing parameters to be fed to the
|
|
269
264
|
* Twilio API call, as defined in [the API docs](https://bit.ly/3mc8apg)
|
|
270
265
|
*/
|
|
271
|
-
|
|
266
|
+
listMessageMedia(messageId, params) {
|
|
272
267
|
const client = this.getClient();
|
|
273
|
-
return
|
|
268
|
+
return client.messages(messageId).media.list(params);
|
|
274
269
|
},
|
|
275
270
|
/**
|
|
276
271
|
* Return a list of phone calls made to and from an account
|
|
@@ -279,15 +274,15 @@ export default {
|
|
|
279
274
|
* Twilio API call, as defined in [the API docs](https://bit.ly/3iiHIJ9)
|
|
280
275
|
* @returns the list of calls
|
|
281
276
|
*/
|
|
282
|
-
|
|
277
|
+
listCalls(params) {
|
|
283
278
|
const client = this.getClient();
|
|
284
|
-
return
|
|
279
|
+
return client.calls.list(params);
|
|
285
280
|
},
|
|
286
281
|
async listCallsOptions(params = {}) {
|
|
287
282
|
const calls = await this.listCalls(params);
|
|
288
283
|
return calls.map((call) => {
|
|
289
284
|
return {
|
|
290
|
-
label:
|
|
285
|
+
label: callToString(call),
|
|
291
286
|
value: call.sid,
|
|
292
287
|
};
|
|
293
288
|
});
|
|
@@ -298,9 +293,9 @@ export default {
|
|
|
298
293
|
* @param {String} sid - The SID of the Call resource to fetch
|
|
299
294
|
* @returns the Call
|
|
300
295
|
*/
|
|
301
|
-
|
|
296
|
+
getCall(sid) {
|
|
302
297
|
const client = this.getClient();
|
|
303
|
-
return
|
|
298
|
+
return client.calls(sid).fetch();
|
|
304
299
|
},
|
|
305
300
|
/**
|
|
306
301
|
* This will delete a call record from the account. Once the record is
|
|
@@ -310,9 +305,9 @@ export default {
|
|
|
310
305
|
* the Call resource to delete
|
|
311
306
|
* @returns `true` on success
|
|
312
307
|
*/
|
|
313
|
-
|
|
308
|
+
deleteCall(sid) {
|
|
314
309
|
const client = this.getClient();
|
|
315
|
-
return
|
|
310
|
+
return client.calls(sid).remove();
|
|
316
311
|
},
|
|
317
312
|
/**
|
|
318
313
|
* Returns a recording specified by the provided Recording `sid`
|
|
@@ -322,9 +317,9 @@ export default {
|
|
|
322
317
|
*
|
|
323
318
|
* @returns the recording
|
|
324
319
|
*/
|
|
325
|
-
|
|
320
|
+
getRecording(sid) {
|
|
326
321
|
const client = this.getClient();
|
|
327
|
-
return
|
|
322
|
+
return client.recordings(sid).fetch();
|
|
328
323
|
},
|
|
329
324
|
/**
|
|
330
325
|
* Returns a list of transcriptions available for the recording identified
|
|
@@ -335,9 +330,9 @@ export default {
|
|
|
335
330
|
*
|
|
336
331
|
* @returns the list of transcriptions
|
|
337
332
|
*/
|
|
338
|
-
|
|
333
|
+
listRecordingTranscriptions(sid, params) {
|
|
339
334
|
const client = this.getClient();
|
|
340
|
-
return
|
|
335
|
+
return client.recordings(sid).transcriptions.list(params);
|
|
341
336
|
},
|
|
342
337
|
},
|
|
343
338
|
};
|