alexa / alexa-skills-kit-sdk-for-nodejs

The Alexa Skills Kit SDK for Node.js helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Apache License 2.0
3.12k stars 736 forks source link

Alexa skill session does not end with this.emit(':tell', response) #268

Closed Kevintjeb closed 6 years ago

Kevintjeb commented 6 years ago

Hi,

I am using the SDK to define my Alexa Skill.

const handlers = {
 'LaunchRequest': function () {
  this.response.speak(welcomeOutput).listen(welcomeReprompt);
  this.emit(':responseReady');
 },
 'myIntent': function () {
  console.log(this.event.request.dialogState + " <- dialogstate")
  if (this.event.request.dialogState !== "COMPLETED") {
   this.emit(":delegate");
  }
  else {
   let intent = this.event.request.intent;
   if (intent.confirmationStatus === "DENIED") {
    let speechOutput = `Ok, not doing what was requested`;

    this.emit(":tell", speechOutput);
   }
   else if (intent.confirmationStatus === "CONFIRMED") {
    let speechOutput = "Ok doing what was requested ";

    this.emit(":tell", speechOutput);
   }
  }
 }
};

exports.handler = (event, context) => {
 let alexa = Alexa.handler(event, context);
 alexa.appId = APP_ID;
 alexa.registerHandlers(handlers);
 alexa.execute();
};

(Removed specific details)

Using this code my echo Show stays in the session until it times out (8 seconds) then it returns to the homescreen. However, the documentation (And code, I looked at the implementation) specify that using this.emit(":tell") should set the 'shouldEndSession' flag to true, which in turn ends the session.

Unfortunately this is not happening.

talkingnews commented 6 years ago

Hmmm, I'm not so sure... from: https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs

this.emit(':tell',speechOutput); | Tell with speechOutput this.emit(':responseReady'); | Called after the response is built but before it is returned to the Alexa service. Calls : saveState. Can be overridden.

Also, are you using the version of the SDK that comes with Lamdba, or are you doing npm install and then uploading? Because, the version in Lambda is VERY old and very different to the current code, and probably won't behave as you hope/expect.

But either way, try the responseReady method instead and see if that works..

Kevintjeb commented 6 years ago

Thanks for responding,


const Alexa = require('alexa-sdk');

const handlers = {
    'LaunchRequest': function() {
        this.response.speak(welcomeOutput).listen(welcomeReprompt);
        this.emit(':responseReady');
    },
    'OrderIntent': function() {
        if (this.event.request.dialogState !== "COMPLETED") {
            this.emit(":delegate");
        } else {
            let intent = this.event.request.intent;
            if (intent.confirmationStatus === "DENIED") {
                let speechOutput = `response`;
                this.response.speak(speechOutput);
                this.emit(":responseReady");
            } else if (intent.confirmationStatus === "CONFIRMED") {

                let speechOutput = "response";
                this.response.speak(speechOutput);
                this.emit(":responseReady");
            }
        }
    }
};

exports.handler = (event, context) => {
    let alexa = Alexa.handler(event, context);
    alexa.appId = APP_ID;
    alexa.registerHandlers(handlers);
    alexa.execute();
};

This code still does the same, after ''response" it waits till it times out to stop the session.

I was using the standard lambda alexa-sdk, now I downloaded the latest version using NPM and uploaded that.

TianTXie commented 6 years ago

@Kevintjeb , The shouldEndSession property in echo show and echo dot has different behavior, Because in echo show, the display times out might be happened before the session times out. Check this issue for more information.

Kevintjeb commented 6 years ago

Okay, from the other Issue I can't find out how to properly exit the skill upon completion. Therefore my question remains, how can I stop the skill/session programmatically/ in Lambda?

TianTXie commented 6 years ago

I think the only way is to use user utterance like 'Alexa, stop', 'Alexa exit' to trigger the shouldEndSession to be true. Otherwise, the session will remains open until the display times out.