Twilio developer evangelist here.
First, you have one issue with your code that means you will always fail the check.
When you get the ivrSpeech
you call .toLowerCase()
on it:
let ivrSpeech = (event.SpeechResult ? event.SpeechResult : "").toLowerCase();
But then you test against a string with a capital letter in it:
if (ivrSpeech.includes("Call may be recorded and monitored for quality purpose"))
So you should change that to start with.
Otherwise, I am not sure what you mean when you say you want to "fail my test" when it doesn't match. You have the code written out pretty well so far, but I don't quite understand what you want to do in the else
condition.
One option is to hang up the call, which you would achieve like this:
if (ivrSpeech && ivrSpeech.length > 0)
{
if(servicetype.includes("XX"))
{
if (ivrSpeech.includes("call may be recorded and monitored for quality purpose"))
{
twiml.pause({ length: 10 });
}
else
{
twiml.hangup();
}
}
}
callback(null, twiml)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…