【发布时间】:2018-02-01 02:58:15
【问题描述】:
我正在尝试将呼叫流程自动化到回归测试呼叫中心应用程序的 IVR 系统。
我能够拨打电话并按预期接收响应。但我试图了解两行代码之间所用的时间
console.log("Waiting for Server to respond");
和
console.log("Received response from Server");
我的理解是在 Twilio 从我的 Node.js 实例接收到 TwiML 响应后,它会处理并发送/接收电话信号。
只有在收到服务器的全部响应后,我才会在/TC4_Step1_Validate 中收到语音响应。当我记录两条线的时间戳并捕获差异时。它大约需要 20 秒。但实际上应用程序会在几秒钟内做出响应。
我相信 Twilio 会通过等待 3 秒的静音来等待整个对话完成,然后将该音频流转换为文本,然后将其发布到我的函数中。这就是我看到 20 秒的原因。
但我需要了解第一次收到电话响应所花费的时间,而不是整个流的超时时间和语音到文本的转换时间。
简而言之,我试图了解联络中心应用程序响应所需的时间。
请在下面找到我的示例代码
拨打电话的功能
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));
});
拨打电话时从我的联络中心应用程序收集步骤 1 响应的功能
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());
});
验证来自步骤 1 的响应并收集步骤 2 响应的功能
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());
});
【问题讨论】: