module['exports'] = function coffeenator (hook) {
var myResponse;
var Particle = require('particle-api-js');
var particle = new Particle();
function output(data) {
hook.res.end(JSON.stringify(data, true, 2));
}
var token = 'PUT YOUR TOKEN HERE';
console.log(hook.params.result.parameters.action + " coffee request recieved");
if(hook.params.result.parameters.action=="warm")
{
warmCoffeeMachine();
var fnPr = particle.callFunction({ deviceId: 'PUT YOUR DEVICE ID HERE', name: 'warmmachine', argument: 'D0:HIGH', auth: token });;
fnPr.then(
function(data) {
console.log("success called warmcoffee succesfuly");
// output('Function called succesfully:', data);
myResponse =new MyResponse("Warming coffee machine for you","Coffee Machine Being Warmed","Coffee Machine");
hook.res.writeHead(200, {"Content-Type": "application/json"});
hook.res.end(JSON.stringify(myResponse, true, 2));
}, function(err) {
output('An error occurred:', err);
});
myResponse =new MyResponse("Warming coffee machine for you","Coffee Machine Being Warmed","Coffee Machine");
}else if (hook.params.result.parameters.action=="make")
{
makeCoffeeMachine();
var fnPr = particle.callFunction({ deviceId: 'PUT YOUR DEVICE ID HERE', name: 'makecoffee', argument: 'D0:HIGH', auth: token });;
fnPr.then(
function(data) {
console.log("success called make coffee succesfuly");
// output('Function called succesfully:', data);
myResponse =new MyResponse("Making coffee for you","Coffee Being made ","Coffee Machine");
hook.res.writeHead(200, {"Content-Type": "application/json"});
hook.res.end(JSON.stringify(myResponse, true, 2));
}, function(err) {
output('An error occurred:', err);
});
myResponse =new MyResponse("Making coffee for you","Coffee Being made ","Coffee Machine");
}
console.log("****************end end end end end end ");
function MyResponse(aSpeech,aDisplaytext,aSource){
this.speech = aSpeech;
this.displayText= aDisplaytext;
this.source=aSource;
}
};
function warmCoffeeMachine()
{
console.log("machine is warming");
}
function makeCoffeeMachine()
{
console.log("machine is making");
}
Comments