I have an Azure Function HTTP trigger listening to Twilio webhooks. The AF is sitting on a premium service plan. It is returning intermittent 502 errors to Twilio at a fairly high rate of 6% (out of hundreds or thousands of successfuls). I really need to get to the bottom of why this is happening as we are missing important data.
All this trigger does is send the incoming webhook to a service bus and return an OK...I have another nearly identical http trigger in a different AF that hears millions of hits from SendGrid without failure. So I'm having trouble figuring out what the issue is here. Appreciate any advice, let me know if there are questions.
Here's my trigger code:
namespace TwilioWebhookListener
{
public class ReplyListener
{
private readonly AppSettings _settings;
IQueueClient queueClient;
public ReplyListener(AppSettings appSettings)
{
_settings = appSettings;
}
[FunctionName("Twilio-Reply-Listener")]
public async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "reply")] HttpRequest httpRequest,
ILogger log)
{
var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("", Encoding.Default, @"application/xml") };
try
{
log.LogInformation($"Twilio webhook - replyListener started at: { DateTime.UtcNow}");
string requestBody = await new StreamReader(httpRequest.Body).ReadToEndAsync();
queueClient = new QueueClient(_settings.ServiceBusConnection, "twilio-webhook-reply-messages");
await queueClient.SendAsync(new Message(Encoding.UTF8.GetBytes(requestBody)));
return response;
}
catch (Exception e)
{
log.LogInformation($"{DateTime.Now} :: Exception: {e.Message}");
return response;
}
}
}
}