var speechOutput;
var reprompt;
var myURL = 'https://sub.meinServer.de/';
var myWLAN = 'WLAN NAME';
var myPass = "großes Pkleines akleines skleines skleines wkleines okleines rkleines t";
var welcomeOutput = "Hallo! Womit kann behilflich sein? Für einen Überblick, was ich erledigen kann, sage Menü oder Liste.";
var welcomeReprompt = "Wie kann ich helfen? Sage z.B. Menü";
// 2. Skill Code =======================================================================================================
"use strict";
var Alexa = require('alexa-sdk');
var APP_ID = ''; // TODO replace with your app ID (OPTIONAL).
var speechOutput = '';
var handlers = {
'LaunchRequest': function () {
this.emit(':ask', welcomeOutput, welcomeReprompt);
},
'AMAZON.HelpIntent': function () {
speechOutput = 'Dieser Skill kann dir z.B. das Passwort zum Gäste WLAN vorlesen. Sage dazu, Alexa frage Gäste WLAN, wie lautet das Passwort?';
reprompt = 'probiere es mit nenne mir das Passwort';
this.emit(':ask', speechOutput, reprompt);
},
'AMAZON.CancelIntent': function () {
speechOutput = 'ok';
this.emit(':tell', speechOutput);
},
'AMAZON.StopIntent': function () {
speechOutput = 'ok';
this.emit(':tell', speechOutput);
},
'SessionEndedRequest': function () {
speechOutput = '';
//this.emit(':saveState', true);
this.emit(':tell', speechOutput);
},
'AMAZON.YesIntent': function () {
speechOutput = "OK ich wiederhole. " + myPass + " Soll ich es noch einmal wiederholen?";
this.emit(':ask', speechOutput, speechOutput);
},
'AMAZON.NoIntent': function () {
speechOutput = 'OK dann wünsche ich deinen Gästen viel Spaß beim surfen im Internet';
this.emit(':tell', speechOutput);
},
"MenuIntent": function () {
speechOutput = "Sage z.B. Gäste WLAN ein oder ausschalten. Du kannst mich auch fragen, wie ist das Passwort. Womit kann ich dir nun dienen?";
this.emit(":ask", speechOutput, speechOutput);
},
"WLANIntent": function () {
speechOutput = "Das Passwort lautet" + myPass +" Soll ich es noch einmal wiederholen?";
this.emit(":ask", speechOutput, speechOutput);
},
"WLANOnIntent": function () {
speechOutput = "Ok, ich habe das Gäste WLAN aktiviert. Der Name lautet " + myWLAN + ". Frage mich nun z.B. nach dem Passwort";
var url = 'wlan_ein.php';
getValue(url,(result)=>{
this.emit(":ask", speechOutput, speechOutput);
});
},
"WLANOffIntent": function () {
speechOutput = "Ok, ich habe nun das Gäste WLAN deaktiviert";
var url = 'wlan_aus.php';
getValue(url,(result)=>{
this.emit(":tell", speechOutput);
});
},
'Unhandled': function () {
speechOutput = "Ich habe dich leider nicht verstanden. Kannst du das Bitte noch einmal wiederholen?";
this.emit(':ask', speechOutput, speechOutput);
}
};
function getValue(loc,cb) {
var https = require('https');
let endpoint = myURL + loc;
let something = "";
let body = "";
https.get(endpoint, (response) => {
response.on('data', (chunk) => {
body += chunk;
});
response.on('end', () => {
//data = JSON.parse(body);
cb(null);
});
});
}
exports.handler = (event, context) => {
var alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};
function resolveCanonical(slot){
//this function looks at the entity resolution part of request and returns the slot value if a synonyms is provided
var canonical = '';
try{
canonical = slot.resolutions.resolutionsPerAuthority[0].values[0].value.name;
}catch(err){
console.log(err.message);
canonical = slot.value;
}
return canonical;
}
function delegateSlotCollection(){
console.log("in delegateSlotCollection");
console.log("current dialogState: "+this.event.request.dialogState);
if (this.event.request.dialogState === "STARTED") {
console.log("in Beginning");
var updatedIntent= null;
// updatedIntent=this.event.request.intent;
//optionally pre-fill slots: update the intent object with slot values for which
//you have defaults, then return Dialog.Delegate with this updated intent
// in the updatedIntent property
//this.emit(":delegate", updatedIntent); //uncomment this is using ASK SDK 1.0.9 or newer
//this code is necessary if using ASK SDK versions prior to 1.0.9
if(this.isOverridden()) {
return;
}
this.handler.response = buildSpeechletResponse({
sessionAttributes: this.attributes,
directives: getDialogDirectives('Dialog.Delegate', updatedIntent, null),
shouldEndSession: false
});
this.emit(':responseReady', updatedIntent);
} else if (this.event.request.dialogState !== "COMPLETED") {
console.log("in not completed");
// return a Dialog.Delegate directive with no updatedIntent property.
//this.emit(":delegate"); //uncomment this is using ASK SDK 1.0.9 or newer
//this code necessary is using ASK SDK versions prior to 1.0.9
if(this.isOverridden()) {
return;
}
this.handler.response = buildSpeechletResponse({
sessionAttributes: this.attributes,
directives: getDialogDirectives('Dialog.Delegate', updatedIntent, null),
shouldEndSession: false
});
this.emit(':responseReady');
} else {
console.log("in completed");
console.log("returning: "+ JSON.stringify(this.event.request.intent));
// Dialog is now complete and all required slots should be filled,
// so call your normal intent handler.
return this.event.request.intent;
}
}
function randomPhrase(array) {
// the argument is an array [] of words or phrases
var i = 0;
i = Math.floor(Math.random() * array.length);
return(array[i]);
}
function isSlotValid(request, slotName){
var slot = request.intent.slots[slotName];
//console.log("request = "+JSON.stringify(request)); //uncomment if you want to see the request
var slotValue;
//if we have a slot, get the text and store it into speechOutput
if (slot && slot.value) {
//we have a value in the slot
slotValue = slot.value.toLowerCase();
return slotValue;
} else {
//we didn't get a value in the slot.
return false;
}
}
//These functions are here to allow dialog directives to work with SDK versions prior to 1.0.9
//will be removed once Lambda templates are updated with the latest SDK
function createSpeechObject(optionsParam) {
if (optionsParam && optionsParam.type === 'SSML') {
return {
type: optionsParam.type,
ssml: optionsParam['speech']
};
} else {
return {
type: optionsParam.type || 'PlainText',
text: optionsParam['speech'] || optionsParam
};
}
}
function buildSpeechletResponse(options) {
var alexaResponse = {
shouldEndSession: options.shouldEndSession
};
if (options.output) {
alexaResponse.outputSpeech = createSpeechObject(options.output);
}
if (options.reprompt) {
alexaResponse.reprompt = {
outputSpeech: createSpeechObject(options.reprompt)
};
}
if (options.directives) {
alexaResponse.directives = options.directives;
}
if (options.cardTitle && options.cardContent) {
alexaResponse.card = {
type: 'Simple',
title: options.cardTitle,
content: options.cardContent
};
if(options.cardImage && (options.cardImage.smallImageUrl || options.cardImage.largeImageUrl)) {
alexaResponse.card.type = 'Standard';
alexaResponse.card['image'] = {};
delete alexaResponse.card.content;
alexaResponse.card.text = options.cardContent;
if(options.cardImage.smallImageUrl) {
alexaResponse.card.image['smallImageUrl'] = options.cardImage.smallImageUrl;
}
if(options.cardImage.largeImageUrl) {
alexaResponse.card.image['largeImageUrl'] = options.cardImage.largeImageUrl;
}
}
} else if (options.cardType === 'LinkAccount') {
alexaResponse.card = {
type: 'LinkAccount'
};
} else if (options.cardType === 'AskForPermissionsConsent') {
alexaResponse.card = {
type: 'AskForPermissionsConsent',
permissions: options.permissions
};
}
var returnResult = {
version: '1.0',
response: alexaResponse
};
if (options.sessionAttributes) {
returnResult.sessionAttributes = options.sessionAttributes;
}
return returnResult;
}
function getDialogDirectives(dialogType, updatedIntent, slotName) {
let directive = {
type: dialogType
};
if (dialogType === 'Dialog.ElicitSlot') {
directive.slotToElicit = slotName;
} else if (dialogType === 'Dialog.ConfirmSlot') {
directive.slotToConfirm = slotName;
}
if (updatedIntent) {
directive.updatedIntent = updatedIntent;
}
return [directive];
}