Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var personen = {
- "Heiko" : {
- "persönlichkeit": "Triggered gerne andere",
- "skill": "Kann gut lol Spielen"
- },
- "Dominik" : {
- "persönlichkeit": "Ist komisch",
- "skill": "ERROR: Skill.exe not found"
- },
- }
- exports.handler = function (event, context) {
- try {
- console.log("event.session.application.applicationId=" + event.session.application.applicationId);
- if(event.session.new){
- onSessionStarted({requestId: event.request.requestId}, event.session);
- }
- if (event.request.type === "LaunchRequest") {
- onLaunch(event.request,
- event.session,
- function callback(sessionAttributes, speechletResponse) {
- context.succeed(buildResponse(sessionAttributes, speechletResponse));
- });
- } else if (event.request.type === "IntenRequest") {
- onIntent(event.request,
- event.session,
- function callback(sessionAttributes, speechletResponse) {
- context.succeed(buildResponse(sessionAttributes, speechletResponse));
- });
- } else if (event.request.type === "SessionEndedRequest") {
- onSessionEnded(event.request, event.session);
- context.succeed();
- }
- } catch (e) {
- context.fail("Exception: " + e);
- }
- };
- function onSessionStarted(sessionStartedRequest, session){
- }
- function onLaunch(launchRequest, session, callback) {
- getWelcomeResponce(callback)
- }
- function onIntent (intentRequest, session, callback) {
- var intent = intentRequest.intent
- var intentName = intentRequest.intent.name;
- if(intentName == "TestIntent") {
- handleTestResponse(intent, session, callback)
- } else if (intentName == AMAZON.YesIntent) {
- handleYesResponce(intent, session, callback)
- } else if (intentName == AMAZON.NoIntent) {
- handleNoResponce(intent, session, callback)
- } else if (intentName == AMAZON.HelpIntent) {
- handleGetHelpRequest(intent, session, callback)
- } else if (intentName == AMAZON.StopIntent) {
- handleFinishSessionRequest(intent, session, callback)
- } else if (intentName == AMAZON.CancelIntent) {
- handleFinishSessionRequest(intent, session, callback)
- }else {
- throw "Invalid intent"
- }
- }
- function onSessionEnded(sessionEndedRequest, session) {
- }
- function getWelcomeResponce(callback) {
- var speechOutput = "Jo digga was geht?" + "Willst du etwas über Heiko oder Dominik erfahren?"
- var reprompt = "Alter, was ist das nur für 1 Life entscheide dich mal!"
- var header = "Random Infos"
- var shouldEndSession = false
- var sessionAttributes = {
- "speechOutput" : speechOutput,
- "reprompt" : reprompt
- }
- callback(sessionAttributes, buildSpeechletResponse(header, speechOutput, reprompt, shouldEndSession))
- }
- function handleTestResponse(intent, session, callback) {
- var person = intent.slots.Test.value.toLowerCase()
- if(!personen[person]) {
- var speechOutput = "Alter, das Ist keine verfügbare Möglichkeit du noob"
- var repromptText = "Versuch halt mal was anderes wie z.B Heiko oder Dominik"
- var header = "Nicht Verfügbar"
- } else {
- var persönlichkeit = personen[person].persönlichkeit
- var skill = personen[person].skill
- var speechOutput = capitalizeFirst(person) + " " + persönlichkeit + " und " + skill + ". Willst noch was anderes Wissen?"
- var repromptText = "Willst noch was anderes Wissen?"
- var header = capitalizeFirst(person)
- }
- var shouldEndSession = false;
- callback(session.attributes, buildSpeechletResponse(header, speechOutput, repromptText, shouldEndSession))
- }
- function handleYesResponce(intent, session, callback) {
- var speechOutput = "Ok über wen willst du etwas erfahren? Es gibt Heiko und Dominik"
- var repromptText = speechOutput
- var shouldEndSession = false
- callback(session.attributes , buildSpeechletResponseWithoutCard(speechOutput,repromptText,shouldEndSession))
- }
- function handleNoResponce(intent, session, callback) {
- handleFinishSessionRequest(intent,session,callback)
- }
- function handleGetHelpRequest(intent, session, callback) {
- if(!session.attributes) {
- session.attributes = {};
- }
- var speechOutput = "Ich kann die alles über diese Personen sagen: Heiko, Dominik"
- var repromptText = speechOutput
- var shouldEndSession = false;
- callback(session.attributes,buildSpeechletResponseWithoutCard(speechOutput, repromptText, shouldEndSession))
- }
- function handleFinishSessionRequest(intent, session, callback) {
- callback(session.attributes,
- buildSpeechletResponseWithoutCard("Tschau du Lappen","Bis bald",true));
- }
- // ------- Helper functions to build responses for Alexa -------
- function buildSpeechletResponse(title, output, repromptText, shouldEndSession) {
- return {
- outputSpeech: {
- type: "PlainText",
- text: output
- },
- card: {
- type: "Simple",
- title: title,
- content: output
- },
- reprompt: {
- outputSpeech: {
- type: "PlainText",
- text: repromptText
- }
- },
- shouldEndSession: shouldEndSession
- };
- }
- function buildSpeechletResponseWithoutCard(output, repromptText, shouldEndSession) {
- return {
- outputSpeech: {
- type: "PlainText",
- text: output
- },
- reprompt: {
- outputSpeech: {
- type: "PlainText",
- text: repromptText
- }
- },
- shouldEndSession: shouldEndSession
- };
- }
- function buildResponse(sessionAttributes, speechletResponse) {
- return {
- version: "1.0",
- sessionAttributes: sessionAttributes,
- response: speechletResponse
- };
- }
- function capitalizeFirst (s) {
- return s.charST(0).toUpperCase() + s.slice(1)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement