Skip to content

Commit

Permalink
Ported to Twilio. Removed CouchDB logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
mheadd committed Jan 4, 2013
1 parent 9b62781 commit 53c48cc
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 60 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
config/config.js
.buildpath
.project
.settings/*

node_modules/
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2011 Mark J. Headd (http://www.voiceingov.org)
Copyright (c) 2013 Mark J. Headd (http://civic.io)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ This app is built with:

[Node.js](http://nodejs.org/), specifically the following modules are used:

* [SMSified-node](https://github.com/smsified/smsified-node) - A module for sending and receiving SMS messages (text messages) with the SMSified API.
* [cradle](https://github.com/cloudhead/cradle) - a high-level, caching, CouchDB client
* [node-twilio](https://github.com/sjwalter/node-twilio) - A Twilio helper library for node.
* [geonode](https://github.com/feliperazeek/geonode) - A very basic, but simple, geocode library, currently using Google Geocode API (v3)
* [google-places](https://github.com/jpowers/node-google-places) - A Google Places lib for node.js.

The application uses the [SMSified](http://smsified.com) platform to send and receive text messages.
16 changes: 5 additions & 11 deletions config/config-sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ Config = function() {
// Google
this.google_api_key = '';

// SMSified
this.smsified_user = '';
this.smsified_password = '';
this.smsified_sender_address = '';

// CouchDB
this.couchdb_host = '';
this.couchdb_port = '';
this.couchdb_user = '';
this.couchdb_password = '';
this.couchdb_name = '';
// Twilio
this.twilio_sid = "";
this.twilio_token = "";
this.twilio_host = "";
this.twilio_outgoing = "";

};

Expand Down
55 changes: 13 additions & 42 deletions finditforme.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// Include required modules.
var http = require('http');
var smsified = require('smsified');
var qs = require('querystring');
var RestClient = require('twilio').RestClient;
var geo = require('geo');
var cradle = require('cradle');
var GooglePlaces = require('./modules/google-places');

// Include and instantiate config.
require('./config/config');
var config = new Config();
var config = require('./config/config')();

// Create HTTP server to process inbound requests from SMSified
var server = http.createServer(function inboundSMSServer(req, res) {


// Variable to hold JSON payload.
var payload = '';

Expand All @@ -23,12 +21,11 @@ var server = http.createServer(function inboundSMSServer(req, res) {

// Process inbound message.
req.addListener('end', function processPayload() {

var json = JSON.parse(payload);
var inbound = new InboundMessage(json);
var address = config.getAddress(inbound.message);
var type = config.getType(inbound.message).toLowerCase();
var senderNumber = inbound.senderAddress;

var message = qs.parse(payload);
var address = config.getAddress(message.Body);
var type = config.getType(message.Body).toLowerCase();
var senderNumber = message.From;

// Geocode address from the SMS message.
geo.geocoder(geo.google, address, false, function geocodeAddress(formattedAddress, latitude, longitude) {
Expand All @@ -45,39 +42,13 @@ var server = http.createServer(function inboundSMSServer(req, res) {
else {
var answer = config.formatResponse(type, response.results[0]);
}

// Create log record.
var logRecord = {
user: senderNumber,
address: address,
lat: latitude,
lon: longitude,
type: type,
message: answer
};

// Set up connection to CouchDB instance for logging.
var logdb = new (cradle.Connection)(config.couchdb_host, config.couchdb_port, {
auth : {
username : config.couchdb_user,
password : config.couchdb_password
}
}).database(config.couchdb_name);

// Send response SMS message.
var sms = new SMSified(config.smsified_user, config.smsified_password);
var options = {senderAddress: config.smsified_sender_address, address: senderNumber, message: answer};

// Send response to user & log result.
sms.sendMessage(options, function sendSMSMessage(result) {
logRecord.result = result;
logdb.save(logRecord, function saveLogRecord(err, res){
if(err) {
console.log('An error occured when saving message log: ' + err.error + ' ' + err.reason);
}
});
// Send response SMS message & log result.
var sms = new RestClient(config.twilio_sid, config.twilio_token);
sms.sendSms(config.twilio_outgoing, senderNumber, answer, function sendSMS() {
res.writeHead(200);
res.end();
});


});

Expand Down
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "finditforme",
"version": "0.0.1",
"description": "SMS-based locator for places of interest Philly",
"main": "finditforme.js",
"dependencies": {
"google-places": "*",
"twilio": "0.4.1",
"geo":"*"
}
}

0 comments on commit 53c48cc

Please sign in to comment.