If you are anything like me, then you find coding in ColdFusion so much fun that when you're doing it, you tend forget about most other things like work and friends and loved ones and how early the cat wakes you up in the morning or why it's so freakin' hot in the office. As a result, those close to you might feel neglected. Here is a small, stand alone ColdFusion application that will help maintain the quality of your relationship by periodically prompting you to send a text message (SMS Message) to your girl friend (yes, I am aware of how sad this is). All you need are a few files and a scheduled ColdFusion task.
The first file is the XML data file that will define the text messages that the system will randomly select from:
Launch code in new window » Download code as text file »
Notice that there are some message node attributes being used:
mintime: This is the minimum value at which time a message can be considered valid for selection. For instance, the message "The day is so long" doesn't really make sense in the morning; and so, it is not valid until 4:00 PM.
maxtime: This is the maximum value at which time a message can be considered valid for selection. For instance, morning-related messages shouldn't be used in the afternoon.
days: This is a comma-delimited list of three-letter days in which the message is valid. For instance, weekend-related messages should not be valid early in the week, and therefore might have a Thr,Fri days attribute value.
You can, of course, put as many messages that you want. Each text message has a max length that it can be, which depends on the cellular carrier. I am not doing any validation checking for that.
The next file is the Application.cfc ColdFusion component where we define the application initialize it. The bulk of the initization imports the XML data files. We import not only the SMS message XML file, we also import a app_data.xml data file. This file contains information about the current state of the application including the time at which the next message can be send and the last three message IDs that were used.
Launch code in new window » Download code as text file »
As you can see, we are converting the SMS message data into a ColdFusion query object. We are doing this because based on the XML attributes, our message selection needs to have dynamic criteria. Nothing is better suited to this than a ColdFusion query of queries (man those QoQs really rock hard core!).
The NextMessage time stamp is there to limit the number of SMS text message prompts that we receive each day. This application is going to be launched via a scheduled task (which can be set to fire as often as you like). In order for "affection" to seem more natural, the frequency of the SMS text messages needs to seem more random. The NextMessage date/time value will allow the scheduled task to be run repeatedly without launching so many message prompts.
The PrevMessages array is a way for the system to not prompt you for the same message too often. That would sound far to mechanical. This helps take the burden off of you, the ColdFusion programming enthusiast, from having to keep all the outgoing SMS text messages straight in your head.
Now that we have the application defined, we are going to employ a two part process for sending out the text messages. We cannot just blindly send them out - what happens if we left our phones at home? What happens if we are at lunch with our targeted loved one? Getting a text message at those times would obviously be bad and ruin the party. Therefore, the system will email you with a confirmation prompt. Here is the code that selects the message (notice the dynamic criteria ColdFusion query of queries):
Launch code in new window » Download code as text file »
Notice that the bulk of the select message ColdFusion template is only run during the week and between the hours of 9am to 6pm and only if the current time is greater than or equal to the time of NextMessage. This is how we prevent too many text message email prompts from going out. Running that ColdFusion template will result in an email like this:
Hey Romeo, do you want to send out the following text message:
Wish I was at home with you.
SEND TEXT MESSAGE
If you read the text message and want to send it out, you simply click on the link "Send Text Message" and the text is sent out. The ColdFusion template responsible for sending out the SMS text message is confirm_message.cfm:
Launch code in new window » Download code as text file »
Notice that the SMS text message is sent using the Verizon Wireless cellular phone email account and a CFMail tag. This is the easiest way to accomplish this task. Once the message does get sent out, we update the system - the next available message time is updated and the current message ID is appended to the previous messages. We are storing the application setting data as XML via WDDX. WDDX, while I have some issues with it, provides a really easy and fast way for us to serialize and deserialize simple data for simple uses.
The To/From vtext numbers are hard coded, but these could easily be part of the application settings structure. Frankly, I just didn't think of it till the application demo was already done.
Please note that this post is just in good fun and I am NOT really that sad :)
Download Code Snippet ZIP File
Comments (15) | Post Comment | Ask Ben | Permalink | Other Searches | Print Page
no, you really ARE that sad.
Posted by some guy on May 21, 2007 at 8:43 PM
If I did that I would be bound to be found out. I would be off sick one day when the message "I wish I was at home with you" would pop up on her phone. Then she would think I really meant to send the message to someone else......
Maybe the plot for my next sitcom!
Posted by Kevin Roche on May 22, 2007 at 5:01 AM
Hurrah ! I'm *so* using this :-)
@Kevin: The confirmation link should stop 'you' sending if you are ill.
Posted by Tom Chiverton on May 22, 2007 at 6:04 AM
Ben,
you are not sad at all. This is brilliant!! He he, I'm absolutely going to make use of this.
Posted by Boyan on May 22, 2007 at 10:06 AM
I am glad that some people can appreciate the humor in this :)
Posted by Ben Nadel on May 22, 2007 at 10:09 AM
Btw, none but the first snippet download links work. Just FYI.
Posted by Boyan on May 22, 2007 at 10:17 AM
@Boyan,
Yeah the color coding I implemented a while back killed the code download :( I am working on fixing that. Sorry.
Posted by Ben Nadel on May 22, 2007 at 11:11 AM
The code pop-up and download code features are back in effect.
Posted by Ben Nadel on May 22, 2007 at 2:55 PM
@Ben
You are the man as usual. Thanks!
Posted by Boyan on May 22, 2007 at 4:29 PM
Doh! I forgot...just a simple idea - it would be really could if you could provide a way to download all the files/snippets in one zip file. You can use something like CFC Zipper - http://www.intersuite.com/client/index.cfm/2007/4/5/CFC-Zipper-15
Posted by Boyan on May 22, 2007 at 4:31 PM
@Boyan,
I think that is a tremendous idea. Consider it "in the works."
Posted by Ben Nadel on May 22, 2007 at 4:34 PM
@Ben
Great! You got a wish list somewhere? Or something of that sort? I want to get you something for all your help.
Posted by Boyan on May 23, 2007 at 8:59 AM
@Boyan,
I appreciate that, but your most excellent suggestions are payment enough. Check it out:
http://www.bennadel.com/index.cfm?dax=blog:722.view
Not quite there yet, but just about. You're like an idea machine; I love it!
Posted by Ben Nadel on May 23, 2007 at 9:15 AM
@Ben,
yeah, I saw that. Thanks! You are awsome! Thanks for the compliment but still - make a wishlist. I'm sure people will be happy to buy you a thing or two. I can't beleive you don't have one yet with all the help/code you provide to the CF community.
Just something I noticed on your front page - under "Recent Snippets", the last "recent" entry is from Sep-28-2006. Not sure if that's by design but thought I'd mention it.
Posted by Boyan on May 23, 2007 at 10:29 AM
Yeah the Snippets have basically fallen from grace. When I first started the blog I had this vision that I would blog about concepts and then provide examples via the Snippets section... but, once I really started going, what I realized was that I put the concepts AND snippets directly into the blog content. I tried duplicating the examples into the snippets as well, but that just because too much effort with too little time.
What I am planning to do is create a "Projects" section in the coldfusion section ( http://www.bennadel.com/coldfusion/ ) under which I will put documentation and snippets for bigger things like the POIUtility and SkinSpider and what not.
I will keep the snippets section linkable, but will probably remove it from the primary nav and the homepage. We shall see... its all up in the air at this point.
Posted by Ben Nadel on May 23, 2007 at 10:35 AM