4

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

I am using Twilio as an SMS provider, and ServiceStack to implement Service Layer.

I can see the SMS being sent successfully, however, I am not getting any response on 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 have downloaded Ngrok, and running it to map the localhost site to make it accessible externally.

Following 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; }
}

While I can see the SMS getting delivered to the destination number, I cannot see anything happening at call back level.

Can anyone please suggest what needs to be done?

Any help on this will be much appreciated.

Thanks

Nirman
  • 6,715
  • 19
  • 72
  • 139
  • 1
    Are you seeing the callback in the ngrok logs (check http://127.0.0.1:4040 while ngrok is running) or not at all? – philnash May 22 '17 at 14:30
  • I just checked the log, and I am not seeing the callback in the ngrok logs. – Nirman May 23 '17 at 06:18
  • I have also verified that I can receive the response from Twilio, if I use requestbin URL, but I want to use ngrok as I want to perform further actions based on response. Also, If I simply copy-paste the Ngrok POST url in PostMan application, I can see the service getting invoked and code getting executed. Not sure, why Twilio is unable to send response to Ngrok configured URL! – Nirman May 23 '17 at 06:29

2 Answers2

2

In case the callback is a GET, I'd leave the Route and impl open to accept any HTTP Verb, e.g:

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

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

Since you've defined a custom route, you should likely be using it (i.e. instead of the predefined route) in the callback:

statusCallback: new Uri("http://8754622.ngrok.io/TwilioCallBack"));
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Thanks for your anwer, and much appreciated. As per the twilio official document, callback is POST. – Nirman May 22 '17 at 13:34
  • I could confirm that the response we get from Twilio is POST, as I checked it inside "requestbin". – Nirman May 22 '17 at 14:08
0

After a lot many attempts, and referring various posts, I came to know that Twilio callbacks are not working properly if the request contains a query string.

In those cases, Twilio reports Failed to parse StatusCallback URL per RFC2396 error which we can see in Twilio's debugger.

This post briefly addresses the issue - https://github.com/twilio/twilio-node/issues/145 The issue is marked as resolved in Github by someone, but I was still facing the same issue. Hoping for someone to look into there.

Unfortunately, I had to remove query string parameters from the callback URL, afterwhich I could see the POST requests coming in and hitting the service.

Nirman
  • 6,715
  • 19
  • 72
  • 139
  • Callbacks should work with a query string. Can you share the URL that caused the `Failed to parse` error? – philnash May 23 '17 at 14:09