0
votes

Trying to understand why the incoming voice call webhook is getting called twice.

I'm using an Azure Function with a HTTP trigger. Python 3.

It returns a valid TwiML once when I test it through the web browser and look at the logs.

<?xml version="1.0" encoding="UTF-8"?><Response><Say>hello this is a test </Say><Play digits="wwww#" /></Response>

However, when I call the Twilio number it begins saying "hello this is a test" followed by ringing and the same message played again. My phone then displays called failed.

When I place the same XML code in a TwiML bin it works perfectly, only firing once.

Having a similar problem to this person: Incoming Voice Webhook is getting called twice for the same call


More information - code in the function

import logging
from twilio.twiml.voice_response import Say, Play, VoiceResponse
import azure.functions as func


def main(req: func.HttpRequest) -> func.HttpResponse:
    response = VoiceResponse()
    response.say('hello this is test bots')
    response.play('', digits='wwww#')

    return func.HttpResponse(str(response), status_code=200)
1
The other link I can explain, sometimes based on a Session Initiation Protocol (SIP) response, a carrier may retry a call, thinking the original carrier is unable to terminate it. The new CallSID is the clue in this case. Not common for a Busy (486 Response Code) but it appears that was the case. I cannot explain why your webhook is being called twice however. If you look in your Call Logs for the CallSID(s), what do you see as TwiML from your Azure function? Did you configure a failover URL possibly and that is firing?Alan
Hi @Alan, checking out the call logs and there are two different CallSIDs both returning Last SIP Response 603 Decline I see the same TwiML from the post above and I have not configured a failover URL.Midnight Frost
@Alan any idea why the code from a TwiML bin is successful and the azure function causes an error? Added pictures of the requests to the orginal postMidnight Frost
My recommendation it to use a tool like Postman (postman.com) and compare the Content-Type and the HTTP Response codes (most likely here), there has to be a difference there. You won't be able to do this with a TwiML Bin (since it checks for a specific signature header - X-Twilio-Signature), but use this URL instead, and then compare it to your Azure functions endpoint response, demo.twilio.com/docs/voice.xml.Alan
@Alan thank you for the suggestion!! I hadn't set the Content-Type to text/xml. It's now working normallyMidnight Frost

1 Answers

1
votes

Thanks Alan for helping me solve this.

I needed to add the header Content-Type with value 'text/xml'

added parameter mimetype='text/xml' to the func.HttpResponse()

import logging
from twilio.twiml.voice_response import Say, Play, VoiceResponse
import azure.functions as func

def main(req: func.HttpRequest) -> func.HttpResponse:
    response = VoiceResponse()
    response.say('hello this is test bots')
    response.play('', digits='wwww#')

    return func.HttpResponse(str(response), status_code=200, mimetype='text/xml')