I am trying to automate a call flow to regression test call center application's IVR system.
I am able to place calls and receive the response as expected.But I am trying to understand the time taken between the 2 lines of code
console.log("Waiting for Server to respond");
and
console.log("Received response from Server");
My understanding is after Twilio receives the TwiML response from my Node.js instance, it process and send/receive the telephony signals.
Only after it receives the whole response from the server, I am receiving the voice response in /TC4_Step1_Validate
. When I log the timestamp for both the lines and capture the difference. It comes around 20 seconds. But in reality the application responds within couple of seconds.
I believe Twilio waits for the whole dialogue to complete by waiting for 3 second silence, convert that audio stream to text and then post it to my function. That is the reason I see that 20 seconds.
But I need to understand the time it took to first receive the telephony response and not the whole stream with timeout and speech to text conversion time.
In Short I am trying to understand the time it took for the contact center application to respond.
Please find my sample code below
Function to place a call
app.get('/TC4', function(req, res) {
client.calls.create({
url: 'http://{PUBLIC_URL}/TC4_Step1',
to: '{TO_NUMBER}',
from: '{TWILIO_NUMBER}',
method: 'GET',
Record: 'false',
})
.then((call) => res.send(call.sid));
});
Function to Gather Step 1 response from my contact center application when I place a call
app.get('/TC4_Step1', function(req, res) {
res.setHeader('Content-Type', 'application/xml');
const response = new VoiceResponse();
const gather = response.gather({
input: 'speech',
action: 'http://{PUBLIC_URL}/TC4_Step1_Validate',
timeout: 3,
});
res.send(response.toString());
console.log("Waiting for Server to respond");
console.log(response.toString());
});
Function to validate response from Step1 & Gather step 2 response
app.post('/TC4_Step1_Validate', function(req, res) {
const response = new VoiceResponse();
console.log("Received response from Server");
console.log(req.body.SpeechResult.toLowerCase());
if(req.body.SpeechResult.toLowerCase().indexOf("{VERIFY_TEXT1}")!=-1 && req.body.SpeechResult.toLowerCase().indexOf("{VERIFY_TEXT2}")!=-1) {
response.pause({
length: 2
});
const gather = response.gather({
input: 'speech',
action: 'http://{PUBLIC_URL}/TC4_Step2_Validate',
timeout: 3,
});
} else {
console.log("Failed Step 1");
response.hangup();
}
res.setHeader('Content-Type', 'application/xml');
res.send(response.toString());
console.log("DTMF Input 2");
console.log(response.toString());
});