微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

确认提示后意图未实现

如何解决确认提示后意图未实现

我正在研究词法处理,并且想在所有插槽值都填满后实现意图。但是在确认提示后,意图并未实现。它一遍又一遍地询问确认提示,但没有实现意图。我的代码在python中,所以请检查我的代码中是否有错误。谢谢。

查看屏幕截图。

enter image description here

enter image description here

我还附有验证码。

import json
def flightDecision(currName,currSlots,Departure_city,Arrival_city,ReturnDate,Departing,Date,Flight_schedule):
    if Departing == "roundtrip" and Date == None:
        return{
            "dialogAction": {
                "type": "ElicitSlot","slottoElicit": "Date","intentName": 'Bookaflight',"slots": {
                  "Departure_city": Departure_city,"Arrival_city": Arrival_city,"Departing": Departing,"Date": Date,},}
    if Departing == 'roundtrip' and Date != None and ReturnDate == None:
        return{
            "dialogAction": {
                "type": "ElicitSlot","slottoElicit": "ReturnDate","ReturnDate": ReturnDate,}
    if Departing == 'roundtrip' and ReturnDate != None and Flight_schedule == None:
         return{
            "dialogAction": {
                "type": "ElicitSlot","slottoElicit": "Flight_schedule","Flight_schedule": Flight_schedule
                },}
    if Departing == "oneway" and Date == None:
        return{
            "dialogAction": {
                "type": "ElicitSlot",}
    if Departing == 'oneway' and Date != None and Flight_schedule == None:
        return{
            "dialogAction": {
                "type": "ElicitSlot","Flight_schedule": Flight_schedule,}
        
    return{
        "dialogAction":{
            "type": "ConfirmIntent","intentName": "Bookaflight","slots":{
                "Departure_city": Departure_city,#  "message":{
                #      "contentType": "PlainText",#      "message": "you want to book a ticket"
                #  }
            }
        }
    }
    
def delegate(currSlots,currName,Flight_schedule):
    return{
        'dialogAction': {
            'type': 'Delegate','slots': currSlots
        }
    }
    
def lambda_handler(event,context):
    currName = event['currentIntent']['name']
    currSlots = event['currentIntent']['slots']
    Departing = event['currentIntent']['slots']['Departing']
    ReturnDate = event['currentIntent']['slots']['ReturnDate']
    Arrival_city = event['currentIntent']['slots']['Arrival_city']
    Departure_city = event['currentIntent']['slots']['Departure_city']
    Date = event['currentIntent']['slots']['Date']
    Flight_schedule = event['currentIntent']['slots']['Flight_schedule']
    
    while not Departing:
        return delegate(currSlots,Flight_schedule)
    else:
        return flightDecision(currSlots,Flight_schedule)

解决方法

如果您使用相同的Lambda函数进行验证和实现,则需要检查invocationSource并决定如何进行相应操作。由于还启用了意图确认,因此也请使用confirmationStatus参数来知道用户是确认还是拒绝提示。

检查Lex传递给代码钩子Lambda的JSON结构的输入事件格式:https://docs.aws.amazon.com/lex/latest/dg/lambda-input-response-format.html#using-lambda-input-event-format

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。