Hyperlink in response card button in Amazon Lex

这一生的挚爱 提交于 2020-01-24 10:14:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!