Reputation: 6507
We are using the outbound voice API. We have successfully set up an application and are able to create an outbound call using a test NCCO: https://developer.nexmo.com/ncco/tts.json We are using the NodeJS SDK. However, we are not able to understand why the NCCOs must be accessed through URLs, instead of being supplied as a JSON object directly. Moreover, we are using the voice API to verify user accounts at our services. Once a user registers to our services, we give them the option to choose between a SMS or a phonecall to verify their accounts. Evidently, each user will receive a distinct code in their SMS/call (e.g., 1234). We would like to receive help on how to bypass the answer_url field, and be able to supply a distinct text-to-speech text, per user.
In brief, is there a way to, instead of supplying to the voice call API, a static JSON object through a public URL, supply a JSON object dynamically generated that contains a distinct code for the user?
Below is an example of the nexmo node method to generate an outbound call:
nexmo.calls.create({
to: [{
type: 'phone',
number: RECEIVING_NUMBER
}],
from: {
type: "phone",
number: NEXMO_VIRTUAL_NUMBER
},
answer_url: ['https://developer.nexmo.com/ncco/tts.json']
}, (err, res) => {
if(err) console.log(JSON.stringify(err,null,2));
else { console.log(res); }
})
Upvotes: 2
Views: 366
Reputation: 4733
You can build Nodejs api that returns JSON and use it as answer_url. by this way you can send query parameters to this api to make dynamic NCCOs.
example:
answer_url: ['https://example.com/answer?code=12345']
app.get('/answer', function(req, res) {
const ncco = [{
'action': 'talk',
'voiceName': 'Jennifer',
'text': req.params.code
}
];
res.json(ncco);
});
Upvotes: 2