My last blog post explained how to create an app using SMSified, Node.js, the Node.js SMSified library and Nodester that forwards all text messages from an SMSified phone number to a personal cell phone. As I tested and used the app, I quickly determined what I really wanted was the ability to both receive and reply to SMS messages without ever exposing my actual mobile number. This isn’t a trivial problem to solve, though; in the SMS Forwarding app, I can hard code my phone number so all text messages sent to my SMSified number are redirected to me…that’s easy. If I want to reply back, however, the destination number would vary depending on who sent the original text.

The solution I decided on, due to simplicity and dependability, was to require the destination phone number in the reply. So if I receive a text message, it’ll look like this:

Caller: tel: 14075550100 -- Msg: SMSified rocks!
(your phone might include the   after tel:, others interpret it as a space)

When I reply back, my text would need to look like this:

14075550100 Told you.

Then in my app, I strip out the first ten characters of the reply, assign them as the destination phone number (the address) and everything else after those characters as the message, all using substr.

The following code is the complete application; it looks very similar to the SMS Forwarding app, except it’s a little cleaned up (some tweaking to implement DRY better and to reduce the amount of characters used in our messages) and now includes the new variables the if/else statement to handle the reply:

var sys = require('sys');
var express = require('express');
var app = express.createServer();
var smsified = require('smsified'); app.configure(function(){ app.use(express.bodyParser());
}); app.post('/', function(req, res){ var callerID = req.body['inboundSMSMessageNotification']['inboundSMSMessage']['senderAddress']; var message = req.body['inboundSMSMessageNotification']['inboundSMSMessage']['message']; var my_number = '14075550100'; var complete_msg = "Caller: "   callerID   " -- Msg: "   message; var sender = '15855550100'; var reply_id = message.substr(0,11); var reply_msg = message.substr(12); var sms = new SMSified('username', 'password'); if(callerID == "tel: "   my_number) { var options1 = {senderAddress: sender, address: reply_id, message: reply_msg}; sms.sendMessage(options1, function(result) { sys.puts(sys.inspect(result)); }); res.end(); } else { var options2 = {senderAddress: sender, address: my_number, message: complete_msg}; sms.sendMessage(options2, function(result) { sys.puts(sys.inspect(result)); }); res.end(); }
}); app.listen(10056);

As before, the app is hosted up on Github for your viewing and use. Let us know if you use the code for anything cool!

Update: In order to upload an app to Nodester when using the SMSified Node.js library, you’ll need to adjust the code slightly:

var sms = new smsified.SMSified('username', 'password');

Props to @matbeeDOTcom for the fix.

©2011 SMSified. All Rights Reserved.

.

Originally from All Voxeo Blogs Feed