#How to retrieve the call duration in the webhook response ?

1 messages · Page 1 of 1 (latest)

jaunty boltBOT
#
AI-generated Answer for micheldenizob

To retrieve the call duration in a webhook response, you can use the statusCallback parameter in Twilio's API. This parameter allows you to specify a URL that Twilio will notify when the call status changes, including when the call is completed. In the webhook payload sent to your specified URL, you will receive details about the call, including its duration.

Here's a basic example of how you might set this up in Node.js:

const VoiceResponse = require('twilio').twiml.VoiceResponse;

app.post('/call/incoming', (_, res) => {
    const twiml = new VoiceResponse();
    twiml.connect().stream({ url: `wss://${process.env.SERVER_DOMAIN}/call/connection` });

    // Add statusCallback to handle call completion
    twiml.dial({
        statusCallback: 'https://your-server.com/call-status',
        statusCallbackEvent: ['completed'],
    });

    res.writeHead(200, { 'Content-Type': 'text/xml' });
    res.end(twiml.toString());
});

In this setup, replace 'https://your-server.com/call-status' with the URL of your endpoint where you want to receive the call details. When the call is completed, Twilio will send a request to this URL, including the call duration in the payload. You can then process this information as needed.

merry cargo
#

Does Conversational AI webhook provide the call duration ?