Skip to content

Instantly share code, notes, and snippets.

@dovy
Last active April 28, 2017 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dovy/3407588e06ffc7f582cd5eca6b225275 to your computer and use it in GitHub Desktop.
Save dovy/3407588e06ffc7f582cd5eca6b225275 to your computer and use it in GitHub Desktop.
Sickie button
{
"button": {
"id": "" // Your button ID
},
"gmail": {
"user": "", // Gmail user/email
"pass": "" // Gmail pass
},
"message": {
"from": "From Message", // Whatever you want the from to say
"to": [ "" ], // Put in as many "emails" as you want
"subject": "Sickie Button Pressed!"
}
}
#! /usr/bin/env node
const config = require('./config.json');
const dash_button = require('node-dash-button');
const nodemailer = require('nodemailer');
// TODO: accept and register an array of button MACs
const dash = dash_button(config.button.id);
const util = require('util');
const _ = require('lodash');
const when = require('when');
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: config.gmail.user,
pass: config.gmail.pass
}
});
// setup email data with unicode symbols
let mailOptions = {
from: config.message.from, // sender address
to: config.message.to.toString(), // list of receivers
subject: config.message.subject, // Subject line
text: new Date().toISOString().
replace(/T/, ' '). // replace T with a space
replace(/\..+/, '') // delete the dot and everything after
};
console.log('waiting for dash button to be pressed...');
dash.on('detected', () => {
console.log('Dash button detected!');
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message %s sent: %s', info.messageId, info.response);
});
// for now we can ignore the promise as it handles any logging and we've no need to care about when it resolves or rejects
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment