2016-11-28 22:09:45 +00:00

91 lines
3.1 KiB
Plaintext

var http = require('http'); // if going through a proxy that uses SSL change to "require('https');"
// Your external IP. Alexa can only access publically-accessible IPs. No LAN access unfortunately.
// In my case I had to move receiver to DMZ
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var local_ip = 'home.k-world.me.uk';
var local_port = '8088';
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* App ID for the skill
*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var APP_ID = "amzn1.ask.skill.8f9502ec-5452-4c18-a8e5-6f2aed86d676";
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* The AlexaSkill prototype and helper functions
*/
var AlexaSkill = require('./AlexaSkill');
var DTVControl = function () {
AlexaSkill.call(this, APP_ID);
};
// Extend AlexaSkill
DTVControl.prototype = Object.create(AlexaSkill.prototype);
DTVControl.prototype.constructor = DTVControl;
//Ignore Certificate errors if using HTTPS communication
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
DTVControl.prototype.intentHandlers = {
desk: function (intent, session, response) {
//No matter what she wants to tell you her opinion.
function satisfyAlexa() {
response.tell("Desk Updated");
};
// Obtain User Intent
switch(intent.slots.Control.value) {
// List of triggers and URL to goto
case "red":
path = '/DeskControl/red.php';
break;
case "blue":
path = '/DeskControl/blue.php';
break;
case "green":
path = '/DeskControl/green.php';
break;
case "off":
path = '/DeskControl/off.php';
break;
default:
response.tell("Sorry, I didnt understand that desk request.");
break;
}
var options = {
host: local_ip,
port: local_port, // default port for webserver
path: '' + path, // Modify if path is prefixed
method: 'POST' //, //(remove first comment slashes if using the "auth" option below)
// auth: 'username:password' // this is used if going through authenticated proxy (this is BASIC AUTH)
};
var req = http.request(options, satisfyAlexa);
req.end();
}
}
exports.handler = function (event, context) {
var dtvControl = new DTVControl();
dtvControl.execute(event, context);
};