0.0.2 • Published 10 years ago

thegeek v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

TheGeek

I made TheGeek to essentially bootstrap my projects involving email and sms (and eventually have also manage tasks). I am sort of new to making Node Modules so I sure this can be improved. Currently TheGeek can send and reveive emails and run jobs against said emails. It also can send SMS (using Twilio).

Version

0.0.1

Tech

Currently TheGeek relies on the following modules;

  • emailjs : Sending Email
  • lodash : I only use this in one spot for doing a deep clone, it probably could be phased out.
  • mail-listener2 : Listening for and parsing new mail.
  • twilio : send SMS.

Installation

npm install thegeek

Usage

Simple script that will watch your email and send a text to the given number with the email subject as the SMS body, then it will reply to the email with the status of the text using HTML. It will also queue a test job and run the email against it.

var Geek = require('thegeek'),
	geek = new Geek();

//Configure IMAP
//This connection is super simple, it assumes incoming and outgoing use same credentials and uses the default ports of 143 in / 587 out.
geek.imap.connect({
	host : "mail.somedomain.com",
	username : "madz@somedomain.com",
	password : "saltytearsofjoy"
}, function() {
	console.log("Imap Configured!");
});

//Configure Twilio
geek.sms.connect({
	sid : "ABC1234567890987654321123456789009",//Twilio SID
	token : "a1a1a1a1b2b2b2b2c3c3c3c3d4d4d4d4",//Twilio Token
	number : "+15555551234" //Twilio Number
}, function() {
	console.log("SMS Configured!");
});

//Our Job
var testJob = function(mail) {
	 if(mail.subject === "HELP!"){
	 	console.log("Add something useful in this function, because someone needs HELP!");
	 } 	
};

//Give the geek a job to do.
geek.imap.addJob("MyTestJob", testJob);


//On mail event.
geek.imap.on("mail", function(mail, index, attributes) {
	//run jobs (in this case there is only one)
	geek.imap.runJobs(mail);
	
	//Twilio message, send to that phone number with the email subject as the message
	var message = {
		to : "+15551239898",
		body : mail.subject
	};
	
	//send message
	geek.sms.send(message, function(err, message) {
		//set up reply email. 
		var reply = {
			text : "Testing",
			from : "<madz@somedomain.com>",
			to : mail.from[0].address,
			cc : "",
			subject : "Re: " + mail.subject,
			attachment : [{
			data : "",
			alternative : true
			}]
		};
		
		if (err) {
			reply.attachment[0].data = "<html><b><u>ERROR:</u></b><br>" + err.message + "</html>";
		} else {
			reply.attachment[0].data = "<html><b><u>SUCCESS:</u></b><br>" + message + "</html>";
		}	
		
		//send reply email.
		geek.imap.send(reply);
	});
});

geek.imap.start(function() {
	console.log("Geek has started!");
});

This is still a work in progress. I hope to add the ability to unzip files, add some transformation functions, maybe add some other listeners for services such as Twitter or Facebook, also I want to add the ability for this to add multiple email listeners (You can technically define multiple geeks to achieve the same thing, but I want the single instance to be able to do it).


I will document more later as this is just 0.0.1, check out the index.js though for now to see all the other config options for IMAP.

MIT

Free to use for whatever