Node.js 带问题的分歧

Node.js 带问题的分歧,node.js,amazon-web-services,aws-lambda,amazon-lex,Node.js,Amazon Web Services,Aws Lambda,Amazon Lex,如何在amazon lex中使用lambda验证来实现此流程?我已经试过了,但是问题是循环的,没有进展,谢谢 这是我目前拥有的代码,从slot1到slot2,如果发生这种情况,但是当我尝试从slot2到slot3时,slot2循环并且不会前进,谢谢 exports.handler = (event, context, callback) => { const sessionAttributes = event.sessionAttributes; const slots

如何在amazon lex中使用lambda验证来实现此流程?我已经试过了,但是问题是循环的,没有进展,谢谢

这是我目前拥有的代码,从slot1到slot2,如果发生这种情况,但是当我尝试从slot2到slot3时,slot2循环并且不会前进,谢谢

exports.handler = (event, context, callback) => { const sessionAttributes = event.sessionAttributes; const slots = event.currentIntent.slots; const slot1 = slots.Slot1; const slot2 = slots.Slot2; const slot3 = slots.Slot3; const optSlot1 = ['1','2']; const optSlot2 = ['1','2']; const optSlot3 = ['1','2']; if(slot1 === optSlot1[0]) { let response = { dialogAction: { type: "ElicitSlot", intentName: event.currentIntent.name, slots: slots, slotToElicit : "slot2", } } callback(null, response); } if(slot2 === optSlot2[0] || slot2 === optSlot2[1]) { let response = { dialogAction: { type: "ElicitSlot", intentName: event.currentIntent.name, slots: slots, slotToElicit : "slot3", } } callback(null, response); } }; exports.handler=(事件、上下文、回调)=>{ const sessionAttributes=event.sessionAttributes; const slots=event.currentIntent.slots; const slot1=slots.slot1; const slot2=slots.slot2; const slot3=slots.slot3; 常量optSlot1=['1','2']; 常量optSlot2=['1','2']; 常量optSlot3=['1','2']; if(slot1==optSlot1[0]){ let response={ 对话行动:{ 键入:“插槽”, intentName:event.currentIntent.name, 插槽:插槽, Slotto引出:“slot2”, } } 回调(空,响应); } if(slot2==optSlot2[0]| | slot2===optSlot2[1]){ let response={ 对话行动:{ 键入:“插槽”, intentName:event.currentIntent.name, 插槽:插槽, Slotto:“slot3”, } } 回调(空,响应); } };
由于slot1的第一个IF语句继续解析为true,因此slot2会不断被激发,因此它会再次将激发slot2返回给Lex,而代码的其余部分永远不会被激发

你应该考虑是否检查一个时隙是空的,然后检查这个值是什么。例如,我选择这样编写我的机器人的Lambda代码:

                             --((pseudo code))--
if slot1 is empty then 
    elicit slot1
else                                           --slot1 is filled
    if slot1 is Yes then 
        if slot2 is empty then 
            elicit slot2
        else                                   --slot2 is filled
            if slot3 is empty
                elicit slot3
            else                               --slot3 is filled
               ...and so on
        end
    else                                       --slot1 is No
        elicit slotDates
end
const slot1 = event.slots.slot1
if (slot1 == "Yes") { ...
你可以根据你的谈话流程来简化它,但这是最基本的想法。对话越深入,您也会越深入地了解嵌套的if语句。当你阅读代码时,你可以沿着它的分支往下看


附带提示(请忽略此建议):

这将很难理解,因为您的机器人变得更加复杂,因为您必须不断地从对话逻辑中向后滚动,以查看该插槽的选项。您可以让自己更轻松,让用户更自然,并更多地使用Lex内置的插槽值识别

例如,当您有一个布尔问题Yes/No时,您可以在Lex中创建一个自定义SlotType,提供两个值“Yes”和“No”,然后为每个值提供许多同义词,例如“yea,yea,yep,right,当然可以”。这样,机器人可以问一个自然的开放式问题,用户可以自然地回答

你应该避免像老式的自动电话接线员那样使用Lex,告诉用户如何回答这样的问题:“如果是,请键入1。如果不是,请键入2”。Lex的功能远比这强大

因此,如果您使用Lex来确定用户说了什么,并将其等同于“是”或“否”,并用其中一个值填充插槽,那么您的代码将如下所示:

                             --((pseudo code))--
if slot1 is empty then 
    elicit slot1
else                                           --slot1 is filled
    if slot1 is Yes then 
        if slot2 is empty then 
            elicit slot2
        else                                   --slot2 is filled
            if slot3 is empty
                elicit slot3
            else                               --slot3 is filled
               ...and so on
        end
    else                                       --slot1 is No
        elicit slotDates
end
const slot1 = event.slots.slot1
if (slot1 == "Yes") { ...

更容易阅读。

欢迎使用StackOverflow。为了提供帮助,您必须提供更多信息。(1) 您当前在Lambda中使用的代码是什么?(2) 你能举一个对话的例子来解释你所说的“问题是循环的,不前进”是什么意思吗?我已经纠正了这个问题,谢谢你的建议!