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

How to stop user session with Alexa-sdk? #32

Closed faiza-nawaz-confiz closed 7 years ago

faiza-nawaz-confiz commented 7 years ago

Hi, i'm using alexa-sdk. My skill is very simple, but i'm not sure how to stop user session so that he can't use my skill without restarting it. I use "shouldEndSession" for this purpose, when not using SDK. but i'm unable to find this in functionality provided by SDK (I'm sure it's been provided. Please guide).

deegles commented 7 years ago

Hi,

If you use this.emit(':tell', ...) the current session will end.

faiza-nawaz-confiz commented 7 years ago

@deegles, means, if i use this.emit(':tell',...), the session will end. and if i use this.emit(':responsebody'), it will not? Please guide in a little more detail.. Will be really helpful. thanks

gabrielkaputa commented 7 years ago

Hi, here you can see what ends the session and what does not: https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/blob/master/lib/response.js. this should answer your question

ghost commented 7 years ago

Closing as @gabrielkaputa answered with reference doc.

Feel free to re-open if you have any further questions

pranavshenoy commented 6 years ago

Hi I am using this.emit(':tell', 'hello alexa'), but this is not ending the session, it executes the following statements too. due to this i am getting timeout error in lambda function

DKorosec commented 6 years ago

Same here, the :tell emit is not ending the session and alexa is waiting for the async get request to complete (executed after the :tell) which creates an annoying 3-4 seconds delay in response. Is there any workaround?

pranavshenoy commented 6 years ago

@DKorosec I found the issue in the exports.handler, write this statement context.callbackWaitsForEmptyEventLoop = false;

by default this is true, which means (according to amazon doc), callback will wait until event loop is empty. if it is set to false, then it will exit once the callback is called, irrespective of whether event loop is empty or not.

what I am not understanding is why will event loop be non- empty in this case? what will be there in the event loop. Thanks in advance for explanation.

DKorosec commented 6 years ago

@pranavshenoy thanks, it resolved the issue I was having 👍. If your following statements are synchronous, they will be executed because they are inside the same event. If you make then asynchronous (for example wrap them around setTimeout) they will be put inside an event loop and won't be executed in the current event which executes the :tell command.