我的 lambda 函数有一个意图。我正在尝试填补 4 个插槽,其中 3 个是必需的。在我的测试中,似乎我必须将 Assignee 字段设置为默认值,否则在我的实际处理程序中发生故障,这发生在下面的 else 语句之后。这是我当前定义默认值的方式:
如果 strings.ToUpper(request.DialogState) == "STARTED" {
log.Println("DialogState == STARTED")
// Pre-fill slots: update the intent object with slot values for which
// you have defaults, then return Dialog.Delegate with this updated intent
// in the updatedIntent property.
slots := make(map[string]alexa.IntentSlot)
slots["Summary"] = alexa.IntentSlot{
Name: "Summary",
Value: "",
ConfirmationStatus: "NONE",
}
slots["TicketType"] = alexa.IntentSlot{
Name: "TicketType",
Value: "",
ConfirmationStatus: "NONE",
}
slots["Project"] = alexa.IntentSlot{
Name: "Project",
Value: "",
ConfirmationStatus: "NONE",
}
slots["Assignee"] = alexa.IntentSlot{
Name: "Assignee",
Value: "tcheek",
ConfirmationStatus: "NONE",
}
i := &alexa.Intent{
Name: "OpenTicketIntent",
ConfirmationStatus: "NONE",
Slots: slots,
}
response.AddDialogDirective("Dialog.Delegate", "", "", i)
response.ShouldSessionEnd = false
log.Println("DialogState has exited STARTED")
} else if strings.ToUpper(request.DialogState) != "COMPLETED" {
log.Println("DialogState == IN PROGRESS")
// return a Dialog.Delegate directive with no updatedIntent property.
response.ShouldSessionEnd = false
response.AddDialogDirective("Dialog.Delegate", "", "", nil)
log.Println("DialogState has exited IN PROGRESS")
} else {
我还尝试将 Assignee 字段设置为默认值,如下所示:
slots := make(map[string]alexa.IntentSlot)
slots["Assignee"] = alexa.IntentSlot{
Name: "Assignee",
Value: "tcheek",
ConfirmationStatus: "NONE",
}
i := &alexa.Intent{
Name: "OpenTicketIntent",
ConfirmationStatus: "NONE",
Slots: slots,
}
response.AddDialogDirective("Dialog.Delegate", "", "", i)
在这种情况下,我在模拟器中得到以下 lambda 函数响应:
{
"body": {
"version": "1.0",
"response": {
"directives": [
{
"type": "Dialog.Delegate",
"updatedIntent": {
"name": "OpenTicketIntent",
"confirmationStatus": "NONE",
"slots": {
"Assignee": {
"name": "Assignee",
"value": "tcheek",
"confirmationStatus": "NONE"
}
}
}
}
],
"shouldEndSession": false
}
}
}
问题是,一旦我要求它打开一个错误票(它映射到带有“打开 {ticketType} 票”话语的意图),它会给出“请求的技能响应有问题”的响应。
我认为设置默认值是必要的,我错了吗?我是否错误地设置了默认值?