Twilio callback not working in my .NET service

I am developing an SMS service that is expected to send SMS. Also, I need to track the status of the SMS.

I am using Twilio as my SMS provider and ServiceStack to implement the service level.

I can see that the SMS was sent successfully, however I am not getting any response for the configured callback url.

var message = MessageResource.Create(to: new PhoneNumber(sms.ToNumber),
from: new PhoneNumber(sms.FromNumber),
body: sms.MessageBody,
statusCallback: new Uri("http://8754622.ngrok.io/json/oneway/TwilioCallBack"));

      

I downloaded Ngrok and ran it to map a local site to make it accessible externally.

This is how I am trying to handle the callback from Twilio

public object Post(TwilioCallBack request)
{
    return _notificationProviderManager.SaveCallBackEvent(request.MessageStatus);
}

[Route("/TwilioCallBack", "POST")]
public class TwilioCallBack : INotificationCallBack
{
    public int id { get; set; }
        public string MessageStatus { get; set; }
}

      

As long as I see that the SMS has been delivered to the recipient's number, I don't see anything that could happen at the callback level.

Can anyone suggest what needs to be done?

Any help on this would be much appreciated.

thank

+3


source to share


2 answers


After many attempts and referring to various posts, I found out that Twilio callbacks do not work correctly if the request contains a query string.

In these cases, Twilio reports an error Failed to parse StatusCallback URL per RFC2396

, which we can see in the Twilio debugger.



This article covers the issue briefly - https://github.com/twilio/twilio-node/issues/145 The issue was flagged as resolved on Github by someone, but I was still facing the same issue. Hope someone looks in there.

Unfortunately I had to remove the query string parameters from the callback url, after which I could see the incoming POST requests and hit the service.

0


source


In case the callback is GET I would leave Route and impl open to accept any HTTP verb like:

public object Any(TwilioCallBack request) { ... }

[Route("/TwilioCallBack")]
public class TwilioCallBack { ... }

      



Since you've defined a custom route, you should probably use it (i.e. instead of the predefined route) in your callback:

statusCallback: new Uri("http://8754622.ngrok.io/TwilioCallBack"));

      

+2


source







All Articles