问题
I have created a lex chatbot and integrated it into website .Its working fine.I got to know that I have to invoke response cards from lambda .I did that too.Also,I enabled repsonse card checkbox in lex console.After all this,I am not able too see the buttons in the website.Is there any other way to display the buttons other than response cards?
Below is the code:Here,after the fulfillment,I have given the response card which means that after the message "Hey your ticket has been raised",the buttons will be displayed.This displays in lex test chatbot.
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
回答1:
I believe your problem is the version number. Try setting it to 1
or '1'
.
I couldn't find a clear explanation as to why, but here are some evidences at least:
From the AWS example doc: Generating Response Cards Dynamically
responseCard: {
"version": 1,
...
}
I also looked deeper into the lex-web-ui files you are using and in the lex-web-ui.js file it has this:
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;
},
And that specifically checks for (this.message.responseCard.version === '1' || this.message.responseCard.version === 1)
in order to display.
来源:https://stackoverflow.com/questions/62975180/response-cards-not-showing-amazon-lex