您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

设计用户体验Design the user experience


可以创建具有各种特征的机器人,例如,以轮播或列表格式显示的文本、按钮、图像和丰富卡片等。You can create bots with a variety of features such as text, buttons, images, rich cards displayed in carousel or list format, and more. 但是,每个通道(例如 Facebook、Slack 等)However, each channel such as Facebook, Slack, etc. 最终会控制消息传递客户端呈现特征的方式。ultimately controls how its messaging clients render features. 即使多个通道均支持某个特征,每个通道也可能以略有不同的方式呈现该特征。Even when multiple channels support a feature, each channel may render the feature in a slightly different way. 如果消息包含某通道本身不支持的功能,则该通道可能会尝试将消息内容向下呈现为文本或静态图像,这可能会显著影响消息在客户端上的外观。In cases where a message contains feature(s) that a channel does not natively support, the channel may attempt to down-render message contents as text or as a static image, which can significantly impact the message's appearance on the client. 某些情况下,通道可能根本不支持特定功能。In some cases, a channel may not support a particular feature at all. 例如,GroupMe 客户端无法显示键入指示器。For example, GroupMe clients cannot display a typing indicator.

富用户控件Rich user controls

“富用户控件”是常用的 UI 控件,例如按钮、图像、轮播和菜单。机器人可以将这些控件提供给用户,然后用户即可用其来传递选择和意向。Rich user controls are common UI controls such as buttons, images, carousels, and menus that the bot presents to the user and the user engages with to communicate choice and intent. 机器人可以使用 UI 控件集来模拟应用,甚至可以在应用中以嵌入方式运行。A bot can use a collection of UI controls to mimic an app, or can even run embedded within an app. 机器人嵌入应用或网站时,可以利用托管它的应用的功能,因此可以表示几乎任何 UI 控件。When a bot is embedded within an app or website, it can represent virtually any UI control by leveraging the capabilities of the app that is hosting it.

几十年来,应用程序和网站开发人员一直依赖于 UI 控件来启用用户与其应用程序的交互,而这些相同的 UI 控件也可在机器人中高效使用。For decades, application and website developers have relied on UI controls to enable users to interact with their applications and these same UI controls can also be very effective in bots. 例如,可以通过按钮为用户提供简单的选择。For instance, buttons are a great way to present the user with a simple choice. 让用户通过单击标记为“Hotels”的按钮来传达“Hotels”的意思比强制用户键入“Hotels”要容易,且更快速。 Allowing the user to communicate "Hotels" by clicking a button labeled Hotels is easier and quicker than forcing the user to type "Hotels." 这在移动设备上尤其如此,用户更喜欢单击而不是键入。This especially holds true on mobile devices, where clicking is greatly preferred over typing.


可以通过卡为用户提供各种视觉、听觉和/或可选择的消息,为聊天流提供帮助。Cards allow you to present your users with a variety of visual, audio, and/or selectable messages and help to assist conversation flow. 如果用户需要从固定的一组项目中进行选择,则可以轮播的方式显示多张卡,每张都包含图像、文本说明和单个选择按钮。If a user needs to select from within a fixed set of items you can display a carousel of cards, each containing an image, a text description, and a single selection button. 如果用户有一组针对单个项的选择,则可显示较小的单个图像和一组按钮,并提供可供选择的各种选项。If a user has a set of choices for a single item, you can present a smaller single image and a collection of buttons with various options to choose between. 他们是否要求提供某个主题的详细信息?Did they ask for more information on a subject? 卡可以使用音频或视频输出提供深度信息,或者提供详细介绍其购物体验的回执。Cards can provide in depth information using audio or video output, or a receipt that details their shopping experience. 纸牌的各种使用范围广泛,有助于指导用户与机器人之间的对话。There is an incredibly wide range of uses for cards to help guide the conversation between your user and your bot. 所用卡的类型取决于应用程序的需求。The type of card you use will be determined by the needs of your application. 让我们更深入地了解卡、其操作以及某些建议使用。Let's take a closer look at cards, their actions, and some recommended uses.

Microsoft 机器人服务卡是可编程的对象,包含标准化的集合,而这些集合中的富用户控件可以跨不同范围的通道进行识别。Microsoft Bot Service cards are programmable objects containing standardized collections of rich user controls that are recognized across a wide range of channels. 下表介绍了可用卡的列表,并针对每种类型的卡提供了使用方面的最佳做法建议。The following table describes the list of available cards and best practice suggestions of usage for each type of card.

卡类型Card type 示例Example 说明Description
AdaptiveCardAdaptiveCard 自适应卡图像 一种开放式卡交换格式,以 JSON 对象方式呈现。An open card exchange format rendered as a JSON object. 通常用于跨通道部署卡。Typically used for cross-channel deployment of cards. 卡会适应每个托管通道的外观。Cards adapt to the look and feel of each host channel.
AnimationCardAnimationCard 动画卡图像 一种可播放动态 GIF 或短视频的卡。A card that can play animated GIFs or short videos.
AudioCardAudioCard 音频卡图像 一种可播放音频文件的卡。A card that can play an audio file.
HeroCardHeroCard 英雄卡图像 包含单个大图像、一个或多个按钮和文本的卡。A card that contains a single large image, one or more buttons, and text. 通常用于以视觉方式突出显示可能的用户选择。Typically used to visually highlight a potential user selection.
ThumbnailCardThumbnailCard 缩略图卡图像 包含单个缩略图图像、一个或多个按钮和文本的卡。A card that contains a single thumbnail image, one or more buttons, and text. 通常用于以视觉方式突出显示可能的用户选择的按钮。Typically used to visually highlight the buttons for a potential user selection.
ReceiptCardReceiptCard 回执卡图像 一种让机器人能够向用户提供收据的卡。A card that enables a bot to provide a receipt to the user. 它通常包含要包括在收据中的项目列表、税款和总计信息以及其他文本。It typically contains the list of items to include on the receipt, tax and total information, and other text.
SignInCardSignInCard 登录卡图像 一种让机器人能够请求用户登录的卡。A card that enables a bot to request that a user sign-in. 它通常包含文本和一个或多个按钮,用户可以单击这些按钮来启动登录进程。It typically contains text and one or more buttons that the user can click to initiate the sign-in process.
SuggestedActionSuggestedAction 建议的操作卡图像 为用户提供一组表示用户选择的 CardAction。Presents your user with a set of CardActions representing a user choice. 在选中任何建议的操作以后,此卡会消失。This card disappears once any of the suggested actions is selected.
VideoCardVideoCard 视频卡图像 一种可播放视频的卡。A card that can play videos. 通常用于打开 URL 并流式传输提供的视频。Typically used to open a URL and stream an available video.
CardCarouselCardCarousel 卡轮播图像 一个可水平滚动的卡集合,可以让用户轻松地查看一系列可能的用户选择。A horizontally scrollable collection of cards that allows your user to easily view a series of possible user choices.

可以通过卡对机器人设计一次,然后就可以让机器人跨各种通道使用。Cards allow you to design your bot once, and have it work across a variety of channels. 但是,并非所有卡类型在所有可用通道中都受到完全的支持。However, not all card types are fully supported across all available channels.

有关如何向机器人添加卡的详细说明,可参阅添加富卡媒体附件向消息添加建议的操作部分。Detailed instructions for adding cards to your bot can be found within these sections Add rich card media attachments and Add suggested actions to messages. 还可以在下面找到卡片的示例代码:C#/JS 自适应卡片:C#/JS,附件:C#/JS 和建议的操作:C#/JSSample code can also be found here for cards: C#/JS adaptive cards: C#/JS, attachments: C#/JS, and suggested actions: C#/JS.

