sms gateway via ajax - c#

I am looking at implementing an SMS gateway to send SMS messages to phones from my application.
I was wondering if there are any services that would support sending of messages via AJAX from my views. So ideally, I would have a button on my page that calls the SMS service and passes a json message object to a SMS gateway and retrieves a response.
I'm more than happy building ajax post requests, but I have never used any form of SMS gateway so would appreciate any advice or pointers.
Many thanks

If I understand correctly you would like to use some paid SMS gateway provider like Twilio.
Sending sms via ajax from client application is possible but should not be done in public avaliable websites. Using REST api provided by Twilio you must provide authToken and sid these two will be avaliable for everyone who see your view, so everyone will have possibility to send sms/mms on your cost.
Correct architecture for such solution is to pass custom ajax request to your own server and then in private back end use gateway API library.
This topic was already raised, for example here:
Backbone/JS: looking to access the Twilio SMS API via an AJAX call
Here https://www.twilio.com/docs/libraries you can find libraries for all modern server technologies like .Net, Node.ja, Ruby etc.
And here is a little sample how to send a SMS from C#.
using System;
using Twilio;
class Example
{
static void Main(string[] args)
{
// Find your Account Sid and Auth Token at twilio.com/user/account
string AccountSid = "AC32a3c49700934481addd5ce1659f04d2";
string AuthToken = "";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendMessage("+14158141829", "+14159352345", "Jenny please?! I love you <3", "");
Console.WriteLine(message.Sid);
}
}

Related

Receiving SMS in C# with RingCentral

I am able to send SMS using C#. But my problem is I don't know to receive those SMS.
I looked into following documentation with WebHook and C# here:
https://developers.ringcentral.com/guide/notifications/quick-start/webhook/c-sharp
But not sure how to do it exactly.
Can I get any help to know how I can receive the SMS. Any sample will be great.
There are 3 ways to receive SMS:
PubNub Subscription
WebHook Subscription
API Request
Here are some details:
Using PubNub, you can receive SMS.
Check it out here: https://github.com/ringcentral/ringcentral-csharp-client/blob/master/RingCentral.Test/SubscripotionTest.cs#L31
Since this is used by PubNub, so you don't need ngrok
If you want WebHook, you need to subscribe for push notification check the reference demo: https://github.com/ringcentral/ringcentral-csharp-client/blob/master/RingCentral.Test/WebHookTest.cs
The direct API of RingCentral APIs to receive SMS content in your C#, by calling this API inside your SDK is: /restapi/v1.0/account/~/extension/~/message-store/{messageId}/content/{attachmentId}. Here you need to put the message id and the attachment id to retrieve message content from message-store
Hope this help.

How to send SMS from Twilio API using proxy

I'm new to Twilio and I am trying to create a sample code for sending SMS to a number. I already created account on Twilio and written a program which is working good on local. but now going further that program is not able to send SMS from Prod server. what i can to know that we can communicate to external uri through proxy. so i implemented proxy in my code. below is the property which i set for proxy information in TwilioRestClient.
var twilio = new TwilioRestClient(AccountSid, AuthToken);
twilio.Proxy = new WebProxy("http://ProxyAddress", 8080);
But this code is not working after adding proxy to it. can any one help me in this. is this the right way of doing that?

Making an custom content outbound voice call from console client

