Midnight Frost
Midnight Frost

Reputation: 19

Twilio - Incoming Voice Webhook is getting called twice for the same call?

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)

Upvotes: 0

Views: 864

Answers (1)

Midnight Frost
Midnight Frost

Reputation: 19

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')

Upvotes: 1

Related Questions