【问题标题】:How to add Response Card in Lex using PutIntent method?如何使用 PutIntent 方法在 Lex 中添加响应卡?
【发布时间】:2018-10-30 16:23:08
【问题描述】:

我正在尝试使用putIntent() 在 lex 中添加响应卡。在 AWS 中,putIntent 方法接受 responseCard 作为字符串,但如何在使用响应卡创建 Intent 时添加 titlesubTitleImageUrlbutton 值和 button 名称参数通过putIntent?

所以谁能帮我解决这个问题。提供一个示例输入,其中响应卡作为可以包含上述属性的字符串。提前谢谢你。

"slots": [
    {
        "description": "string",
        "name": "string",
        "priority": number,
        "responseCard": "string",
        "sampleUtterances": [ "string" ],
        "slotConstraint": "string",
        "slotType": "string",
        "slotTypeVersion": "string",
        "valueElicitationPrompt": {
        "maxAttempts": number,
        "messages": [
            {
                "content": "string",
                "contentType": "string",
                "groupNumber": number
            }
        ],
        "responseCard": "string" --(how to pass title, imageUrl and other attributes) 
    }

【问题讨论】:

    标签: aws-sdk amazon-lex


    【解决方案1】:

    看起来您从Lex API PutIntent 获得了完整响应格式的正确插槽部分。

    responseCard 格式可以在 Lambda Input Response Format 找到

    "responseCard": {
      "version": integer-value,
      "contentType": "application/vnd.amazonaws.card.generic",
      "genericAttachments": [
          {
             "title":"card-title",
             "subTitle":"card-sub-title",
             "imageUrl":"URL of the image to be shown",
             "attachmentLinkUrl":"URL of the attachment to be associated with the card",
             "buttons":[ 
                 {
                    "text":"button-text",
                    "value":"Value sent to server on button click"
                 }
              ]
           } 
       ] 
    }
    

    假设您以上述格式将 responseCard 对象创建为名为 responseCard 的变量,然后将该对象作为字符串传递给 PutIntent 尝试:

    JSON.stringify(responseCard) 如果使用 Node.js,或者
    json.dumps(responseCard, separators=(',',':')) 如果使用 Python。

    【讨论】:

    • 感谢您的回复。我已经尝试过这种方法,但没有奏效。无法在 Amazon lex 控制台中看到该特定提示的响应卡。
    • 我明白了。您绝对应该在您的问题中包含您之前尝试过的内容以及任何代码示例或在这些尝试期间发生的任何错误。据我所知,没有其他格式可以将 responseCard 作为字符串传递,因此我会考虑调试您之前的尝试。因此,我建议编辑您的问题以包含该代码和任何错误或只是发生了什么。
    • 需要注意的是,Amazon Lex 控制台不呈现响应卡。即使您在那里看不到它也可能是正确的。
    • 这实际上不是真的。 Lex 控制台会呈现响应卡,但您必须提供图像 URL(实际上并不需要获取响应卡对象)。不幸的是,它只是有点错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-08
    相关资源
    最近更新 更多