Skip to content

Instantly share code, notes, and snippets.

@yosun
Last active November 15, 2017 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yosun/1be49dad42b1d008e5207492096e612a to your computer and use it in GitHub Desktop.
Save yosun/1be49dad42b1d008e5207492096e612a to your computer and use it in GitHub Desktop.
therooms alexasjukk
'use strict';
const Alexa = require('alexa-sdk');
exports.handler = (event, context) => {
// TODO implement
const alexa = Alexa.handler(event, context);
alexa.appId = undefined;// "amzn1.ask.skill.c86d5355-97ac-4e3b-954e-5913e99c7e40";
// To enable string internationalization (i18n) features, set a resources object.
alexa.registerHandlers(handlers);
alexa.execute();
};
const handlers = {
'LaunchRequest': function () {
this.emit('GetRoom');
},
'enterroom': function () {
this.emit('GetRoom');
},
'Unhandled': function(){
this.emit('GetRoom');
},
'GetRoom': function () {
//check to see if the device we're working with supports display directives
//enable the simulator if you're testing
if(supportsDisplay.call(this)||isSimulator.call(this)) {
console.log("has display:"+ supportsDisplay.call(this));
console.log("is simulator:"+isSimulator.call(this));
var content = {
"simpleCardTitle" : this.t('SKILL_NAME'),
"bodyTemplateTitle" : null,
"bgimage" : "http://permute.xyz/_temp/cartoon-livingroom.png",
"bodyTemplateContent" : null,
"templateToken" : "factBodyTemplate",
"askOrTell" : ":tell",
"sessionAttributes": {}
};
renderTemplate.call(this, content);
} else {
// Just use a card if the device doesn't support a card.
this.emit(':responseReady');
}
},
'AMAZON.HelpIntent': function () {
const speechOutput = this.t('HELP_MESSAGE');
const reprompt = this.t('HELP_MESSAGE');
//this.response.speak(speechOutput).listen(reprompt);
this.emit(':responseReady');
},
'AMAZON.CancelIntent': function () {
const reprompt = this.t('STOP_MESSAGE');
// this.response.speak(speechOutput).listen(reprompt);
this.emit(':responseReady');
},
'AMAZON.StopIntent': function () {
this.response.speak(this.t('STOP_MESSAGE'));
this.emit(':responseReady');
},
};
//==============================================================================
//=========================== Helper Functions ================================
//==============================================================================
function supportsDisplay() {
var hasDisplay =
this.event.context &&
this.event.context.System &&
this.event.context.System.device &&
this.event.context.System.device.supportedInterfaces &&
this.event.context.System.device.supportedInterfaces.Display
return hasDisplay;
}
function isSimulator() {
var isSimulator = !this.event.context; //simulator doesn't send context
return isSimulator;
}
function renderTemplate (content) {
//create a template for each screen you want to display.
//This example has one that I called "factBodyTemplate".
//define your templates using one of several built in Display Templates
//https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/display-interface-reference#display-template-reference
switch(content.templateToken) {
case "factBodyTemplate":
// for reference, here's an example of the content object you'd
// pass in for this template.
// var content = {
// "hasDisplaySpeechOutput" : "display "+speechOutput,
// "hasDisplayRepromptText" : randomFact,
// "simpleCardTitle" : this.t('SKILL_NAME'),
// "simpleCardContent" : randomFact,
// "bodyTemplateTitle" : this.t('GET_FACT_MESSAGE'),
// "bodyTemplateContent" : randomFact,
// "templateToken" : "factBodyTemplate",
// "sessionAttributes": {}
// };
/*
{
"type": "BodyTemplate6",
"token": "string",
"backButton": "VISIBLE"(default) | "HIDDEN",
"backgroundImage": Image,
"title": "string",
"image": "Image",
"textContent": null
}
*/
var response = {
"version": "1.0",
"response": {
"directives": [
{
"type": "Display.RenderTemplate",
"template": {
"type": "BodyTemplate6",
"title": content.bodyTemplateTitle,
"token": content.templateToken,
"backgroundImage": content.bgimage,
"textContent": {
"primaryText": {
"type": "RichText",
"text": "<font size = '5'>"+content.bodyTemplateContent+"</font>"
}
},
"backButton": "HIDDEN"
}
}
],
"outputSpeech": {
"type": "SSML",
"ssml": "<speak>"+content.hasDisplaySpeechOutput+"</speak>"
},
"reprompt": {
"outputSpeech": {
"type": "SSML",
"ssml": "<speak>"+content.hasDisplayRepromptText+"</speak>"
}
},
"shouldEndSession": content.askOrTell==":tell",
"card": {
"type": "Simple",
"title": content.simpleCardTitle,
"content": content.simpleCardContent
}
},
"sessionAttributes": content.sessionAttributes
}
this.context.succeed(response);
break;
default:
this.response.speak("Thanks for chatting, goodbye");
this.emit(':responseReady');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment