Handle an Incoming Call

The Voice provider's onCall function allows you to return an NCCO for incoming call webhooks using the Voice API.

Method Signature

onCall(callback: string)

Handle Call Webhooks

In the route specified with the callback parameter, you can return an NCCO to instruct the Voice API on how to handle the call.

const session = vcr.createSession();
const voice = new Voice(session);

await voice.onCall("onCall");

app.post('/onCall', async (req, res, next) => {
    const ncco = [
        {
            action: 'talk',
            text: "Hi from Vonage!",
        }
    ];
    res.json(ncco);
});
session = vcr.createSession()
voice = Voice(session)

await voice.onCall("onCall")

@app.post('/onCall')
async def onAnswer():
    return  [
                {
                    'action': 'talk',
                    'text': 'Hi from Vonage!'
                }
        ]