In der Frageschleife bleiben

Hier wird über die Entwicklung von Skills diskutiert.
Antworten
Benutzeravatar

Themenstarter
Luigihausen
Beiträge: 4
Registriert: So 28. Mai 2017, 18:28

So 28. Mai 2017, 18:37

Hallo zusammen
Heute habe ich mich an meinem ersten custom Skill mit Lambda versucht und auch erste Fortschritte gemacht.
Es geht im ersten Test nur darum, nach Informationen zu Familienmitgliedern zu fragen und einen vordefinierten Text zu jedem Auszugeben.
Der Willkommenstext wird abgespielt, die gewünscht Frage nach dem Informationen zu XYZ kann ich stellen, der Intent wird übergeben und mit if / else-if / else ausgewertet und auch von Alexa ausgegeben.
Jetzt möchte ich nur nicht für jede neue Frage den Öffne "Invocation Name" Befehlt wieder sagen und auch nicht den Willkommenstext hören.

Wie kann ich verhindern, dass am Ende der Ausgabe das "Programm" verlassen wird?
0 x
Benutzeravatar

amartin
Beiträge: 117
Registriert: Sa 4. Feb 2017, 19:12
Vorhandene Echos: 1
Vorhandene Echo Dots: 1

So 28. Mai 2017, 18:41

was verwendest du denn um deinen Skill zu programmieren?
0 x
Benutzeravatar

Themenstarter
Luigihausen
Beiträge: 4
Registriert: So 28. Mai 2017, 18:28

So 28. Mai 2017, 18:55

Ich verwende Node.js 6.10
0 x
Benutzeravatar

amartin
Beiträge: 117
Registriert: Sa 4. Feb 2017, 19:12
Vorhandene Echos: 1
Vorhandene Echo Dots: 1

So 28. Mai 2017, 19:00

verwendest du "alexa-skills-kit-sdk-for-nodejs" oder "alexa-app" ? wenn du das offizielle alexa sdk verwendest kannst du einfach dein:

Code: Alles auswählen

this.emit(':tell', 'ladida')
ersetzen durch

Code: Alles auswählen

 this.emit(':ask', 'ladida', 'noch da?')
0 x
Benutzeravatar

Themenstarter
Luigihausen
Beiträge: 4
Registriert: So 28. Mai 2017, 18:28

So 28. Mai 2017, 19:15

Leider kann ich Dir Deine Frage nicht einmal beantworten.
Ich habe über https://developer.amazon.com ein Custom Skill erstellt und über AWS Lambda mit Node.js 6.10 den folgenden Code entsprechend angepasst.
Wie gesagt, ich stehe noch ganz am Anfang ;-)

Code: Alles auswählen

'use strict';

// --------------- Helpers that build all of the responses -----------------------

function buildSpeechletResponse(title, output, repromptText, shouldEndSession) {
    return {
        outputSpeech: {
            type: 'PlainText',
            text: output,
        },
        card: {
            type: 'Simple',
            title: `SessionSpeechlet - ${title}`,
            content: `SessionSpeechlet - ${output}`,
        },
        reprompt: {
            outputSpeech: {
                type: 'PlainText',
                text: repromptText,
            },
        },
        shouldEndSession,
    };
}

function buildResponse(sessionAttributes, speechletResponse) {
    return {
        version: '1.0',
        sessionAttributes,
        response: speechletResponse,
    };
}


// --------------- Functions that control the skill's behavior -----------------------

