【发布时间】:2017-08-16 23:28:12
【问题描述】:
我的意图架构中有 3 个插槽(account、dollar_value、recipient_first)用于 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 函数对提供两个插槽(dollar_value 和 recipient_first)的语音输入的 JSON 响应如下(我的猜测是第二个 if 语句中的 the create_dollar_value_attribute 方法覆盖了第一个):
{
"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 添加值?
【问题讨论】:
标签: python json aws-lambda alexa alexa-skill