我在我的意图模式中有3个插槽(account
,dollar_value
,,0 )用于Alexa技能,我想保存讲话者在会话属性中提供的任何插槽。在Python中为Alexa技能添加会话属性
我使用下面的方法来设置会话属性:
def create_dollar_value_attribute(dollar_value):
return {"dollar_value": dollar_value}
def create_account_attribute(account):
return {"account": account}
def create_recipient_first_attribute(recipient_first):
return {"recipient_first": recipient_first}
但是,如你所猜测的,如果我想保存多个插槽数据sessionAttributes
,该sessionAttributes
被覆盖作为下面的情况:
session_attributes = {}
if session.get('attributes', {}) and "recipient_first" not in session.get('attributes', {}):
recipient_first = intent['slots']['recipient_first']['value']
session_attributes = create_recipient_first_attribute(recipient_first)
if session.get('attributes', {}) and "dollar_value" not in session.get('attributes', {}):
dollar_value = intent['slots']['dollar_value']['value']
session_attributes = create_dollar_value_attribute(dollar_value)
从我lambda函数的JSON响应对于其中两个时隙(dollar_value
和recipient_first
)中提供的是如下语音输入(我的猜测是,the create_dollar_value_attribute
方法在第二if语句覆盖第一):
{
"version": "1.0",
"response": {
"outputSpeech": {
"type": "PlainText",
"text": "Some text output"
},
"card": {
"content": "SessionSpeechlet - Some text output",
"title": "SessionSpeechlet - Send Money",
"type": "Simple"
},
"reprompt": {
"outputSpeech": {
"type": "PlainText"
}
},
"shouldEndSession": false
},
"sessionAttributes": {
"dollar_value": "30"
}
}
为sessionAttributes
正确的反应应该是:
"sessionAttributes": {
"dollar_value": "30",
"recipient_first": "Some Name"
},
如何创建对此有何反应?有没有更好的方法在JSON响应中为sessionAttributes
添加值?
我没有在'事件属性[“会议”]'但是我不知道如何实例化这个'事件[“会议”] [”属性'] = {}'会解决它? alexa/lambda如何知道? 'onSessionStarted'函数做了什么? – Jonathan