When I try to call my Twilio Number that is attached to a Azure Function as a Webhook. I receive a busy line every time. I have tried another number and the same Azure function gets returns a busy line. I send a Post request to it and I am using Auth Token to Authenticate. I am using .NET 8 and have tried it on .NET 7 and this is an upgrade from the function that was originally running .NET Core 3.2.
My code is as below from my Business Logic:
public TwiMLResult ReplyWithMessageToCall()
{
VoiceResponse VR = new VoiceResponse().Say("HELLO");
var res = TwiML(VR);
return res;
}
And this is my Function code.
[Function("AnswerPhone")]
public TwiMLResult Run([HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req = null)
{
return _TwillioService.ReplyWithMessageToCall();
}
Twilio doesn't usually respond with a busy signal unless you a generating Reject twiml. If there is an error with your function it will usually play "An application error has occurred" and then disconnect.
[Edit] A related issue is that Azure Functions require some additional work to return XML. This could be why your current function is returning blank. Try removing TwiMLResult and replacing it with something like what is shown below. Below is some example code for how to return XML from an Azure Function running NET7 in isolated mode.
[Function("Return XML")]
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Function, "post", "get"] HttpRequestData req, FunctionContext executionContext)
{
var voiceresponse = new VoiceResponse();
voiceresponse.Say("Hello!");
var twiml = voiceresponse.ToString();
HttpResponseData response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Remove("Content-Type");
response.Headers.Add("Content-Type", "application/xml");
await response.WriteStringAsync(twiml);
return response;
}