2
votes

I have started to use Twilio Voice call recently for sending OTP to users using Django. I am referring to the given link to customise the Twilio response. https://www.twilio.com/docs/tutorials/walkthrough/click-to-call/python/flask

views.py

def voice_call(otp, mobile_no):
    client = TwilioRestClient(settings.ACCOUNT_SID, settings.AUTH_TOKEN)
    client.calls.create(from_=settings.OTP_FROM_NUMBER,
                        to=mobile_no,
                        url='http://localhost:8000/outbound/',
                        method='POST')


def outbound(self):
    response = twiml.Response()
    response.say("Thank you for contacting our department",
                 voice='alice')
    return HttpResponse(response, content_type="application/xml")

In urls.py, I have /outbound/ that points to my django view module.

If I hit '/outbound/' in browser it renders the correct xml response but in the voice call, it gives an error message saying 'Sorry application error'

Not sure where i am going wrong in rendering the xml. Thanks in advance.

1

1 Answers

1
votes

Twilio developer evangelist here.

I think the problem is that you are trying to point Twilio to your localhost. When Twilio connects the call, it will try to make an HTTP request to the URL you pass in the REST API call. If you pass localhost then Twilio won't be able to reach it as that is only available on your machine.

There is a solution though! We recommend using a tool called ngrok. It allows external services to tunnel through to your localhost so that you can test webhooks like this. Check out these blog posts on how to set up ngrok for use with Twilio and all the reasons I like using ngrok for developing with Twilio.

Let me know if that helps!