Search code examples
debuggingloggingstreamtwiliotwilio-programmable-voice

Not able to properly debug. Twilio Voice Bi-Directional Stream Logs?


We are having a hard time trying to get data on timestamps and delays on each point of:

  1. User making a call to Twilio Number,
  2. Invoking of the TWiML URL,
  3. Sending and Receiving of Bi-Directional Stream data,
  4. Sending data back to user.

Now, Twilio does provide logs on 2nd point as serverless API logs and top level events inside it. But there are no further information apart from that.

Is there a way to get this or is there something inside Twilio already to achieve this?

I have tried going through their docs and their youtube Signal videos. But I am not able to find a direct or in-direct way to achieve this.


Solution

  • Twilio makes available Custom Parameters to Share Information Between Your Applications.

    For example, if you append a URL query parameter to a Twilio REST API request, Twilio will return that parameter in the response.

    curl -X POST https://api.twilio.com/2010-04-01/Accounts/ACxxxxxxxxxx/Calls.json 
    --data-urlencode "Url=https://website.com/instructions" 
    --data-urlencode "To=sip:[email protected]?displayName=Alice&customerID=375d1d60-083b-404d&selectedProductID=87144192-73e2-45a6" 
    --data-urlencode "From=+15017122661" 
    -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
    

    In the above example, when your Twiml endpoint https://website.com/instructions is called by Twilio, these parameters will also be included:

    displayName=Alice

    customerID=375d1d60-083b-404d

    selectedProductID=87144192-73e2-45a6

    This will allow your application and Twilio to stay in sync.

    For your question about Timestamps, you could pass a parameter such as "OriginatedTimestamp=2023-10-22T10:12:07.5980142Z"

    Then when you receive a response, Twilio will include its own Timestamp and you can compare your OriginatedTimestamp with the Twimlio Timestamp parameter. This page lists all the properties for a Call resource.

    If you haven't set it up already, Ngrok makes it very easy to view the properties returned by Twilio - Twilio explains this in a blog post about using Ngrok in 2022. A tool like Fiddler will allow you to view your outgoing requests to Twilio while Ngrok will allow you to view the corresponding replies from Twilio.