1

This question relates to Twilio and the API for it (C#).

I do not have a website nor a web application, just a need to send SMS notifications to my own private mobile when something happens on a server (NOT a webserver). I have already, successfully, sent SMS to my mobile from a C# dll. I want to check the status of the message. All the references imply website/web application use cases, and getting the status using a URL.

How do I do this in C#? Is there an example of the suggestion made here? No PHP or other web servery technology.

Community
  • 1
  • 1
  • You can use Twilio's C# client to send a message. – SLaks Dec 30 '12 at 22:16
  • I don't think you can lookup the status of an SMS like that. You need to wait for the callback to hit your server. – Greg Dec 30 '12 at 22:17
  • Hi Greg. A little more info would be good? Cheers – Harrison Stacked Dec 30 '12 at 23:09
  • You can *send* an SMS with a simple HTTP request from just about any application/server. You can't *receive* an SMS without setting the URL and having it hit a server somewhere. Here's an example that should help: http://www.twilio.com/docs/quickstart/csharp/sms/sending-via-rest – CaseySoftware Dec 31 '12 at 00:41
  • @CaseySoftware: I dont want to _receive_ an SMS, just the (updated) response to _sending_ one, because when initially sent the SMSMessage object has a status of "queued". I need to find out through the DLL whether the notifications been sent, or it has failed. – Harrison Stacked Dec 31 '12 at 02:44

3 Answers3

6

The solution I found, was ridiculously simple. The suggestion (made here) was to hang on to the message id. I discovered the GetSMSMessage method on TwilioRestClient. So querying message status some time after sending will give you the updated status.

Community
  • 1
  • 1
0

By the way, the one thing you'll want to watch out for is that if you query the API too soon, you might get a status of "queued" or "sending" rather than "sent" or "failed", so be sure that your logic is set up to handle these other possible responses.

Also good to keep in mind that if you try to send more than 1 message per-second via a Twilio phone number, Twilio will queue the excess messages and release them at a rate of 1 message per-second per-number. This comes into play because if you have a burst where you send 10 messages in 1 second, but then you go to retrieve the status of the messages after 5 seconds half of the messages will be "sent" and half will be "queued".

TrentonMcManus
  • 487
  • 1
  • 7
  • 16
0

If you dont have a callback url. Just call the method

TwilioClient.Init(accountSid, authToken);

var message = MessageResource.Create(
            body: "Join Earth's mightiest heroes. Like Kevin Bacon.",
            from: new Twilio.Types.PhoneNumber(fromNumber),
            to: new Twilio.Types.PhoneNumber(toNumber)
        );

Console.WriteLine(message.Sid);

//Get the status from twilio
TwilioClient.Init(accountSid, authToken);

var verificationCheck = MessageResource.Fetch(message.Sid);

Console.WriteLine(verificationCheck.Status);

where Sid is the id you get back from Twilio.

John Kuriakose
  • 4,065
  • 2
  • 13
  • 20