我可以通过与DialogFlow连接的Voximplant拨打双音多频拨号一个数字。我关注过this scenario,但正如代码在第147行中声明的那样,// ToDo: aggregate multiple DTMF keys that are pressed in succession and send as a single string。
有没有人能够拨打客栈超过一个数字,或者可以引导我到正确的例子这样做?
发布于 2020-12-31 21:40:09
我为Voximplant做了一个更多的comprehensive example,它可以处理多个DTMF条目。这需要一些额外的参数来控制在报告之前停止收集DTMF的位数和时间:
// Configurable via custom payload
let interToneTime = 3000 // Default time to wait for the next DTMF digit after one is pressed
let maxToneDigits = 12 // Default number of DTMF digits to look for after one is pressed
let dtmfMode = "event" // Send DTMF key presses as events or as "text"
let stopTones = [] // DTMF tones used to indicate end of digit entry然后,我扩展了您链接到的DTMF example from cogint.ai中的原始onTone函数:
function onTone(e) {
Logger.write("DEBUG: onTone called: " + e.tone) // on iteration #" + cnt)
if (stopTones.includes(e.tone)){
Logger.write("DEBUG: stopTone entered: " + e.tone);
toneTimerCallback()
return
}
noInputTimer.stop()
toneCount++;
tones.push(e.tone)
if (toneCount >= maxToneDigits){
Logger.write("DEBUG: maximum number of specified tones reached: " + toneCount) // on iteration #" + cnt)
toneTimerCallback()
}
else
toneTimer.start()
}这实际上是将音调推入一个数组中,如果按下了停止音(即通常是#或*)或超过了maxToneDigits,则会调用toneTimerCallback函数。
toneTimerCallback只是将数字转换为字符串,并将其发送到Dialogflow:
function toneTimerCallback() {
let toneString = tones.join('').toString() // bug requires adding an extra .toString()
if (toneString == '') {
Logger.write("DEBUG: toneTimerCallback - invalid toneString: " + toneString)
return
}
Logger.write("DEBUG: sending DTMF in " + dtmfMode + "mode : " + toneString)
if (dtmfMode == "event")
dialogflow.sendQuery({ event: { name: "DTMF", language_code: "en", parameters: { dtmf_digits: toneString } } })
else if (dtmfMode == "text")
dialogflow.sendQuery({ text: { text: toneString.toString(), language_code: "en" }}) // bug requires adding an extra .toString()
toneCount = 0
tones = []
}这显示了如何将数字作为文本输入或作为事件发送。
gist中的其他相关部分展示了如何使用自定义有效负载按意图设置这些参数。例如,这可以让您为一个意图中的邮政编码指定最多5位数字,并为另一个请求电话号码的意图设置10位。
https://stackoverflow.com/questions/65483523
复制相似问题