Amazon Lex中的响应卡中的超链接按钮 [英] Hyperlink in response card button in Amazon Lex

查看:76
本文介绍了Amazon Lex中的响应卡中的超链接按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Amazon lex制作响应卡,以给出响应卡,该响应卡具有指向另一个网站的按钮.以下是我在AWS Lambda python中使用的代码.我已经在Facebook Messenger上发布了聊天机器人.但是,每当我在fb Messenger中选择按钮时,该按钮中的链接似乎都无法将我带到该网站.有什么办法可以将响应卡按钮变成超链接按钮?

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"
                     }
                    ]
                }
            ]
            }
        }
    }

推荐答案

到目前为止,您无法使用按钮进行操作.这些按钮具有两个参数textvalue. 单击按钮时,按钮的value发送到服务器,而text附加到聊天室.因此,它只会将值发送回Lex,但不能打开功能作为超链接.

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.

但是,您可以在响应卡中使用图像来实现相同的功能. imageUrl是要显示的图像的URL,而attachmentLinkUrl是要打开的URL.因此,我建议您删除按钮并使用要显示的地图图像,并在attachmentLinkUrl中提供您的超链接.
另外,如果要显示多个超链接,则可以在单个responseCard中显示多个卡片(最多10张).

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.

以下是示例代码:

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.

这篇关于Amazon Lex中的响应卡中的超链接按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