-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3095ef8
commit e33b5a0
Showing
8 changed files
with
522 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
archive.zip | ||
.DS_Store | ||
src/device.json | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var gulp = require('gulp'); | ||
var lambda = require('gulp-awslambda'); | ||
var zip = require('gulp-zip'); | ||
|
||
gulp.task('default', function() { | ||
return gulp.src('src/**') | ||
.pipe(zip('archive.zip')) | ||
.pipe(lambda('particle', { region: 'us-east-1', profile: 'bp' })) | ||
.pipe(gulp.dest('.')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"intents": [ | ||
{ | ||
"intent": "SetBrightness", | ||
"slots": [ | ||
{ | ||
"name": "Brightness", | ||
"type": "AMAZON.NUMBER" | ||
}, | ||
{ | ||
"name": "Room", | ||
"type": "LIST_OF_ROOMS" | ||
} | ||
] | ||
}, | ||
{ | ||
"intent": "SetMode", | ||
"slots": [ | ||
{ | ||
"name": "Mode", | ||
"type": "LIST_OF_MODES" | ||
}, | ||
{ | ||
"name": "Room", | ||
"type": "LIST_OF_ROOMS" | ||
} | ||
] | ||
}, | ||
{ | ||
"intent": "SetColor", | ||
"slots": [ | ||
{ | ||
"name": "Color", | ||
"type": "LIST_OF_COLORS" | ||
}, | ||
{ | ||
"name": "Room", | ||
"type": "LIST_OF_ROOMS" | ||
} | ||
] | ||
}, | ||
{ | ||
"intent": "AMAZON.HelpIntent" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "ask-particle", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": ["alexa", "particle", "photon"], | ||
"author": "brendonparker", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"gulp": "^3.9.1", | ||
"gulp-awslambda": "^0.4.0", | ||
"gulp-zip": "^3.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
SetMode set mode to {Mode} | ||
SetMode set mode to {Mode} in {Room} | ||
|
||
SetBrightness set brightness to {Brightness} | ||
SetBrightness set brightness to {Brightness} in {Room} | ||
SetBrightness set brightness to {Brightness} percent | ||
SetBrightness set brightness to {Brightness} percent in {Room} | ||
|
||
SetColor set color to {Color} | ||
SetColor set color to {Color} in {Room} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
Oops, something went wrong.