设计机器人时,请勿因为常用的 UI 元素“不够智能”而自动放弃使用它们。When designing your bot, do not automatically dismiss common UI elements as not being "smart enough." 所述,在设计机器人时,应该尽可能以最佳、最快和最易的方式解决用户的问题。As discussed previously, your bot should be designed to solve the user's problem in the best, quickest, and easiest manner possible. 避免一冲动就纳入自然语言理解,因为这通常是不必要的,会引入不必要的复杂性。Avoid the temptation to start by incorporating natural language understanding, as it is often unnecessary and introduces unjustified complexity.


一开始尽量使用最少的 UI 控件,只要机器人能够解决用户的问题就可以了。如果以后这些控件不够用了,再添加其他元素。Start by using the minimum UI controls that enable the bot to solve the user's problem, and add other elements later if those controls are no longer sufficient.

文本和自然语言理解Text and natural language understanding

机器人可以接受用户的 文本 输入,并尝试使用正则表达式匹配或 自然语言理解 API(例如 LUIS)对该输入进行分析。A bot can accept text input from users and attempt to parse that input using regular expression matching or natural language understanding APIs, such as LUIS. 自然语言理解不一定是好的解决方案,具体取决于用户提供的输入类型。Depending on the type of input that the user provides, natural language understanding may or may not be a good solution.

在某些情况下,用户会 回答非常具体的问题In some cases, a user may be answering a very specific question. 例如,如果机器人问“你叫什么名字?”,则用户可能会使用只指定名称的文本“John”回答,或者使用句子“我的名字是 John”回答。For example, if the bot asks, "What is your name?", the user may answer with text that specifies only the name, "John", or with a sentence, "My name is John".

提问具体的问题可以缩小机器人正常情况下可能会收到的响应的范围,降低对响应进行分析和理解所需的逻辑的复杂性。Asking specific questions reduces the scope of potential responses that the bot might reasonably receive, which decreases the complexity of the logic necessary to parse and understand the response. 例如,考虑提问下述宽泛的、没有固定答案的问题:“你感觉怎样?”。For example, consider the following broad, open-ended question: "How are you feeling?". 对于这样的问题,必须了解潜在答案的各种可能的排列组合,这是很复杂的任务。Understanding the many possible permutations of potential answers to such a question is a very complex task.

与之相反,对于“你觉得痛吗?是/否”和“你感到哪里痛?胸/头/手臂/腿”这样的具体问题,则需要更具体的回答,机器人不需实施自然语言理解就可以分析和理解这些回答。In contrast, specific questions such as "Are you feeling pain? yes/no" and "Where are you feeling pain? chest/head/arm/leg" would likely prompt more specific answers that a bot can parse and understand without needing to implement natural language understanding.


尽可能提问具体问题,这些问题不需要对响应进行分析所需的自然语言理解功能。Whenever possible, ask specific questions that will not require natural language understanding capabilities to parse the response. 这样就会简化机器人,提高机器人理解用户话语的成功率。This will simplify your bot and increase the success your bot will understand the user.

其他情况下,用户可能会 键入特定的命令In other cases, a user may be typing a specific command. 例如,允许开发人员用来管理虚拟机的 DevOps 机器人可能会被设计成接受特定的命令,如“/STOP VM XYZ”或“/START VM XYZ”。For example, a DevOps bot that enables developers to manage virtual machines could be designed to accept specific commands such as "/STOP VM XYZ" or "/START VM XYZ". 将机器人设计成接受这样的具体命令可以提供很好的用户体验,因为该语法易于学习,而每个命令的预期结果很清楚。Designing a bot to accept specific commands like this makes for a good user experience, as the syntax is easy to learn and the expected outcome of each command is clear. 另外,机器人不需自然语言理解功能,因为用户的输入可以通过正则表达式轻松地进行分析。Additionally, the bot will not require natural language understanding capabilities, since the user's input can be easily parsed using regular expressions.


将机器人设计成要求用户提供具体命令通常会提供好的用户体验,同时也不需自然语言理解功能。Designing a bot to require specific commands from the user can often provide a good user experience while also eliminating the need for natural language understanding capability.

