没有值传递给插槽但原始值在机器人中传递

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了没有值传递给插槽但原始值在机器人中传递相关的知识,希望对你有一定的参考价值。

我使用AWS lex和AWS lambda作为验证Codehook。当我尝试使用动态生成的响应卡传递值时,它在AppointmentTime Slot中显示空值,但原始值在slotDetails中显示值。这是通过lex发送的请求:

{
"messageVersion": "1.0",
"invocationSource": "DialogCodeHook",
"userId": "prwna44b91sbr4w7d2pwwva59anaqzqx",
"sessionAttributes": {
    "store_id": "26",
    "address": "Quark Atrium, A‐45, Phase VIII Extension,Industrial Focal Point,Sahibzada Ajit Singh Nagar, Punjab 160071,India",
    "closingTime": "19:00:00",
    "city": "Mohali",
    "phone": "9718409751",
    "bookingDateTime": "2018-05-27T21:25:46+05:30",
    "openingTime": "10:00:00",
    "state": "PB",
    "email": "bhuvnesh.kumar@sourcefuse.com",
    "zip_code": "44545"
},
"requestAttributes": null,
"bot": {
    "name": "ScheduleRide",
    "alias": "$LATEST",
    "version": "$LATEST"
},
"outputDialogMode": "Text",
"currentIntent": {
    "name": "BookAppointment",
    "slots": {
        "CustomerAgreement": null,
        "DropLocationPrompt": "yes",
        "PickupAddress": "Unnamed Road, Industrial Area, Sector 74, Sahibzada Ajit Singh Nagar, Punjab 140308, India",
        "RequiredService": null,
        "AppointmentTime": null,
        "DropAddress": null,
        "PhoneNumber": null,
        "AppointmentDate": "2018-05-28"
    },
    "slotDetails": {
        "CustomerAgreement": {
            "resolutions": [],
            "originalValue": null
        },
        "DropLocationPrompt": {
            "resolutions": [
                {
                    "value": "yes"
                }
            ],
            "originalValue": "yes"
        },
        "PickupAddress": {
            "resolutions": [],
            "originalValue": "Unnamed Road, Industrial Area, Sector 74, Sahibzada Ajit Singh Nagar, Punjab 140308, India"
        },
        "RequiredService": {
            "resolutions": [],
            "originalValue": null
        },
        "AppointmentTime": {
            "resolutions": [
                {
                    "value": "00:00"
                },
                {
                    "value": "12:00"
                }
            ],
            "originalValue": "14:00:00"
        },
        "DropAddress": {
            "resolutions": [],
            "originalValue": null
        },
        "PhoneNumber": {
            "resolutions": [],
            "originalValue": null
        },
        "AppointmentDate": {
            "resolutions": [],
            "originalValue": "28 may"
        }
    },
    "confirmationStatus": "None"
},
"inputTranscript": "14:00:00"

这是传递给lex的请求,请参阅slots对象中的AppointmentTime,它显示null,并且在slotDetails对象中,它显示值。这是我从响应卡对象传递的按钮数组:

 [ { text: '1:00 PM', value: '13:00:00' },
   { text: '1:30 PM', value: '13:30:00' },
   { text: '2:00 PM', value: '14:00:00' },
   { text: '2:30 PM', value: '14:30:00' },
   { text: '3:00 PM', value: '15:00:00' },
   { text: '3:30 PM', value: '15:30:00' },
   { text: '4:00 PM', value: '16:00:00' },
   { text: '4:30 PM', value: '16:30:00' },
   { text: '5:00 PM', value: '17:00:00' },
   { text: '5:30 PM', value: '17:30:00' },
   { text: '6:00 PM', value: '18:00:00' },
   { text: '6:30 PM', value: '18:30:00' } ]

以下是buildResponseCard的功能:

  function buildResponseCard(title, subTitle, options){
let buttons = null;
console.log(options);
let genericAttachments = [];
if (options != null){
    buttons = [];
    for(let i = 0; i < (options.length); i++){
        buttons.push(options[i]);
        if(i%3 === 2){
            genericAttachments.push({
             title,
             subTitle,
             buttons
            });
            buttons = [];
        }
    }
}
return {
    version: 1,
    contentType: "application/vnd.amazonaws.card.generic",
    genericAttachments
};
}

我希望显示插槽对象上的AppointmentTime槽值的原因是,只要槽中的值通过验证无效,我将其设置为null并将通过lambda函数回调它,我将无法回调slotDetails响应中的对象。谁能告诉我怎样才能实现这一目标?

答案

对于AMAZON.TIME内置插槽:

当用户输入不明确的时间时,Amazon Lex使用Lambda事件的slotDetails属性将模糊时间的分辨率传递给Lambda函数。 ...在这种情况下,slot map中的值为null,slotDetails实体包含两种可能的时间分辨率。

您输入的“14:00:00”并不是一个明确的时间,Lex会尝试将其解决到中午或午夜,这显然是错误的。这可能是因为Lex Time插槽只需要几小时和几分钟(hh:mm)而不是秒(hh:mm:ss)。

因此,如果您可以,一种解决方案是从您的时间值中删除秒数字。例如:

[ { text: '1:00 PM', value: '13:00' }, ... ]

但是,如果您必须在时间值中有秒,那么您只需找到用户从inputTranscript值中选择的时间,然后从那里进行验证。

var userInput = event.inputTranscript;

编辑:

另一种选择是忽略Lex建议的分辨率并获得插槽细节的原始值。像这样:

var timeValue = event.currentIntent.slotDetails.AppointmentTime.originalValue;

然后自己设置AppointmentTime插槽。像这样:

event.currentIntent.slots.AppointmentTime = timeValue;

以上是关于没有值传递给插槽但原始值在机器人中传递的主要内容,如果未能解决你的问题,请参考以下文章

成员结构的值在作为指针传递给函数后丢失

深浅拷贝

使用 QNetWorkAccessManager 将值传递给插槽

我为一个类声明了一个变量,并将其传递给一个方法来实例化它,但原始变量仍未实例化

传递双精度值返回未知值C.

片段和活动之间没有传递值