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...

Troubleshooting a Discourse Update on DigitalOcean: Resolving Unresolvable Errors

For the past three years, I've maintained a Discourse server on a DigitalOcean Droplet. Recently, I decided to update it with some of the latest Discourse features. What I anticipated to be a straightforward update process turned into several days of frustrating setbacks. The version of Discourse I was running was already three years old, so I assumed that running the built-in "Update" feature would suffice. However, after clicking the update button, the progress bar sluggishly crawled forward over the next half hour, only to display the dreaded message: "Error – Update Failed." The logs provided little to no help, but based on my experience with other software updates via GIT, I suspected that the failure might be due to the repository head still being called "Master." In recent years, there has been a shift away from using "Master" as the repository head, with "Main" becoming the preferred term. Despite trying several methods ...

Ethereum Merge - So What?

Artwork by Steven Grundy The long awaited Ethereum "Merge" is finally upon us.  I've heard people say "So what".   So what?  I think they don't understand the implications of the merge.  Either that or they really are betting against Ethereum. I think this upgrade is probably the biggest thing for Ethereum since smart contracts first came out.  This change has the possibility of upsetting the apple cart in terms of Ethereum and BTC.  That's a big claim, but I really think it's possible. The Ethereum Merge has been set for the week of September 19th, 2022.  The merge is when the Ethereum execution layer will be joined with the new proof of stake consensus layer.  What does that mean and why should I care? What it means is that Ethereum will be changing from an energy intensive Crypto coin like all others to a 99% more efficient crypto coin like only a few have done.  Right now Ethereum is mined just like BTC and a host of other Crypto cur...