问题
I am trying to make a response card in amazon lex to give out a response card that has a button that leads to another website. Below is the code that I have used in aws lambda python. I have published the chatbot on facebook messenger. But whenever I select the button in fb messenger, the link in the button does not seem to bring me to the website. Is there any way to make the response card button turn into hyperlink button?
def location(intent_request):
session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
return {
'dialogAction': {
'type': 'Close',
'fulfillmentState': 'Fulfilled',
'message': {
'contentType': 'PlainText',
'content': 'Here is a map'
},
'responseCard': {
'version': '17',
'contentType': 'application/vnd.amazonaws.card.generic',
'genericAttachments': [
{
'title': 'Here is a list of hospitals',
'subTitle': 'Below is a map',
"buttons":[
{
"text":"Show Google Maps",
"value":"https://www.google.com/maps/search/?api=1&query=nearby+hospitals"
}
]
}
]
}
}
}
回答1:
As of now you cannot do that using the buttons. The buttons have two parameters text
and value
. When you click on a button, the value
of button is sent to the servers and the text
is appended to the chat. So it will just send the value back to Lex
but cannot open function as hyperlink.
However you can use image in the response card for the same functionality. imageUrl
is the url of the image to be displayed, and attachmentLinkUrl
is the url which you want to open. So I would suggest you to remove buttons and use an image of map to be shown and provide your hyperlink in attachmentLinkUrl
.
Also, if you want to show multiple hyperlink, you can show multiple cards (upto 10) in a single responseCard
.
Below is a sample code:
return {
'dialogAction': {
'type': 'Close',
'fulfillmentState': 'Fulfilled',
'message': {
'contentType': 'PlainText',
'content': message
},
'responseCard': {
'version': '0',
'contentType': 'application/vnd.amazonaws.card.generic',
'genericAttachments': [
{
'title': 'Here is a list of hospitals',
'subTitle': 'Below is a map',
'attachmentLinkUrl': 'https://www.google.com/maps/search/?api=1&query=nearby+hospitals',
'imageUrl': 'https://images.sftcdn.net/images/t_optimized,f_auto/p/95612986-96d5-11e6-af7c-00163ec9f5fa/3771854867/google-maps-screenshot.png'
},
{
'title': 'Here is a list of medical shops',
'subTitle': 'Below is a map',
'attachmentLinkUrl': 'https://www.google.com/maps/search/?api=1&query=nearby+medical+shops',
'imageUrl': 'https://images.sftcdn.net/images/t_optimized,f_auto/p/95612986-96d5-11e6-af7c-00163ec9f5fa/3771854867/google-maps-screenshot.png'
}
]
}
}
}
You can check this as well for details about response cards.
Hope it helps.
来源:https://stackoverflow.com/questions/48554902/hyperlink-in-response-card-button-in-amazon-lex