Initial push
This commit is contained in:
commit
76338d8e7c
13
Alexa-Skill/IntentSchema
Normal file
13
Alexa-Skill/IntentSchema
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"intents": [
|
||||
{
|
||||
"intent": "house",
|
||||
"slots": [
|
||||
{
|
||||
"name": "Control",
|
||||
"type": "Control_List"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
6
Alexa-Skill/SampleUtterances
Normal file
6
Alexa-Skill/SampleUtterances
Normal file
@ -0,0 +1,6 @@
|
||||
house to turn {Control}
|
||||
house can you turn {Control}
|
||||
house to turn {Control} please
|
||||
house {Control}
|
||||
house to turn the {Control}
|
||||
house to {Control}
|
8
Alexa-Skill/slots
Normal file
8
Alexa-Skill/slots
Normal file
@ -0,0 +1,8 @@
|
||||
television on
|
||||
tv on
|
||||
TV on
|
||||
t. v. on
|
||||
television off
|
||||
tv off
|
||||
TV off
|
||||
t. v. off
|
175
Lambda/AlexaSkill
Normal file
175
Lambda/AlexaSkill
Normal file
@ -0,0 +1,175 @@
|
||||
// Alexa SDK for JavaScript v1.0.00
|
||||
// Copyright (c) 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. Use is subject to license terms.
|
||||
'use strict';
|
||||
function AlexaSkill(appId) {
|
||||
this._appId = appId;
|
||||
}
|
||||
|
||||
AlexaSkill.prototype.requestHandlers = {
|
||||
LaunchRequest: function (event, context, response) {
|
||||
this.eventHandlers.onLaunch.call(this, event.request, event.session, response);
|
||||
},
|
||||
|
||||
IntentRequest: function (event, context, response) {
|
||||
this.eventHandlers.onIntent.call(this, event.request, event.session, response);
|
||||
},
|
||||
|
||||
SessionEndedRequest: function (event, context) {
|
||||
this.eventHandlers.onSessionEnded(event.request, event.session);
|
||||
context.succeed();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Override any of the eventHandlers as needed
|
||||
*/
|
||||
AlexaSkill.prototype.eventHandlers = {
|
||||
/**
|
||||
* Called when the session starts.
|
||||
* Subclasses could have overriden this function to open any necessary resources.
|
||||
*/
|
||||
onSessionStarted: function (sessionStartedRequest, session) {
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when the user launches the skill without specifying what they want.
|
||||
* The subclass must override this function and provide feedback to the user.
|
||||
*/
|
||||
onLaunch: function (launchRequest, session, response) {
|
||||
throw "onLaunch should be overriden by subclass";
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when the user specifies an intent.
|
||||
*/
|
||||
onIntent: function (intentRequest, session, response) {
|
||||
var intent = intentRequest.intent,
|
||||
intentName = intentRequest.intent.name,
|
||||
intentHandler = this.intentHandlers[intentName];
|
||||
if (intentHandler) {
|
||||
console.log('dispatch intent = ' + intentName);
|
||||
intentHandler.call(this, intent, session, response);
|
||||
} else {
|
||||
throw 'Unsupported intent = ' + intentName;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when the user ends the session.
|
||||
* Subclasses could have overriden this function to close any open resources.
|
||||
*/
|
||||
onSessionEnded: function (sessionEndedRequest, session) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Subclasses should override the intentHandlers with the functions to handle specific intents.
|
||||
*/
|
||||
AlexaSkill.prototype.intentHandlers = {};
|
||||
|
||||
AlexaSkill.prototype.execute = function (event, context) {
|
||||
try {
|
||||
console.log("session applicationId: " + event.session.application.applicationId);
|
||||
|
||||
// Validate that this request originated from authorized source.
|
||||
if (this._appId && event.session.application.applicationId !== this._appId) {
|
||||
console.log("The applicationIds don't match : " + event.session.application.applicationId + " and "
|
||||
+ this._appId);
|
||||
throw "Invalid applicationId";
|
||||
}
|
||||
|
||||
if (!event.session.attributes) {
|
||||
event.session.attributes = {};
|
||||
}
|
||||
|
||||
if (event.session.new) {
|
||||
this.eventHandlers.onSessionStarted(event.request, event.session);
|
||||
}
|
||||
|
||||
// Route the request to the proper handler which may have been overriden.
|
||||
var requestHandler = this.requestHandlers[event.request.type];
|
||||
requestHandler.call(this, event, context, new Response(context, event.session));
|
||||
} catch (e) {
|
||||
console.log("Unexpected exception " + e);
|
||||
context.fail(e);
|
||||
}
|
||||
};
|
||||
|
||||
var Response = function (context, session) {
|
||||
this._context = context;
|
||||
this._session = session;
|
||||
};
|
||||
|
||||
Response.prototype = (function () {
|
||||
var buildSpeechletResponse = function (options) {
|
||||
var alexaResponse = {
|
||||
outputSpeech: {
|
||||
type: 'PlainText',
|
||||
text: options.output
|
||||
},
|
||||
shouldEndSession: options.shouldEndSession
|
||||
};
|
||||
if (options.reprompt) {
|
||||
alexaResponse.reprompt = {
|
||||
outputSpeech: {
|
||||
type: 'PlainText',
|
||||
text: options.reprompt
|
||||
}
|
||||
};
|
||||
}
|
||||
if (options.cardTitle && options.cardContent) {
|
||||
alexaResponse.card = {
|
||||
type: "Simple",
|
||||
title: options.cardTitle,
|
||||
content: options.cardContent
|
||||
};
|
||||
}
|
||||
var returnResult = {
|
||||
version: '1.0',
|
||||
response: alexaResponse
|
||||
};
|
||||
if (options.session && options.session.attributes) {
|
||||
returnResult.sessionAttributes = options.session.attributes;
|
||||
}
|
||||
return returnResult;
|
||||
};
|
||||
|
||||
return {
|
||||
tell: function (speechOutput) {
|
||||
this._context.succeed(buildSpeechletResponse({
|
||||
session: this._session,
|
||||
output: speechOutput,
|
||||
shouldEndSession: true
|
||||
}));
|
||||
},
|
||||
tellWithCard: function (speechOutput, cardTitle, cardContent) {
|
||||
this._context.succeed(buildSpeechletResponse({
|
||||
session: this._session,
|
||||
output: speechOutput,
|
||||
cardTitle: cardTitle,
|
||||
cardContent: cardContent,
|
||||
shouldEndSession: true
|
||||
}));
|
||||
},
|
||||
ask: function (speechOutput, repromptSpeech) {
|
||||
this._context.succeed(buildSpeechletResponse({
|
||||
session: this._session,
|
||||
output: speechOutput,
|
||||
reprompt: repromptSpeech,
|
||||
shouldEndSession: false
|
||||
}));
|
||||
},
|
||||
askWithCard: function (speechOutput, repromptSpeech, cardTitle, cardContent) {
|
||||
this._context.succeed(buildSpeechletResponse({
|
||||
session: this._session,
|
||||
output: speechOutput,
|
||||
reprompt: repromptSpeech,
|
||||
cardTitle: cardTitle,
|
||||
cardContent: cardContent,
|
||||
shouldEndSession: false
|
||||
}));
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
module.exports = AlexaSkill;
|
88
Lambda/index
Normal file
88
Lambda/index
Normal file
@ -0,0 +1,88 @@
|
||||
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);
|
||||
|
||||
};
|
BIN
Lambda/index.zip
Normal file
BIN
Lambda/index.zip
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user