From 6b3495f2a633b247170685c7b2f439033a5f9acc Mon Sep 17 00:00:00 2001 From: Miller JS Dev <166415354+millerjsdev@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:15:25 +0300 Subject: [PATCH] Create call.js otp bot calls with twilio/plivo api --- call.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 call.js diff --git a/call.js b/call.js new file mode 100644 index 0000000..61c9d25 --- /dev/null +++ b/call.js @@ -0,0 +1,43 @@ +// Include Twilio and Plivo SDKs +const twilio = require('twilio'); +const plivo = require('plivo'); + +// Initialize Twilio and Plivo clients with your API credentials +const twilioClient = new twilio('YOUR_TWILIO_ACCOUNT_SID', 'YOUR_TWILIO_AUTH_TOKEN'); +const plivoClient = plivo.RestAPI({ + authId: 'YOUR_PLIVO_AUTH_ID', + authToken: 'YOUR_PLIVO_AUTH_TOKEN' +}); + +// Function to send OTP via call using Twilio +function sendOTPCall(targetNumber, otp) { + twilioClient.calls.create({ + url: 'http://your-server.com/otp-voice.xml', // XML file for OTP voice message + to: targetNumber, + from: 'YOUR_TWILIO_PHONE_NUMBER' + }) + .then(call => console.log(call.sid)) + .catch(error => console.error(error)); +} + +// Example otp bot text-to-speech messages via call +// Function to send bot's text-to-speech message via call using Plivo +function sendBotCall(targetNumber, message) { + plivoClient.make_call({ + from: 'YOUR_PLIVO_PHONE_NUMBER', + to: targetNumber, + answer_url: 'http://your-server.com/bot-message.xml?message=' + encodeURIComponent(message) // XML file for bot's message + }, function(status, response) { + console.log('Status: ', status); + console.log('API Response:\n', response); + }); +} + +// Example usage +const targetNumber = 'TARGET_PHONE_NUMBER'; +const yourscript = 'YOUR_SENTENCES'; +const otp = ''; +const botMessage = yourscript; + +sendOTPCall(targetNumber, otp); +sendBotCall(targetNumber, botMessage);