Skip to main content

Sending SMS/MMS text messages via Twilio and ColdFusion in 5 minutes or less

Wow, almost exactly a year since my last post.   How some things change and other things don't.

On the one hand my father has passed away almost a year ago and that has left a big hole in our lives.  On the other hand a year ago BitCoin was at it's peak and was days away from jumping off the cliff.  Well it fell from about $19,000 all the way to $6000 where it has held for many months...until yesterday when it jumped off the cliff again. 

On to Twilio - I'm blown away with how easy it is to get communication components accomplished with Twilio.  We are using it for normal SMS text messages at TapCloud.  We also use it to send out our Authy based 2-Factor authentication tokens, and we are starting to use it for peer-to-peer and one-to-many video conferencing.

One of the great things about Twilio is just how easy it is to use.  Here's an example of just a handful of code that will let you go from start to finish so you'll be sending out MMS messages in about 5 minutes.  For those that don't know, MMS messages appear just like text messages (SMS) but they can also include media such as video, images, and sound.  MMS stands for Multimedia Messaging Service which is a lot harder to say than MMS.

Cutting to the chase, here's the ColdFusion code.  Obviously, use your own Auth Credentials which you can easily get by signing up with Twilio (www.twilio.com).  Due credit, this is based a lot on a very similar example by Ben Nadel.



twilio.accountSID = "111111";
twilio.authToken = "2222222";
twilio.phone = "+18475555555";
mediaUrl = "https://app.tapcloud.com/s/assets/sodiumfacts2.pdf";

twilioRequest = new Http(method = "post",
url = "https://api.twilio.com/2010-04-01/Accounts/#twilio.accountSID#/Messages",
username = twilio.accountSID,
password = twilio.authToken
);

twilioRequest.addParam(
type = "formfield",
name = "From",
value = twilio.phone
);

twilioRequest.addParam(
type = "formfield",
name = "To",
Value = "+18475555555"
);

twilioRequest.addParam(
type = "formfield",
name = "MediaUrl",
value = mediaUrl
);

twilioRequest.addParam(
type = "formfield",
name = "Body",
value = "The Doctor has asked that you follow these Salt guidelines for today:"
);

result = twilioRequest.send();



Done!



Believe it or not, that's all it is to it.  You are using your Twilio phone number in one variable, your destination phone number in another, and an URL pointing to your multimedia object in yet another variable.  Save that as a .CFM and run it and you'll be sending MMS messages to your heart's content.

Comments

  1. I like the work which you have placed in this article. This data is significant and superb. I might want to thank you for sharing this article here. affordable text marketing

    ReplyDelete
  2. Thanks for this... very easy to grasp. I find Nadel's examples too much. This is straight to the point.

    ReplyDelete
  3. This is very nice, and I have it saving all sent messages in a database. But the question I have is how to save the return messages in a database, including the MediaURL data if someone send a picture back in response

    ReplyDelete
  4. Also, how do you get the Twilio smsSID data back from Twilio when you send a message?

    ReplyDelete

Post a Comment

Popular posts from this blog

Dride Zero - Dashcam on Steroids

I took part in a Kickstarter project to build "The ultimate Dashcam".  One with front and back cameras that would shoot in HD, was durable and low power, and would upload video clips to the cloud with the push of a button.  We'll after waiting more than a year, they did just that.  I received my Dride Zero a couple of days ago and, other than an initial rocky "Setup" process, it has been working fantastic. This post isn't so much to talk about the Dride, you can get that information from them at https://dride.io.   This is more for those people who might run into the same issues with Setup that I had.  Hopefully this will save them some of the time I wasted trying to figure it out. Dride Zero Getting Started 1) Unpack from the shipping box.   To get started all you need at first is the Dride Camera, the powercord that has the cigarette lighter connector, and a 16Gb type 10 Micro SD card. 2) Insert the 16Gb Micro SD card in the slot on th

IOTA - A Beginner's Guide to Why IOTA Matters

IOTA is not your typical cryptocurrency.  IOTA, which typically stands for the Internet Of Things is a completely new approach to managing a blockchain. Blockchain technology is what made coins like Bitcoin (BTC) possible.  BTC is just a coin that uses the blockchain technology.  As I've said many times before, the "real" invention here was coming up with a blockchain that works.  To show that it works they created BTC.  The success of BTC is a very good indication of how well blockchains can work. Blockchains are what provide the audit trail of each transaction.  It is what allows you to purchase a digital "product" and be assured that the product is authentic and that you are the only one who owns that particular product.  It is what allows us to use BTC as money because it protects against counterfeiting.  Blockchains do have their limitations, most notably transaction speed, and IOTA solves these limitations.  This is hugely important because almost