function getWelcomeResponse(callback) {
    // If we wanted to initialize the session to have some attributes we could add those here.
    const sessionAttributes = {};
    const cardTitle = 'Unser Skill';
    const speechOutput = 'Willkommen. Über wen von der Familie möchtest Du etwas erfahren. Sage einfach: Was kannst Du mir über XY sagen.';
    const repromptText = 'Bitte nochmal';
    const shouldEndSession = false;

    callback(sessionAttributes,
        buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
}

function handleSessionEndRequest(callback) {
    const cardTitle = 'Session Ended';
    const speechOutput = 'Thank you for trying the Alexa Skills Kit sample. Have a nice day!';
    // Setting this to true ends the session and exits the skill.
    const shouldEndSession = true;

    callback({}, buildSpeechletResponse(cardTitle, speechOutput, null, shouldEndSession));
}

function getInformations(intent, session, callback) {
	const firstname = intent.slots.Firstname.value;
	// console.log("hallo hallo", Firstname);
	
    const repromptText = null;
    const sessionAttributes = {};
    let shouldEndSession = false;
    let speechOutput = '';

    if (firstname=="Max") {
		speechOutput = `${firstname} ist das jüngste Familienmitglied.`;
    } else if (firstname=="Stefanie") {
		speechOutput = `${firstname} ist die Chefin im Haus.`;
	} else if (firstname=="Luigi") {
		speechOutput = `${firstname} ist der Chef im Haus.`;
	} else if (firstname=="Boston") {
		speechOutput = `${firstname} ist der Hund der Familie.`;
	} else {
		speechOutput = `Leider konnte das Familienmitglied nicht gefunden werden.`;
	}
	
	//speechOutput = `${firstname} der Hund der Familie Rüübe. Er liebt Luftballons.`;
    shouldEndSession = true;
    
    // Setting repromptText to null signifies that we do not want to reprompt the user.
    // If the user does not respond or says something that is not understood, the session
    // will end.
    callback(sessionAttributes,
         buildSpeechletResponse(intent.name, speechOutput, repromptText, shouldEndSession));
}


// --------------- Events -----------------------

/**
 * Called when the session starts.
 */
function onSessionStarted(sessionStartedRequest, session) {
    console.log(`onSessionStarted requestId=${sessionStartedRequest.requestId}, sessionId=${session.sessionId}`);
}

/**
 * Called when the user launches the skill without specifying what they want.
 */
function onLaunch(launchRequest, session, callback) {
    console.log(`onLaunch requestId=${launchRequest.requestId}, sessionId=${session.sessionId}`);

    // Dispatch to your skill's launch.
    getWelcomeResponse(callback);
}

/**
 * Called when the user specifies an intent for this skill.
 */
function onIntent(intentRequest, session, callback) {
    console.log(`onIntent requestId=${intentRequest.requestId}, sessionId=${session.sessionId}`);

    const intent = intentRequest.intent;
    const intentName = intentRequest.intent.name;

    // Dispatch to your skill's intent handlers
	if (intentName === 'INFORMATION') {
        getInformations(intent, session, callback);
    } else if (intentName === 'AMAZON.HelpIntent') {
        getWelcomeResponse(callback);
    } else if (intentName === 'AMAZON.StopIntent' || intentName === 'AMAZON.CancelIntent') {
        handleSessionEndRequest(callback);
    } else {
        throw new Error('Invalid intent');
    }
}

/**
 * Called when the user ends the session.
 * Is not called when the skill returns shouldEndSession=true.
 */
function onSessionEnded(sessionEndedRequest, session) {
    console.log(`onSessionEnded requestId=${sessionEndedRequest.requestId}, sessionId=${session.sessionId}`);
    // Add cleanup logic here
}


// --------------- Main handler -----------------------

// Route the incoming request based on type (LaunchRequest, IntentRequest,
// etc.) The JSON body of the request is provided in the event parameter.
exports.handler = (event, context, callback) => {
    try {
        console.log(`event.session.application.applicationId=${event.session.application.applicationId}`);

        /**
         * Uncomment this if statement and populate with your skill's application ID to
         * prevent someone else from configuring a skill that sends requests to this function.
         */
        /*
        if (event.session.application.applicationId !== 'amzn1.echo-sdk-ams.app.[unique-value-here]') {
             callback('Invalid Application ID');
        }
        */

        if (event.session.new) {
            onSessionStarted({ requestId: event.request.requestId }, event.session);
        }

        if (event.request.type === 'LaunchRequest') {
            onLaunch(event.request,
                event.session,
                (sessionAttributes, speechletResponse) => {
                    callback(null, buildResponse(sessionAttributes, speechletResponse));
                });
        } else if (event.request.type === 'IntentRequest') {
            onIntent(event.request,
                event.session,
                (sessionAttributes, speechletResponse) => {
                    callback(null, buildResponse(sessionAttributes, speechletResponse));
                });
        } else if (event.request.type === 'SessionEndedRequest') {
            onSessionEnded(event.request, event.session);
            callback();
        }
    } catch (err) {
        callback(err);
    }
};
0 x
Benutzeravatar

amartin
Beiträge: 117
Registriert: Sa 4. Feb 2017, 19:12
Vorhandene Echos: 1
Vorhandene Echo Dots: 1

So 28. Mai 2017, 21:33

Diese Zeile in deinem Code

Code: Alles auswählen

	//speechOutput = `${firstname} der Hund der Familie Rüübe. Er liebt Luftballons.`;
    shouldEndSession = true;
shouldEndSession = true; sorgt dafür, dass Alexa nach der Ausgabe aufhört zu "lauschen".

Du solltest auch die Variable

Code: Alles auswählen

const repromptText = null;
mit etwas sinnvollem füllen.

Schau dir mal bei Gelegenheit das Alexa NodeJS SDK an:
https://github.com/alexa/alexa-skills-k ... for-nodejs
Zuletzt geändert von amartin am So 28. Mai 2017, 21:34, insgesamt 1-mal geändert.
0 x
Benutzeravatar

Themenstarter
Luigihausen
Beiträge: 4
Registriert: So 28. Mai 2017, 18:28

Mo 29. Mai 2017, 06:28

Vielen Dank für den Tipp.
Ich werde es ausprobieren und mich auch weiter einlesen.
0 x
Antworten

Zurück zu „Fähigkeiten (Skills) entwickeln“

  • Information