issue with non-existing session attributes
Opened this issue · 1 comments
Marakai commented
Following the tutorial on YouTube and using the template code here will fail in Sessions, because event['session]['attributes']
doesn't exist at time of calling the intent handler. In addition, the on_launch()
returns a statement()
with 'shouldEndSession
' set to True.
One solution is:
- Return
conversation()
inon_launch()
with a{}
passed as third parameter - Add a simple check for the 'attributes' dictionary to exist in the
intent_router()
and create it if it doesn't yet.
pcakhilnadh commented
def counter_intent(event,content):
"""
in order to maintain the session , return the session object in every response
"""
if 'attributes' in event['session']:
session_attributes=event['session']['attributes']
if 'counter' in session_attributes:
session_attributes['counter']+=1
else:
session_attributes['counter']=1
else:
event['session']['attributes']={}
session_attributes=event['session']['attributes']
if 'counter' not in session_attributes:
session_attributes['counter']=1
return conversation("SessionIntent",session_attributes['counter'],session_attributes)
#4 closed