Skip to content

Commit

Permalink
Create call.js
Browse files Browse the repository at this point in the history
otp bot calls with twilio/plivo api
  • Loading branch information
millerjsdev committed Apr 8, 2024
0 parents commit 6b3495f
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions call.js
Original file line number Diff line number Diff line change
@@ -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:https://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:https://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);

0 comments on commit 6b3495f

Please sign in to comment.