Reputation: 83
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
Upvotes: 1
Views: 543
Reputation: 1187
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);
}
}
Upvotes: 0