-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
otp bot calls with twilio/plivo api
- Loading branch information
0 parents
commit 6b3495f
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |