context?.streamFile(filePath('welcome'));
for (let i = 0; i < 3; i++) {
const { result } = await context?.getData(filePath('press-code'), 10000, 15);
phoneMap = await PhonesMap.findByPk(result);
if (phoneMap) {
break;
}
await context?.streamFile(filePath('number-not-found'));
}
First he hears an opening message, then he is asked to press in the code, if the code is wrong he has up to 3 attempts to press in a code.
The problem is that users start pressing a code right at the beginning of the call, while the opening message is still playing, and then the first digits are not picked up.
what is the solution? Is it possible to combine the opening message with the “press-code” message so that they listen together to DTMF? Or any other solution?
Thanks in advance
What language is that (“await” seems to be an EcmaScript 2017 keyword)? What library are you using? What are the definitions of any variables and functions that are not part of that library?
What is wrong with using Background and WaitExten in standard dialplan?
Although it is structured differently from background, it does look like GET DATA will accept DTMF, and stop the playback, when streaming the file. That means you could create concatenations of your streamed messages and the prompt. (Background, itself, allows multiple files.)
JS, ding-dong package. (I didn’t see the need to specify the technical details of the code, I just wanted to show the pseudo code of the messages and loop)
It’s a small part of a complex application with permissions and with hidden extensions, it has to be like this.
actually, I created another sound file that is connected from the welcome and the press-code. And I play it in the first iteration of the loop.
Thank so much
for (let i = 0; i < 3; i++) {
const msgSound = i === 0 ? 'welcome-press-code' : 'press-code'; // Here it checks whether the welcome should be played or not
const { result } = await context?.getData(filePath(msgSound), 10000, 15);
phoneMap = await PhonesMap.findByPk(result);
if (phoneMap) {
callLog.set({ TargetPhoneCode: result }).save();
break;
}
await context?.streamFile(filePath('number-not-found'));
}