GetDigits
Collect keypad digits from the caller, with an optional spoken or played prompt.
Collect keypad digits from the caller, with an optional spoken or played prompt.
getDigits collects keypad digits from the caller. Put say or play actions in nested to use as the prompt.
| Parameter | Type | Required | Description |
|---|---|---|---|
numDigits | integer | No | Stop after this many digits. 0 or omitted means no limit: the caller ends with the finish key. |
finishOnKey | string | No | The key that submits the digits early. Default #. |
timeout | integer | No | Seconds to wait for input after the prompt finishes. |
nested | array | No | say and play actions used as the prompt. |
import { sauti, say } from "@sautikit/node";
res.json(
sauti.getDigits({ numDigits: 1, timeout: 5, finishOnKey: "#" }, [
say("Press 1 to confirm, 2 to cancel."),
]),
);{
"actions": [
{
"getDigits": {
"numDigits": 1,
"timeout": 5,
"finishOnKey": "#",
"nested": [
{
"say": {
"text": "Press 1 to confirm, 2 to cancel."
}
}
]
}
}
]
}<GetDigits numDigits="1" timeout="5" finishOnKey="#"><Say>Press 1 to confirm, 2 to cancel.</Say></GetDigits>getDigits has no follow-up URL. When the caller finishes, Sautikit POSTs to the number's voice_callback_url again with the digits in the body, and your server returns the next actions. Read the digits from dtmfDigits, and fall back to digits:
app.post("/voice", (req, res) => {
const digits = req.body.dtmfDigits ?? req.body.digits;
if (digits === "1") {
return res.json({ actions: [{ say: { text: "Your order is confirmed." } }] });
}
res.json({ actions: [{ say: { text: "Goodbye." } }, { hangup: {} }] });
});Build a voice IVR has a full menu.