如何使用 Voximplant 聚合多个 DTMF 密钥?
How can I aggregate multiple DTMF keys with Voximplant?
我可以通过调用与 DialogFlow 连接的 Voximplant 来使用 DTMF 拨一个数字。我已关注 this scenario,但正如第 147 行中的代码所述,// ToDo: aggregate multiple DTMF keys that are pressed in succession and send as a single string
.
有没有人能够拨出超过一位数的电话号码,或者可以指导我找到这样做的正确示例?
我为处理多个 DTMF 输入的 Voximplant 制作了更多 comprehensive example。这需要一些额外的参数来控制多少位以及何时在报告之前停止收集 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
只是将数字转换为字符串并将它们发送到 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 = []
}
这显示了如何将数字作为文本输入或事件发送。
要点中的其他相关部分展示了如何使用自定义负载在每个意图的基础上设置这些参数。例如,这可以让您在一个意图中为邮政编码指定最多 5 位数字,并为另一个要求 phone 号码的意图设置 10。
我可以通过调用与 DialogFlow 连接的 Voximplant 来使用 DTMF 拨一个数字。我已关注 this scenario,但正如第 147 行中的代码所述,// ToDo: aggregate multiple DTMF keys that are pressed in succession and send as a single string
.
有没有人能够拨出超过一位数的电话号码,或者可以指导我找到这样做的正确示例?
我为处理多个 DTMF 输入的 Voximplant 制作了更多 comprehensive example。这需要一些额外的参数来控制多少位以及何时在报告之前停止收集 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
只是将数字转换为字符串并将它们发送到 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 = []
}
这显示了如何将数字作为文本输入或事件发送。
要点中的其他相关部分展示了如何使用自定义负载在每个意图的基础上设置这些参数。例如,这可以让您在一个意图中为邮政编码指定最多 5 位数字,并为另一个要求 phone 号码的意图设置 10。