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 spoken.includes("1")) tmpCode += "1";
if (spoken.includes("two") spoken.includes("3")) tmpCode += "3";
if (spoken.includes("four") spoken.includes("5")) tmpCode += "5";
if (spoken.includes("six") spoken.includes("7")) tmpCode += "7";
if (spoken.includes("eight") 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;
image.png
image.png
Was this page helpful?