Send SMS and MMS Messages In Tcl/Tk
Time to read: 2 minutes
Today we'll use Tcl and the Tk graphical toolkit to rapidly prototype a Twilio-powered SMS and MMS sending application. We're going to be using the packages ttk (which will require Tcl 8.5+), tls, base64, and http.
Sign Up for (or Sign Into) a Twilio Account
You'll need to either have an existing Twilio account or create a new account to try out the Tcl code.
Don't have an account yet? Sign up for a free Twilio trial!
Purchase or Find a SMS-Capable Number
You'll need a SMS (or optionally, MMS) capable number to use this demo application. Purchase a new SMS-enabled number or use one that you already own.
From the Twilio Console, click the '#' hash tag to look at Phone Numbers. Any numbers you have purchased will have the capabilities listed in the middle. 'SMS' and 'MMS' enabled numbers will appear with an icon:
If you need to purchase a number, navigate to the 'Buy a Number' link and click the SMS checkbox (and optionally the MMS checkbox). Hit 'Search' and you should see all of the numbers available.
Prerequisites for This Tcl MMS and SMS Guide
Many POSIX-Compliant operating systems ship with a distribution of Tcl and a number of popular packages. tls
, however, may not be installed on your machine - you can access the tls package's site here. Alternatively, ActiveState maintains a number of excellent distributions of Tcl which make it easy to install packages.
TCL packages needed:
- tls
- http
- base64
- Tk
We were able to run the demo with the default Tcl8.5 distribution that comes with recent versions of Mac OS X. Here's an example session in bash on Mac OSX 10.11.6:
git clone https://github.com/TwilioDevEd/twilio-tcl-demo.git
cd twilio-tcl-demo
export TWILIO_ACCOUNT_SID=ACXXXXXXXXXXX
export TWILIO_AUTH_TOKEN=yourauthtokengoeshere
export TWILIO_PHONE_NUMBER=+18005551212
chmod 755 twilio.tcl
/usr/bin/tclsh8.5 /twilio.tcl # Or wherever; default 8.5 worked on our Mac
Send an SMS or MMS Message with TCL/Tk
Our sample application shows how to bring up a cross-platform GUI with Tcl and Tk, then quickly send out a text message.
The GUI code is pretty boilerplate, other than the fact we're taking full advantage of ttk widgets.
After submitting the form, we first run a function to get the current state of all the GUI elements. Your production application should perform more exhaustive checks than we're demonstrating, but for now we'll just let Twilio reject our out-of-scope requests (like letters instead of phone numbers!).
Following that, we get to the heart of the SMS and MMS sending code. The send_sms{}
procedure should be easily portable to your own application. It takes phone numbers, a message body, Twilio account credentials, and an optional media url as input and POSTS
to Twilio's REST API.
Whether Twilio sends out an MMS or an SMS depends on the content of the Media URL and the number's home country. Twilio currently supports MMS messages in the United States and Canada. Other countries will have the image appended to the body as an automatically shortened URL.
Tickle Your Fancy with Twilio and... Tcl
With the power of Twilio's REST APIs you can quickly integrate communications into your application, no matter the language. Whether that's embedding Twilio connectivity in your appliance, prototyping a desktop support application, SMSing the whole design team when the routes are too scenic or texting you when there's another Tcl flamewar on your favorite newsgroup... we've got your back.
With Twilio's API and your application, the possibilities are endless.
We can't wait to see what you build - let us know on Twitter when you've got something to show!
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.