2016-12-19 16:34:44 +00:00

89 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 = '7474';
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* App ID for the skill
*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var APP_ID = "amzn1.ask.skill.3a572d72-bbf1-488b-ab9b-34e5947b1f27";
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* 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 = {
house: function (intent, session, response) {
//No matter what she wants to tell you her opinion.
function satisfyAlexa() {
response.tell("House Updated");
};
// Obtain User Intent
switch(intent.slots.Control.value) {
// List of triggers and URL to goto
case "television on":
case "tv on":
case "TV on":
case "t. v. on":
case "television off":
case "tv off":
case "TV off":
case "t. v. off":
path = 'code/TVPower';
break;
// List of triggers and URL to goto
case "test":
path = 'code/TVPower/';
break;
default:
response.tell("Sorry, I didnt understand that house 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);
};