jovotech / jovo-framework

🔈 The React for Voice and Chat: Build Apps for Alexa, Messenger, Instagram, the Web, and more
https://www.jovo.tech
Apache License 2.0
1.68k stars 310 forks source link

Cleaner way to have display template responses without ending session? #316

Closed IGx89 closed 5 years ago

IGx89 commented 5 years ago

Various types of Alexa responses (game engine, gadget controller, display templates) should not end the session, however Jovo by default adds shouldEndSession: true to the response so it becomes tricky to clear that.

That was sort of solved by https://github.com/jovotech/jovo-framework/pull/242 for game engine and gadget controller a while back, however there's no solution specifically for display template responses. I'm having to do the following in Jovo v2:

// ListTemplate1
this.$alexaSkill.showDisplayTemplate(template);
this.$alexaSkill.$gameEngine.respond(this.t('SOMETHING'));

and

// BodyTemplate3
this.$alexaSkill.showDisplayTemplate(template);
this.$alexaSkill.$gameEngine.respond('');

I'm not using game engine at all, but that's the only way I have to delete shouldEndSession from the response. It feels like there should be a better way to do so. What, I don't know. Feels almost that shouldEndSession should not be added by default to responses, but that's a pretty big change and I don't know what the repercussions of that would be.

For background, leaving shouldEndSession off display template responses causes the display template to show longer before disappearing (setting to true would cause it to disappear within seconds) and also is required in order for ElementSelected events to be triggered when the user taps a list item. Setting to false is not an option either due to it activating the microphone, if I remember right.

jankoenig commented 5 years ago

Hi @IGx89, thank you. Yes, this makes a lot of sense. Will discuss options with @aswetlow and the team

IGx89 commented 5 years ago

FYI, here's an example of this scenario in an official Alexa sample app: https://github.com/alexa/skill-sample-nodejs-berry-bash/blob/master/lambda/custom/index.js#L189. Note that it checks for a display interface, and if so it clears shouldEndSession, stores session attributes, and responds with some speech.

jankoenig commented 5 years ago

Thank you!

IGx89 commented 5 years ago

More docs on this behavior: https://developer.amazon.com/docs/custom-skills/display-interface-reference.html#use-of-shouldendsession-atribute-and-session-timeouts

aswetlow commented 5 years ago

Added this.$alexaSkill.deleteShouldEndSession() and this.$alexaSkill.shouldEndSession(boolean | undefined)