我正在使用Amazon 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对象。 谁能告诉我怎样才能实现这个目标?
答案 0 :(得分:0)
对于AMAZON.TIME内置插槽:
当用户输入不明确的时间时,Amazon Lex使用Lambda事件的slotDetails属性将模糊时间的分辨率传递给Lambda函数。 ...在这种情况下,slot map中的值为null,slotDetails实体包含两种可能的时间分辨率。
您输入&#34; 14:00:00&#34;不被理解为一个明确的时间,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;