【问题标题】:Response cards not showing -Amazon lex响应卡未显示 -Amazon lex
【发布时间】:2020-11-08 12:17:06
【问题描述】:

我创建了一个 lex 聊天机器人并将其集成到网站中。它工作正常。我知道我必须从 lambda 调用响应卡。我也这样做了。此外,我在 lex 控制台中启用了响应卡复选框。之后这一切,我也看不到网站上的按钮。除了响应卡,还有其他方法可以显示按钮吗?

下面是代码:这里,完成后,我已经给出了响应卡,这意味着在消息“嘿,您的票已被提出”之后,将显示按钮。这显示在 lex 测试聊天机器人中。

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

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


def close():
    val=  {
             "dialogAction":
            {
                "fulfillmentState":"Fulfilled",
                "type":"Close",
                "message":
                 {
                     "contentType":"PlainText",
                     "content":"Hey your ticket has been raised"
                 },
                '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"
                     }
                        ]
                    }
                    ]
                                 }
                    }
                }
    print(val)
    return val
    

def lambda_handler(event, context):
   
    slots = event['currentIntent']['slots']
    empidemployee= event['currentIntent']["slots"]["empidemployee"]
    latestdesc= event['currentIntent']["slots"]["latestdesc"]
    latestservice= event['currentIntent']["slots"]["latestservice"]
    latestimpactvalue= event['currentIntent']["slots"]["latestimpactvalue"]
    latesturgency= event['currentIntent']["slots"]["latesturgency"]
    basicinfo=event['currentIntent']["slots"]["basicinfo"]
    val=close()
    return val
    

【问题讨论】:

标签: aws-lambda amazon-lex


【解决方案1】:

我相信你的问题是版本号。尝试将其设置为1'1'

我找不到明确的解释,但至少有一些证据:

来自 AWS 示例文档:Generating Response Cards Dynamically

responseCard: {
    "version": 1,
        ...
}

我还深入研究了您正在使用的 lex-web-ui 文件,并在 lex-web-ui.js 文件中包含以下内容:

shouldDisplayResponseCard: function shouldDisplayResponseCard() {
  return this.message.responseCard && (this.message.responseCard.version === '1' || this.message.responseCard.version === 1) && this.message.responseCard.contentType === 'application/vnd.amazonaws.card.generic' && 'genericAttachments' in this.message.responseCard && this.message.responseCard.genericAttachments instanceof Array;
},

这会专门检查 (this.message.responseCard.version === '1' || this.message.responseCard.version === 1) 以便显示。

【讨论】:

  • 我也试过这个。我将版本号更改为 1 并使用别名 'BETA' 发布,这是在 aws 开发人员指南中推荐的。但是这些方法都没有反映。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-28
  • 2021-10-23
  • 1970-01-01
相关资源
最近更新 更多