使用知识库机器人或问答式机器人时, 用户可能会 提问一般性问题In the case of a knowledge base bot or questions and answers bot, a user may be asking general questions. 例如,假设一个机器人可以根据数千个文档的内容回答问题。For example, imagine a bot that can answer questions based on the contents of thousands of documents. QnA MakerAzure 搜索都是专门针对此类场景设计的技术。QnA Maker and Azure Search are both technologies which are designed specifically for this type of scenario. 有关详细信息,请参阅设计知识库机器人For more information, see Design knowledge bots.


如果设计的机器人可以根据数据库、网页或文档中的结构化或非结构化数据来回答问题,请考虑使用专门针对此类场景设计的技术,而不要尝试使用自然语言理解来解决问题。If you are designing a bot that will answer questions based on structured or unstructured data from databases, web pages, or documents, consider using technologies that are designed specifically to address this scenario rather than attempting to solve the problem with natural language understanding.

在其他情况下,用户可能会 键入基于自然语言的简单请求In other scenarios, a user may be typing simple requests based on natural language. 例如,用户可能会键入“我需要意大利辣肠比萨”或“我住所 3 英里内现在是否有素食馆开放?”。For example, a user may type "I want a pepperoni pizza" or "Are there any vegetarian restaurants within 3 miles from my house open now?". 自然语言理解 API(例如 LUIS.ai)最适合此类场景。Natural language understanding APIs such as LUIS.ai are a great fit for scenarios like this.

机器人可以使用此类 API 提取用户文本的关键组件,以便确定用户的意向。Using the APIs, your bot can extract the key components of the user's text to identify the user's intent. 在机器人中实现自然语言理解功能时,请为用户可能在其输入中提供的内容的详细程度设置务实的预期。When implementing natural language understanding capabilities in your bot, set realistic expectations for the level of detail that users are likely to provide in their input.



生成自然语言模型时,请勿假定用户会在其初始查询中提供所有必需的信息。When building natural language models, do not assume that users will provide all the required information in their initial query. 请将机器人设计为明确请求所需的信息,根据需要提问一系列问题,引导用户提供该信息。Design your bot to specifically request the information it requires, guiding the user to provide that information by asking a series of questions, if necessary.


与用户沟通时,机器人可以使用 语音 输入和/或输出。A bot can use speech input and/or output to communicate with users. 如果将机器人设计为支持没有键盘或监视器的设备,则与用户沟通时,语音是唯一的方式。In cases where a bot is designed to support devices that have no keyboard or monitor, speech is the only means of communicating with the user.

在富用户控件、文本和自然语言、语音之间进行选择Choosing between rich user controls, text and natural language, and speech

就像人们彼此交流时组合使用手势、声音和符号一样,机器人也可以在与用户交流时组合使用富用户控件、文本(有时包括自然语言)和语音。Just like people communicate with each other using a combination of gestures, voice, and symbols, bots can communicate with users using a combination of rich user controls, text (sometimes including natural language), and speech. 这些沟通方式可以一起使用;不需非此即彼。These communication methods can be used together; you do not need to choose one over another.

例如,假设有一个可以为用户提供食谱帮助的“烹饪机器人”,该机器人在提供说明时,可以播放视频,也可以显示一系列的图片,目的是说明需要做的事情。For example, imagine a "cooking bot" that helps users with recipes, where the bot may provide instructions by playing a video or displaying a series of pictures to explain what needs to be done. 某些用户在按照食谱烹饪时,可能倾向于以翻页的方式浏览食谱,或者使用语音向机器人提问问题。Some users may prefer to flip pages of the recipe or ask the bot questions using speech while they are assembling a recipe. 另一些用户可能倾向于触摸设备的屏幕,而不是通过语音与机器人交互。Others may prefer to touch the screen of a device instead of interacting with the bot via speech. 设计机器人时,请结合 UX 元素,这些元素支持用户可能更喜欢与机器人交互的方式,但前提是它旨在支持的特定用例。When designing your bot, incorporate the UX elements that support the ways in which users will likely prefer to interact with your bot, given the specific use cases that it is intended to support.