I am trying to make an outgoing call using Twilio and C#.
I gave the (fromnumber, tonumber, twiliodemourl) as 3 parameters for initiate
outbound call.Then it is working with default twilio demo voice content.
Now i need to customize the voice content attribute and some other attributes
every time i trigger the initiate outbound call method
I have gone through Twilio docs i did not find any good option for customize the
content dynamically from the code using C# every time i send the request.
My client application running periodically to verify for any new messages and then
trigger initiateoutboundcall.
I don't have any custom URL to post any new XML which voice is looking for in 3rd
parameter of initiateOutBoundCall.
So is it required a external domain URL to customize the voice content dynamically from code?
If no please provide the options/sample i have to do it from C# console application.
I tried to use the twimlets.com to echo the custom text to speak in the call.
For text change it is working fine with custom text. But i am not sure whether twimlets.com/echo can be used for production use? Please confirm. Twimlets is not supporting some of the features which i am looking for like Gather input
like IVR message for outbound call.
Using Twilio Voice and C# client:
Voice Request using Twilio C# client?
Dial the number with custom voice content(). If user not responds leave a
voice mail with the custom voice content().
Dial the number with custom voice content (). If user responds, after reading
the message need to provide options like:
press 1 for repeat the same voice message.
press 2 to confirm the action on the message.
press 3 to send SMS for the voice message.
Need to get the response for each voice call / message?
For the sms it send i am getting response as "queued" instead of message sent.
Based on the SMS sent successfully or not i need to update some flag.
So how i can get the SMS reponse as "sent".
SMSMessage sms = twilio.SendSmsMessage(sFromNumber, sToNumber, sMessage);
Console.WriteLine("SMS Status::::::" + sms.Status);
Similarly I need the reponse for voice call once the call is ring id done.
But it is giving "queued".
var call = twilio.InitiateOutboundCall(sFromNumber,sToNumber, url);
Console.WriteLine("Call Status" + call.Status);
So please provide me options for doing it using Twilio.
It would be great if you provide any sample example using C#.
Twilio evangelist here.
You do need some kind of public URL that Twilio can make an HTTP request to once the outbound call is answered. This is how Twilio gets the instructions it needs in order to proceed with the live, in-progress call.
As you noted there are a number of free options for hosting static TwiML content. Twimlets is one. Twimlbin.com is another. Both services are free and great places to at least get started prototyping or setting up a simple MVP of your application, but bear in mind that if you expect a large amount of traffic or you need to build something with your own custom logic in it you'll probably want to move to something else.
That something else could be your own website hosted as as Azure Website (which you can also get for free). Moving to your own website also means that you can scale it as needed and you can start serving up dynamically generated TwiML instead of just being limited to dynamic TwiML as you basically are with Twimlets or Twimlbin.
If you want to process input from <Gather> and none of the Twimlets meet your needs, then you will likely need to look at the Azure option (or some kind of hosted website, doesn't have to be Azure). This will let you build your own custom logic in order to process the callers input and dynamically generate a TwiML response based on that logic.
Twilio provides helper libraries for TwiML generation and for building Twilio apps using ASP.NET MVC, which you can get from NuGet.
Lets say you want to go down the road of building you own custom Twilio app using ASP.NET MVC and hosting it using an Azure Website. In that scenario, using our helper libraries you could build an action method in your controller that returns the TwiML with the <Say> and <Gather> verbs. Something like:
var response = new TwilioResponse();
response.Say("Hello World");
response.BeginGather(new { action="http://example.azurewebsites.com/gather/" } );
response.EndGather();
You would provide the URL that executes that action method as the third parameter in the initiaizeOutboundCall method eg:
client.IntializeOutboundCall(FROM, TO, "http://example.azurewebsites.net");
Once the user enters their input, Twilio will request the URL you specified in the <Gather> verbs action parameter passing you an extra HTTP parameter named Digits, which you can grab in your action method and use in your app logic:
public void Gather(string Digits) {
var response = new TwilioResponse();
response.Say("You pressed " + Digits);
return TwiML(response);
}
To get the status of a phone call or an SMS, you can include use the statuscallback parameter:
SMS: var result = client.SendMessage(FROM, TO, BODY, "http://example.azurewebsites.net/status");
Voice: var result = client.InitiateOutboundCall(FROM, TO, VOICEURL, "http://example.azurewebsites.net/status");
Twilio will make HTTP request to the statusCallback URL's once the final status of the message or call is reached.
Hope that helps.
As of version 5.32 of the C# SDK, you can pass a dynamic twiml string into the CallResource.Update() method like so:
CallResource.Update(
twiml: "<Response><Say>Custom Message Here</Say></Response>"
pathSid: call.Sid);
Or even:
string customMessage = "<Response><Say>Custom Message Here</Say></Response>"
CallResource.Update(
twiml: customMessage,
pathSid: call.Sid);

Twilio SMS sandbox using C#

How do you use the Twilio sandbox mode with C#? I have a ashx.cs file that I am using to write my code. Would I put it there? If so, what does that look like?
There is no real great examples on their website on how to do this except for CURL and Ruby.
We are using TwiML to general an XML file tha t parses our data to send back and forth to the Twilio service. We don't want to be charged every time we send a test text message.
How would we set the Sandbox up so we could do some testing.
I found the Test auth Token and account Sid, but how do I use those?
We don't have them in our current application and we are specifying our .ashx page in Twilio to process our code.
Thanks in advance.
Twilio evangelist here.
So if you just want to test that your ASHX handler is generating the right results the easiest way to do this is to just fake a POST or a GET request to that handler. This lets you simulate the GET or POST request that Twilio will make to your app when it gets a text message.
You can see the parameters that Twilio will pass to your app when it receives a text message here:
http://www.twilio.com/docs/api/twiml/sms/twilio_request#synchronous
There are a whole bunch of ways to simulate these requests. cURL is one of them. If your ASHX is expecting query string values, you can also just load the ASHX directly in the browser and append those values in the URL. If the handler is expecting a POST request, I used a chrome plugin called Simple REST Client to make these.
Of course you can also Fiddler to make just about any HTTP request.
The Test Credentials really are more for simulating the use of the REST API (programatically sending SMS messages). I just wrote a blog post that shows how to use the test credentials to create integration tests:
http://www.twilio.com/blog/2013/05/automating-twilio-integration-tests-with-test-credentials.html
Hope that helps.
Devin

How to send MMS with C#

I need to send MMS thought a C# application. I have already found 2 interesting components:
http://www.winwap.com
http://www.nowsms.com
Does anyone have experience with other third party components?
Could someone explain what kind of server I need to send those MMS? Is it a classic SMTP Server?
Typically I have always done this using a 3rd party aggregator. The messages are compiled into SMIL, which is the description language for the MMS messages. These are then sent on to the aggregator who will then send them through the MMS gateway of the Network Operator. They are typically charged on a per message basis and the aggregators will buy the messages in a block from the operators.
If you are trying to send an MMS message without getting charged then I am not sure how to do this, or if it is possible.
You could do it yourself. Some MMS companies just have a SOAP API that you can call. All you need to do is construct the XML and send it off via a URL. I have done this once before, but can't remember the name of the company I used.
This post earlier discussed different approaches for SMS and might be helpful for you.
You could use Twilio to accomplish this. You can dive into the docs for specific implementation details but using the C# helper library the code to send an MMS would look like this:
// Send a new outgoing MMS by POSTing to the Messages resource */
client.SendMessage(
"YYY-YYY-YYYY", // From number, must be an SMS-enabled Twilio number
person.Key, // To number, if using Sandbox see note above
// message content
string.Format("Hey {0}, Monkey Party at 6PM. Bring Bananas!", person.Value),
// media url of the image
new string[] {"https://demo.twilio.com/owl.png" }
);
Disclaimer: I work for Twilio.

Categories

Resources