anjishnu / ask-alexa-pykit

A minimalist SDK for developing skills for the Amazon Echo's ASK - Alexa Skills Kit using Amazon Web Services's Python Lambda Functions. Currently supported profiles are for Linux servers and AWS Lambda. Check the appropriate release branch. The cherrypy release branches have added components for request validation.
MIT License
275 stars 58 forks source link

Cannot store new session attributes. #13

Closed AtheMathmo closed 8 years ago

AtheMathmo commented 8 years ago

The end of the alexa_io.route_request reads as follows:

response = handler_fn(request)
response['sessionAttributes'] = request.session
return response

The request variable is the incoming request from Alexa which will always have None attributes unless we explicitly store some. This means that the code above removes any attributes we assign before returning the response.

I think the correct behaviour would be to simply remove the line that reassigns the attributes? This would allow the user to specify any sessionAttributes in their responses. To allow for this we modified the create_response method as so:

@classmethod
def create_response(self, message=None, end_session=False, card_obj=None,
                    reprompt_message=None, is_ssml=None, session_attributes=None):
   # ... Removed some stuff
   if session_attributes:
      response['sessionAttributes'] = session_attributes
   return response

Of course - it is likely I'm misunderstanding the intended usage! I'm happy to file a PR if you do want the above changes.

anjishnu commented 8 years ago

I think the idea is for you to modify the request.session variables (deleting and adding to it) without needing to return the same variables over and over.

So you can do:


def some_handler(request):
  request.session['new_attr'] = 'foobar'
  return alexa.create_response('something')

And the new attribute will automatically get propagated down into the request. instead of


def some_handler(request):
  session = request.session
  session['new_attr'] = 'foobar'
  return alexa.create_response('something', session_attributes=session)

Do you think this way of doing things is too difficult to understand or removes some functionality? If so we could consider revert to the old style of doing things - but I am guessing most people who are working with session attributes might appreciate the abstraction.

AtheMathmo commented 8 years ago

Ah yeah - you're right. Sorry this was towards the end of a day at Angel Hack and I didn't see the functionality you've described above.

I think it is a little difficult to understand but perhaps some documentation is a better way to solve that. I think the functionality itself is better as is.

P.S. We won the Amazon Alexa prize with the help of your library, thanks!

anjishnu commented 8 years ago

Yup, more documentation definitely seems necessary! I'll add it to the lambda_handler.py module, and keep this issue open until then.

Great to hear that you guys won! What did you build? Is it possible to get a link to a demo or something? Hopefully this repo allowed you to focus on your functionality instead of basic plumbing for Alexa!

AtheMathmo commented 8 years ago

We do have a demo video! I sent it to your email.

This library definitely helped us focus on functionality. It took a little while to understand how everything fits together (though you were a big help with that). Thanks again for your hard work with this :)