diff --git a/server/notification-providers/plivo.js b/server/notification-providers/plivo.js index 79be359b8..d807207ba 100644 --- a/server/notification-providers/plivo.js +++ b/server/notification-providers/plivo.js @@ -18,16 +18,30 @@ class Plivo extends NotificationProvider { "Basic " + Buffer.from(notification.plivoAuthID + ":" + notification.plivoAuthToken).toString("base64"), }, + timeout: 10000, }; config = this.getAxiosConfigWithProxy(config); - const data = { - src: notification.plivoFromNumber, - dst: notification.plivoToNumber, - text: msg, - }; + const baseURL = `https://api.plivo.com/v1/Account/${notification.plivoAuthID}`; - await axios.post(`https://api.plivo.com/v1/Account/${notification.plivoAuthID}/Message/`, data, config); + if (notification.plivoMessageType === "call") { + const answerUrl = new URL(notification.plivoAnswerUrl); + answerUrl.searchParams.set("message", msg); + const data = { + from: notification.plivoFromNumber, + to: notification.plivoToNumber, + answer_url: answerUrl.toString(), + answer_method: "GET", + }; + await axios.post(`${baseURL}/Call/`, data, config); + } else { + const data = { + src: notification.plivoFromNumber, + dst: notification.plivoToNumber, + text: msg, + }; + await axios.post(`${baseURL}/Message/`, data, config); + } return okMsg; } catch (error) { diff --git a/src/components/notifications/Plivo.vue b/src/components/notifications/Plivo.vue index bd1b97e3d..2ce11a1f9 100644 --- a/src/components/notifications/Plivo.vue +++ b/src/components/notifications/Plivo.vue @@ -48,9 +48,37 @@
{{ $t("plivoToNumberHelptext") }}
+
+ + +
+ +
+ + +
{{ $t("plivoAnswerUrlHelptext") }}
+
+
- + + https://www.plivo.com/docs/voice/api/call + + https://www.plivo.com/docs/messaging/api/message @@ -64,5 +92,10 @@ export default { components: { HiddenInput, }, + mounted() { + if (typeof this.$parent.notification.plivoMessageType === "undefined") { + this.$parent.notification.plivoMessageType = "sms"; + } + }, }; diff --git a/src/lang/en.json b/src/lang/en.json index da681f222..210610a61 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -1053,9 +1053,13 @@ "plivoAuthToken": "Auth Token", "plivoAuthTokenHelptext": "Your Plivo Auth Token from the Plivo Console", "plivoFromNumber": "From Number", - "plivoFromNumberHelptext": "The Plivo phone number or sender ID to send from (e.g. +15551234567)", + "plivoFromNumberHelptext": "The Plivo phone number to send from (e.g. +15551234567). SMS may also use an approved alphanumeric sender ID; voice calls require a Plivo phone number.", "plivoToNumber": "To Number", - "plivoToNumberHelptext": "The destination phone number to receive SMS notifications (e.g. +15559876543)", + "plivoToNumberHelptext": "The destination phone number that receives the SMS or voice call (e.g. +15559876543)", + "plivoMessageType": "Message Type", + "plivoVoiceCall": "Voice Call", + "plivoAnswerUrl": "Answer URL", + "plivoAnswerUrlHelptext": "URL that returns Plivo XML for the call. The alert text is appended as a ?message= query parameter, so your endpoint can return e.g. {message}.", "twilioAccountSID": "Account SID", "twilioApiKey": "Api Key (optional)", "twilioApiKeyHelptext": "The API key is optional but recommended. You can provide either Account SID and AuthToken from the may TwilioConsole page or Account SID and the pair of Api Key and Api Key secret",