alexa-app
alexa-app copied to clipboard
Session Attributes key values are not displaying in next requests
Hi,
I am setting session attributes in one intent request. < var session = req.getSession(); session.set("Name:"," rajeev"); res.shouldEndSession(false); > So this session attributes i should get on every next requests rite ? Currently i am not getting any session attributes. Am i missing anything here?
Hi!
Do you have a more complete example you can post? That looks generally right, but it's hard to see where else things might be going wrong without a more full-featured example of a functioning application.
This code to set the attributes
app.intent('SongIntent', {
"slots": { "SongName": "AMAZON.MusicRecording"},
"utterances": ["{play} {shape of you|SongName} {song}"]
}, function(req, res) {
var session = req.getSession();
if(!accessToken.is_accessToken_Present(session)){
res.say("Please link your account in alexa app.");
res.linkAccount();
}else{
return getmusic(req.slot('SongName'),"track",accessToken.getAccessToken(session)).
then(obj=> {
if(obj.url!=undefined){
//console.log("got response song url :"+obj.url);
res.say("playing the song " +req.slot('SongName')+" from app");
var stream = {
"url": obj.url,
"token": obj.token,
"offsetInMilliseconds": 0
};
res.audioPlayerPlayStream("REPLACE_ALL", stream);
} else{
res.say(obj.sys_message);
}
session.set("Name"," rajeev");
res.shouldEndSession(false);
return res.send();
}).catch(function(error) {
res.say("Sorry i couldn't find the song you were looking in to.");
return res.send();
});
}
});
This code when user says pause for the song i sent to him. I am checking the attributes
app.intent("AMAZON.PauseIntent", {
"slots": {},
"utterances": []
}, function(request, response) {
if(request.hasSession()){
var session = request.getSession();
var name= session.get("Name");
console.log("\nsession name:\n"+name);
}
console.log("\n Amazon pause intent: \n"+JSON.stringify(request));
response.audioPlayerStop();
});
And i am not getting the session attributes in any intent like playbackstarted, playbackstopped resume intent.
Hi @rajeevs960 Did you get a solution ?, I am facing the same issue.
Hi @supriya2502
No i did not get the solution for this. I am using my own mongo database as my requirement got little changed. So did not try for the solution.
I think its a bug in the library. Since im not sure I'm also gonna post some code snippets of my code and the log just in case. Here the code im using:
Set
}).then(function (currentPodcast) {
if (currentPodcast.ID != null) {
if (currentPodcast.podcast_url) {
var stream = {
url: currentPodcast.podcast_url,
token: currentPodcast.podcast_url,
offsetInMilliseconds: 0
};
console.log(currentPodcast);
console.log(currentPodcast.number);
request.getSession().set("lastPlayedPodcast", currentPodcast.number);
response.audioPlayerPlayStream('REPLACE_ALL', stream);
console.log('Play Audio');
Get
}).then(function (currentPodcasts) {
let session = request.getSession();
let rawNumber = session.get("lastPlayedPodcast");
console.log('Session: \n');
console.log(session);
console.log('lastPlayedPodcast: ');
console.log(rawNumber);
let nextPodcastNumber = parseInt(session.get("lastPlayedPodcast"), 10) + 1;
console.log('nextPodcastNumber (parsed rawnumber): ' + nextPodcastNumber);
console.log(session.details);
And also here my log alexa.log
This is a bug with Amazon's infrastructure, not alexa-app. When using audio player or gadgets API's, session does not work consistently. This is true even if you use raw json and not alexa-app at all.