Looking to set up Twilio's SMS service so that when a user presses a certain button, it leverages my account with Twilio to send a text.
Using Backbone.js with coffeescript, and this has to be done client-side for the moment, so I'm doing something like this:
events: {
"click .button": "sendText"
}
and then sendText
looks like this:
sendText: ()->
accountSid = '{my account sid}'
authToken = '{my auth token}'
ToNumber = "{string of a number to text to}"
FromNumber = "{string of my Twilio number}"
Body = escape("Hey, this is working.")
myJSONData = "To=%2B1" + ToNumber + ", From=%2B1" + FromNumber + ", Body=" + Body
$.ajax({
type: 'POST',
url: 'https://api.twilio.com/2010-04-01/Accounts/'+ accountSid + '/SMS/Messages',
data: myJSONData,
success: (data) -> {
console.log('SMS sent successfully!')
}
})
Is this heading in the right direction? I know that I haven't entered my auth credentials anywhere yet, but I'm not certain where to do that yet.