DTMF struggles
hey guys i have been trying to implement DTMf functionality for my voice agent but it seems to not work .
I got some tips from this developer call with nico,CallSense
Any help will be much appreciated,
here is the second havascript block,// Ensure tmpCode exists
tmpCode = tmpCode "";
// 1️⃣ User SPOKE the digits (rare but possible)
if (last_event.type === "intent" && last_event.payload?.query) {
const spoken = String(last_event.payload.query).toLowerCase();
// convert spoken words to digits
if (spoken.includes("zero")) tmpCode += "0";
if (spoken.includes("one") spoken.includes("1")) tmpCode += "1";
if (spoken.includes("two") spoken.includes("2")) tmpCode += "2";
if (spoken.includes("three") spoken.includes("3")) tmpCode += "3";
if (spoken.includes("four") spoken.includes("4")) tmpCode += "4";
if (spoken.includes("five") spoken.includes("5")) tmpCode += "5";
if (spoken.includes("six") spoken.includes("6")) tmpCode += "6";
if (spoken.includes("seven") spoken.includes("7")) tmpCode += "7";
if (spoken.includes("eight") spoken.includes("8")) tmpCode += "8";
if (spoken.includes("nine") spoken.includes("9")) tmpCode += "9";
}
// 2️⃣ User PRESSED a DTMF key
else if (last_event.type === "dtmf" && last_event.data) {
const digit = String(last_event.data);
if (!isNaN(digit)) {
tmpCode += digit;
}
}
// 3️⃣ Not speech & not DTMF → reset
else {
tmpCode = "";
throw "invalid";
}
// 4️⃣ When user enters 4 digits → verify
if (tmpCode.length === 4) {
if (tmpCode === randomCode) {
tmpCode = "";
return "Verified";
} else {
tmpCode = "";
return "Wrong code";
}
}
// 5️⃣ Return nothing until 4 digits
return;


6 Replies
what about this code,if (last_event?.type?.startsWith('DTMF ')) {
const digit = last_event.type.slice(-1);
if (!isNaN(digit)) { tmpCode += digit; }
if (tmpCode.length === 4) { if (tmpCode == randomCode) { tmpCode = ''; // Reset after verification return 'Verified'; } else { tmpCode = ''; // Reset for incorrect attempt return 'Wrong code' } } } else { tmpCode = '' throw 'invalid' }
if (!isNaN(digit)) { tmpCode += digit; }
if (tmpCode.length === 4) { if (tmpCode == randomCode) { tmpCode = ''; // Reset after verification return 'Verified'; } else { tmpCode = ''; // Reset for incorrect attempt return 'Wrong code' } } } else { tmpCode = '' throw 'invalid' }
hey, ignore tico for now! you don't need to do DTMF manually anymore - just enable DTMF on your project
Hi Jacklyn thank you
i did that already...

the funniest thing just happened, i dissabled the keypad input and it worked
so its like if i turn it on it doesnt work but if i turn it off it works
@jacklyn :)