-
Notifications
You must be signed in to change notification settings - Fork 21
/
call.js
43 lines (38 loc) · 1.4 KB
/
call.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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);