How to add Response Card in Lex using PutIntent method?

Viewed 702

I am trying to add a Response Card in lex using putIntent(). In AWS the putIntent method accepts responseCard as a String but how to add title, subTitle, ImageUrl, button values, and button names at the time of creating an Intent using response card parameter through putIntent?

So can anyone please help me to solve the issue. Provide a sample input where response card as String which can contain the above attributes. Thank you in advance.

"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) 
    }
1 Answers

Looks like you got the correct slots portion of the full response format from Lex API PutIntent.

The responseCard format can be found at 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"
             }
          ]
       } 
   ] 
}

Assuming you create that responseCard object in the format above as a variable named responseCard, then to make that object a string to pass in PutIntent try:

JSON.stringify(responseCard) if using Node.js, or
json.dumps(responseCard, separators=(',',':')) if using Python.

Related