Create the DTMF webhook

Create the /webhooks/dtmf route by entering the following code beneath your /webhooks/answer route:'/webhooks/dtmf', (req, res) => {
    let actions = [];
    let ncco = [];
    switch (req.body.dtmf.digits) {
        case '1':
                action: 'talk',
                text: `It is ${new Intl.DateTimeFormat(undefined, {
                    dateStyle: 'full',
                    timeStyle: 'long',
        case '2':
                action: 'stream',
                streamUrl: [
    ncco = actions.concat(mainMenu(req));



This code examines the request to see which digit the user entered (in req.body.dtmf) and adds the appropriate action to the existing NCCO. If the user presses 1, it adds a talk action to read out the current date and time. If the user presses 2, it plays an audio file into the call using a stream action. If the user presses any other key, it is ignored and the function returns the original NCCO with the initial menu choices you defined in the mainMenu function.