Node.js
Create the DTMF webhook
Create the /webhooks/dtmf route by entering the following code beneath your /webhooks/answer route:
app.post('/webhooks/dtmf', (req, res) => {
let actions = [];
let ncco = [];
switch (req.body.dtmf.digits) {
case '1':
actions.push({
action: 'talk',
text: `It is ${new Intl.DateTimeFormat(undefined, {
dateStyle: 'full',
timeStyle: 'long',
}).format(Date.now())}`,
});
break;
case '2':
actions.push({
action: 'stream',
streamUrl: [
'https://nexmo-community.github.io/ncco-examples/assets/voice_api_audio_streaming.mp3',
],
});
}
ncco = actions.concat(mainMenu(req));
console.log(ncco);
res.json(ncco);
});
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.
Build a Call Menu
Create an interactive voice response (IVR) menu to handle customer calls
以下の言語で利用可能:
手順
1
Introduction2
Prerequisites3
What you will build4
Install the dependencies5
Create the server6
Create the answer webhook7
Create the DTMF webhook8
Create the event webhook9
Configure your Voice application10
Run it!11
Conclusion12
What's next?