Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twilio callback is not working in my .NET service

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

like image 650
Nirman Avatar asked Oct 18 '25 06:10

Nirman


1 Answers

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"));
like image 179
mythz Avatar answered Oct 20 '25 05:10

mythz