响应卡未显示在website-lex中 [英] Response cards not displaying in website-lex

查看:57
本文介绍了响应卡未显示在website-lex中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了Lex Chatbot并开发了一个网站并集成了该Chatbot.它的工作正常.但是按钮形式的响应卡没有出现.我知道我必须从lambda函数中调用它.所以我包含了响应卡代码.它可以工作,但是在显示按钮后返回然后再次询问第一个广告位值.我不知道我哪里错了

I have created Lex Chatbot and developed a website and integrated this Chatbot. Its working fine.But response cards in the form of buttons are not showing up.I got to know that I have to invoke it from lambda function.So I included the response card code .It works ,but after displaying the buttons it goes back and asks the first slot value again.I dont know where I am wrong

这是预期的对话.

User:Hi
Lex:请给我您的开斋节
用户:e123456
Lex:请选择以下影响之一:
1.低2.高3.中(以按钮的形式)
用户点击低
Lex:谢谢,你的票已经升起(预期)

User:Hi
Lex:Please provide me your eid
User:e123456
Lex:Choose one of the impact below:
1.low 2.high 3.medium (in form of buttons)
User clicks on low
Lex:Thanks,your ticket has been raised(expected)

会发生什么:

User:Hi
Lex:请给我您的开斋节
用户:e123456
Lex:请选择以下影响之一:
1.低2.高3.中
用户点击低
Lex:请给我您的eid(回去并询问第一个广告位值)

User:Hi
Lex:Please provide me your eid
User:e123456
Lex:Choose one of the impact below:
1.low 2.high 3.medium
User clicks on low
Lex:Please provide me your eid(goes back and asks the first slot value)

这是我的代码:

import json
import logging
import re
import http.client
import mimetypes

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

  
def elicit_slot_response(output_session_attributes,intent_name,slot_to_elicit,message):
    responses= {
     'dialogAction': {
     'type': 'ElicitSlot',
     'slottoElicit':'slot_to_elicit',
     'message': {
      'contentType': 'PlainText',
      'content': message
                },
      'responseCard': {
                'version': '0',
                'contentType': 'application/vnd.amazonaws.card.generic',
                'genericAttachments': [
                    {
                    'title': 'title1',
                    'subTitle': 'subtitle',
                    "buttons":[ 
                     {
                        "text":"button 1",
                        "value":"value 1"
                     },
                     {
                        "text":"button 2",
                        "value":"value 2"
                     },
                     {
                        "text":"button 3",
                        "value":"value 3"
                     }
                        ]
                    }
                    ]
                                 }
     }
   }

    return responses    


def close():
    val=  {
             "dialogAction":
            {
                "fulfillmentState":"Fulfilled",
                "type":"Close",
                "message":
                 {
                     "contentType":"PlainText",
                     "content":"Hey your ticket has been raised"
                 }
                    }
                    
                }
    print(val)
    return val
    

def lambda_handler(event, context):
    val = ""
    slots = event['currentIntent']['slots']
    empidemployee= event['currentIntent']["slots"]["empidemployee"]
    latestdesc= event['currentIntent']["slots"]["latestdesc"]
    latestimpact= event['currentIntent']["slots"]["latestimpact"]
    output_session_attributes = event['sessionAttributes'] if event['sessionAttributes'] is not None else {}
    elicit_slot_response(output_session_attributes,'latestdetails','latestimpact',"impact")
    val=close()
    return val
   
    

推荐答案

对话流程重新启动,因为在包含响应卡的Lambda函数的ElicitSlot响应中,您没有返回包含以下内容的slots参数:用户已经输入的广告位值.

The conversation flow restarts because in the ElicitSlot response from the Lambda function containing the response cards, you are not returning the slots parameter which would contain the slot values already taken as an input from the user.

因此,在响应,其值可以为event['currentIntent']['slots'].

So, include the slots parameter in the response the value for which could be event['currentIntent']['slots'].

这篇关于响应卡未显示在website-lex中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