【问题标题】:can we add view more option in hero card for long messages我们可以在英雄卡中为长消息添加查看更多选项吗
【发布时间】:2020-03-23 20:35:45
【问题描述】:

我正在使用微软的bot框架,是否可以为英雄卡中的长消息提供查看更多选项。

我的卡片正在渲染,我可以看到完整的文本。由于文本很长,聊天气泡不适合窗口。我知道我们可以拆分文本并发送两次,但我的客户对查看更多选项非常具体。

感谢任何帮助。

谢谢 桑吉夫

【问题讨论】:

    标签: botframework bots chatbot azure-bot-service


    【解决方案1】:

    取决于您连接的频道。对于示例,在 Facebook Messenger 上这是不可行的,因为那里允许的 UI 组件没有此选项。

    但对于支持Adaptive Cards 的其他频道,例如Partners,您可能会找到其他解决方案,例如为支持大文本和许多其他内容的卡片设置动态高度

    更新

    我希望这会有所帮助,因为自适应卡片中还没有“查看更多”选项,但有一个如下所示的切换选项

    转到Adaptive cards designer并将以下内容(替换原始json)粘贴到左下角的卡有效负载编辑器
    之后点击右上角的Preview Mode,然后点击预览卡片,就会有一个TOGGLE Action

    {
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.0",
    "body": [
        {
            "type": "Container",
            "selectAction": {
                "type": "Action.ToggleVisibility",
                "targetElements": [
                    "leg1Details"
                ]
            },
            "items": [
                {
                    "type": "ColumnSet",
                    "columns": [
                        {
                            "width": "24px",
                            "items": [
                                {
                                    "type": "Image",
                                    "style": "Person",
                                    "backgroundColor": "#0078D7",
                                    "url": "http://messagecardplayground.azurewebsites.net/assets/smallairplane_white.png"
                                }
                            ],
                            "type": "Column"
                        },
                        {
                            "width": "stretch",
                            "spacing": "Small",
                            "verticalContentAlignment": "Center",
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "text": "**Depart:** Delta Air Lines flight 8471 to Paris"
                                }
                            ],
                            "type": "Column"
                        }
                    ]
                },
                {
                    "type": "ColumnSet",
                    "spacing": "None",
                    "columns": [
                        {
                            "width": "24px",
                            "items": [
                                {
                                    "type": "Image",
                                    "horizontalAlignment": "Center",
                                    "width": "1px",
                                    "url": "http://messagecardplayground.azurewebsites.net/assets/palebluedot1x1.png",
                                    "height": "20px"
                                }
                            ],
                            "type": "Column"
                        },
                        {
                            "width": "stretch",
                            "spacing": "Small",
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "text": "Bengaluru, Sun 11/12/2017 1:55 AM, 10 hours 41 minutes",
                                    "isSubtle": true
                                }
                            ],
                            "type": "Column"
                        }
                    ]
                }
            ]
        },
        {
            "type": "ColumnSet",
            "id": "leg1Details",
            "isVisible": false,
            "spacing": "None",
            "columns": [
                {
                    "width": "24px",
                    "padding": "none",
                    "backgroundImage": {
                        "url": "http://messagecardplayground.azurewebsites.net/assets/palebluedot1x1.png",
                        "mode": "repeatVertically",
                        "horizontalAlignment": "Center"
                    },
                    "type": "Column"
                },
                {
                    "width": "stretch",
                    "spacing": "Small",
                    "items": [
                        {
                            "type": "Container",
                            "padding": {
                                "top": "default"
                            },
                            "items": [
                                {
                                    "type": "ColumnSet",
                                    "columns": [
                                        {
                                            "width": 45,
                                            "items": [
                                                {
                                                    "type": "Container",
                                                    "padding": "none",
                                                    "backgroundImage": "http://messagecardplayground.azurewebsites.net/assets/TxP_Background.png",
                                                    "items": [
                                                        {
                                                            "type": "Image",
                                                            "horizontalAlignment": "Center",
                                                            "url": "http://messagecardplayground.azurewebsites.net/assets/TxP_Flight.png"
                                                        }
                                                    ]
                                                },
                                                {
                                                    "type": "Container",
                                                    "style": "emphasis",
                                                    "spacing": "None",
                                                    "items": [
                                                        {
                                                            "type": "TextBlock",
                                                            "text": "Flight to Paris",
                                                            "wrap": true,
                                                            "size": "ExtraLarge",
                                                            "weight": "Lighter",
                                                            "color": "Accent"
                                                        },
                                                        {
                                                            "type": "TextBlock",
                                                            "text": "Delta Air Lines flight 8471",
                                                            "wrap": true,
                                                            "size": "Medium",
                                                            "spacing": "Small"
                                                        },
                                                        {
                                                            "type": "TextBlock",
                                                            "wrap": true,
                                                            "text": "Confirmation code: ABCDEF",
                                                            "size": "Medium",
                                                            "spacing": "None"
                                                        },
                                                        {
                                                            "type": "TextBlock",
                                                            "wrap": true,
                                                            "text": "10 hours 45 minutes",
                                                            "size": "Medium",
                                                            "spacing": "None"
                                                        }
                                                    ]
                                                }
                                            ],
                                            "type": "Column"
                                        },
                                        {
                                            "width": 55,
                                            "spacing": "None",
                                            "padding": "default",
                                            "items": [
                                                {
                                                    "type": "Container",
                                                    "height": "stretch",
                                                    "items": [
                                                        {
                                                            "type": "ColumnSet",
                                                            "columns": [
                                                                {
                                                                    "width": "auto",
                                                                    "items": [
                                                                        {
                                                                            "type": "TextBlock",
                                                                            "text": "BLR",
                                                                            "weight": "Lighter",
                                                                            "size": "ExtraLarge"
                                                                        }
                                                                    ],
                                                                    "type": "Column"
                                                                },
                                                                {
                                                                    "width": "stretch",
                                                                    "verticalContentAlignment": "Center",
                                                                    "items": [
                                                                        {
                                                                            "type": "Image",
                                                                            "width": "10000px",
                                                                            "url": "http://messagecardplayground.azurewebsites.net/assets/graydot2x2.png",
                                                                            "height": "2px"
                                                                        }
                                                                    ],
                                                                    "type": "Column"
                                                                },
                                                                {
                                                                    "width": "auto",
                                                                    "spacing": "Small",
                                                                    "verticalContentAlignment": "Center",
                                                                    "items": [
                                                                        {
                                                                            "type": "Image",
                                                                            "url": "http://messagecardplayground.azurewebsites.net/assets/smallairplane.png",
                                                                            "height": "16px"
                                                                        }
                                                                    ],
                                                                    "type": "Column"
                                                                },
                                                                {
                                                                    "width": "auto",
                                                                    "items": [
                                                                        {
                                                                            "type": "TextBlock",
                                                                            "text": "CDG",
                                                                            "weight": "Lighter",
                                                                            "horizontalAlignment": "Right",
                                                                            "size": "ExtraLarge"
                                                                        }
                                                                    ],
                                                                    "type": "Column"
                                                                }
                                                            ]
                                                        },
                                                        {
                                                            "type": "ColumnSet",
                                                            "columns": [
                                                                {
                                                                    "width": 1,
                                                                    "items": [
                                                                        {
                                                                            "type": "TextBlock",
                                                                            "text": "1:55 AM",
                                                                            "size": "Medium"
                                                                        }
                                                                    ],
                                                                    "type": "Column"
                                                                },
                                                                {
                                                                    "width": 1,
                                                                    "items": [
                                                                        {
                                                                            "type": "TextBlock",
                                                                            "text": "8:10 AM",
                                                                            "horizontalAlignment": "Right",
                                                                            "size": "Medium"
                                                                        }
                                                                    ],
                                                                    "type": "Column"
                                                                }
                                                            ]
                                                        },
                                                        {
                                                            "type": "ColumnSet",
                                                            "spacing": "None",
                                                            "columns": [
                                                                {
                                                                    "width": 1,
                                                                    "items": [
                                                                        {
                                                                            "type": "TextBlock",
                                                                            "isSubtle": true,
                                                                            "wrap": true,
                                                                            "text": "November 12, 2017"
                                                                        }
                                                                    ],
                                                                    "type": "Column"
                                                                },
                                                                {
                                                                    "width": 1,
                                                                    "items": [
                                                                        {
                                                                            "type": "TextBlock",
                                                                            "isSubtle": true,
                                                                            "wrap": true,
                                                                            "text": "November 12, 2017",
                                                                            "horizontalAlignment": "Right"
                                                                        }
                                                                    ],
                                                                    "type": "Column"
                                                                }
                                                            ]
                                                        },
                                                        {
                                                            "type": "ColumnSet",
                                                            "spacing": "None",
                                                            "columns": [
                                                                {
                                                                    "width": 1,
                                                                    "items": [
                                                                        {
                                                                            "type": "TextBlock",
                                                                            "isSubtle": true,
                                                                            "text": "Bengaluru"
                                                                        }
                                                                    ],
                                                                    "type": "Column"
                                                                },
                                                                {
                                                                    "width": 1,
                                                                    "items": [
                                                                        {
                                                                            "type": "TextBlock",
                                                                            "isSubtle": true,
                                                                            "text": "Paris",
                                                                            "horizontalAlignment": "Right"
                                                                        }
                                                                    ],
                                                                    "type": "Column"
                                                                }
                                                            ]
                                                        }
                                                    ]
                                                },
                                                {
                                                    "type": "ColumnSet",
                                                    "horizontalAlignment": "Right",
                                                    "separator": true,
                                                    "spacing": "Large",
                                                    "columns": [
                                                        {
                                                            "width": "auto",
                                                            "selectAction": {
                                                                "type": "Action.OpenUrl",
                                                                "url": "http://www.microsoft.com"
                                                            },
                                                            "items": [
                                                                {
                                                                    "type": "ColumnSet",
                                                                    "columns": [
                                                                        {
                                                                            "width": "auto",
                                                                            "verticalContentyAlignment": "center",
                                                                            "items": [
                                                                                {
                                                                                    "type": "Image",
                                                                                    "url": "http://messagecardplayground.azurewebsites.net/assets/smallairplane.png",
                                                                                    "height": "16px"
                                                                                }
                                                                            ],
                                                                            "type": "Column"
                                                                        },
                                                                        {
                                                                            "width": "auto",
                                                                            "spacing": "Small",
                                                                            "items": [
                                                                                {
                                                                                    "type": "TextBlock",
                                                                                    "text": "Check in"
                                                                                }
                                                                            ],
                                                                            "type": "Column"
                                                                        }
                                                                    ]
                                                                }
                                                            ],
                                                            "type": "Column"
                                                        },
                                                        {
                                                            "width": "auto",
                                                            "spacing": "Large",
                                                            "selectAction": {
                                                                "type": "Action.OpenUrl",
                                                                "url": "http://www.microsoft.com"
                                                            },
                                                            "items": [
                                                                {
                                                                    "type": "ColumnSet",
                                                                    "columns": [
                                                                        {
                                                                            "width": "auto",
                                                                            "verticalContentyAlignment": "center",
                                                                            "items": [
                                                                                {
                                                                                    "type": "Image",
                                                                                    "url": "http://messagecardplayground.azurewebsites.net/assets/calendaricon.png",
                                                                                    "height": "16px"
                                                                                }
                                                                            ],
                                                                            "type": "Column"
                                                                        },
                                                                        {
                                                                            "width": "auto",
                                                                            "spacing": "Small",
                                                                            "items": [
                                                                                {
                                                                                    "type": "TextBlock",
                                                                                    "text": "View in Calendar"
                                                                                }
                                                                            ],
                                                                            "type": "Column"
                                                                        }
                                                                    ]
                                                                }
                                                            ],
                                                            "type": "Column"
                                                        }
                                                    ]
                                                }
                                            ],
                                            "type": "Column"
                                        }
                                    ]
                                }
                            ]
                        }
                    ],
                    "type": "Column"
                }
            ]
        }
     ]}
    

    【讨论】:

    • 感谢您的回复。我需要在网页中托管我的机器人。
    • 您将使用支持自适应卡的 Direct Line 频道。因此,我建议您检查它们并使用它们的出色功能!您也可以创建自己的自定义卡片。
    • 我找不到更多信息。可能我有更多的探索。你能帮我解决这个问题吗?比如一些代码什么的
    • 我尝试了你的建议,它在自适应卡片设计器中运行良好。当我尝试在我的机器人中实现时它不起作用。当我添加 Action.ToggleVisibility 按钮未呈现时。但是当我将类型更改为 Action.ShowCard 或 openurl 按钮正在加载。谢谢
    • 我很高兴它成功了!如果我的回答有帮助,如果您能接受或支持它,那就太好了!如果你能更新你的答案,展示你是如何让它工作的,那就太好了,这样其他人也会受益
    猜你喜欢
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-28
    • 1970-01-01
    • 2021-12-06
    相关资源
    最近更新 更多