How to maintain value for use throughout the project in alexa

I am developing an Alexa music app and it works like this. I ask Alex to play music so that the artist says that this is the lady of the gaga. I get the name and pass it to my api and get 10 songs in response. Now I go through the first song to InetentRequest and play the song.

Now I'm looking for an AudioPlayer.PlaybackNearlyFinished alexa request form to insert a second song. But the problem is that I can’t name the artist here to play the song. Anyway, to save the name of the artist somewhere and use it in the project, wherever I want?

+5
source share
2 answers

I think the best way to store session data like this is in response session attributes.

When you create a response object, you put all the data you need into the 'sessionAttributes' object. If you use the SDK, it will probably have a function for this.

When you receive the next intention in the same Alexa session, it will have your data in the "session.attributes" event.

docs refer to your data as a "Key-value pairs map", but I find that you can put whatever you want there, as long as the top level is an object, not an array.

+1
source

If you do not save the artist in the session and do not save it on the next song, I think you may need to find a way to use the MusicRecording intention in your skills.

https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/built-in-intent-ref/musicrecording-intents

0
source

Source: https://habr.com/ru/post/1262972/


All Articles