category
消息扩展允许用户通过Microsoft Teams客户端中的按钮和表单与您的web服务交互。用户可以从撰写消息区域、命令框或直接从消息中在外部系统中搜索或启动操作。这些交互的结果可以作为格式丰富的卡片返回给Teams客户端。
重要事项
消息扩展可在政府社区云(GCC)、GCC High和国防部(DOD)环境中使用。
本文概述了消息扩展、用例、功能、操作和搜索命令以及链接展开。
下图显示了可以调用消息扩展的位置:
注:
@不支持在撰写框中提及消息扩展名。
与外部用户的群聊不支持消息扩展选项。
Scenarios where message extensions are used
Scenario | Example |
---|---|
You need an external system to perform an action and return the result to your conversation. | Reserve a resource and allow the channel to know the reserved time slot. |
You need to search for something in an external system and share the results with the conversation. | Search for a work item in Azure DevOps and share it with the group as an Adaptive Card. |
You want to complete a complex task involving multiple steps or large amounts of information in an external system and share the results with a conversation. | Create a bug in your tracking system based on a Teams message, assign that bug, and send a card to the conversation thread with the bug's details. |
Understand how message extensions work
A message extension is composed of a web service hosted by you and an app manifest that defines the location where your web service is invoked within the Teams client. The web service utilizes the Bot Framework's messaging schema and secure communication protocol, so you must register your web service as a bot in the Bot Framework.
Note
Though it's possible to manually create the web service, we recommend to use Bot Framework SDK to work with the protocol.
In the app manifest (previously called as Teams app manifest), a single message extension is defined with up to 10 different commands. Each command defines a type, such as action or search and the locations in the client from where the message extension is invoked. The invoke locations include the compose message area, command bar, and message. On invoke, the web service receives an HTTPS message with a JSON payload with all the relevant information. Respond with a JSON payload to inform the Teams client of the next interaction to enable.
消息扩展命令类型
有两种类型的消息扩展命令,动作命令和搜索命令。消息扩展命令类型定义了web服务可用的UI元素和交互流。某些交互,如身份验证和配置,可用于这两种命令类型。
动作命令
动作命令用于向用户呈现一个模态弹出窗口,以收集或显示信息。当用户提交表单时,您的web服务会通过将消息直接插入对话或插入撰写消息区域来做出响应。稍后,用户可以提交消息。对于更复杂的工作流,您可以将多个表单链接在一起。
动作命令从编写消息区域、命令框或消息中触发。当从消息中调用命令时,发送给机器人的初始JSON有效载荷包括调用它的整个消息。下图显示了消息扩展操作命令对话框(在TeamsJS v1.x中称为任务模块):
Search commands
搜索命令允许用户在外部系统中搜索信息。要使用搜索命令,请在搜索框中手动输入查询,或在撰写邮件区域中插入指向受监视域的链接,然后将搜索结果嵌入到邮件中。在简单的搜索命令流中,初始调用消息包括用户提交的搜索字符串。您可以使用卡片列表和卡片预览进行回复。Teams客户端为用户呈现卡片预览列表。当用户从列表中选择一张卡时,全尺寸卡将插入到撰写消息区域。
卡片是从撰写消息区域或命令框触发的,但不是从消息触发的。它们不能从消息中触发。下图显示了消息扩展名搜索命令对话框:
Note
For more information on cards, see what are cards.
链接展开
注:
链接展开仅支持基于机器人的消息扩展。
当在撰写消息区域粘贴URL时,将调用web服务。此功能称为链接展开。当包含特定域的URL粘贴到撰写消息区域时,您可以订阅以接收调用消息。您的web服务可以将URL展开为详细的卡片,提供比标准网站预览卡片更多的信息。您可以添加按钮,允许用户在不离开Teams客户端的情况下立即采取行动。当链接粘贴到邮件扩展插件中时,以下图像显示了链接展开功能:
构建消息扩展
要构建消息扩展,如果您还没有,有两种方法:
- 使用API(基于API)构建消息扩展:
- 您可以轻松地从现有的API创建消息扩展。此方法需要OpenAPI描述(OAD)文档。
- 使用Bot Framework(基于Bot)构建消息扩展:如果你想要一对一的对话体验,你可以从Bot创建一个新的消息扩展。
下表可帮助您选择要开始使用的消息扩展名类型:
基于API的消息扩展
创建和维护更简单、更快。- 消息扩展使用API。
- 机器人逻辑不需要额外的代码或资源。
- 非常适合消息扩展只需要与web服务通信而不需要任何复杂逻辑或状态管理的场景。
- 流量被私有化,因为它们不依赖于Azure机器人基础设施。
- 支持搜索命令。
基于Bot的消息扩展
更灵活。- 消息扩展使用Bot框架。
- 可以使用机器人的全部功能。
- 非常适合消息扩展需要与多个服务通信、管理复杂的逻辑或用户交互或跨会话维护状态的场景。
- 支持动作命令、搜索命令和链接展开。
Select an option to start building a message extension:
Code sample
Sample name | Description | .NET | Node.js | Python | Manifest |
---|---|---|---|---|---|
Message extension with action-based commands | This sample shows how to define action commands, create dialog, and respond to dialog submit action. | View | View | View | View |
Message extension with search-based commands | This sample shows how to build a Search-based Message Extension. It searches NuGet packages and displays the results in search based messaging extension. | View | View | View | View |
Message extension action preview | This sample shows how to use action preview in Messaging Extensions using Bot Framework v4. | View | View | NA | View |
Message extension action for task scheduling | This sample shows how to schedule a task from message extension action command and get a reminder card at a scheduled date and time. | View | View | NA | View |
Northwind inventory message extension | This sample demonstrates how to use a Teams message extension as a plugin in Microsoft Copilot for Microsoft 365. | NA | View | NA | NA |
- 登录 发表评论
- 3 次浏览
Tags
最新内容
- 7 hours ago
- 7 hours ago
- 9 hours 8 minutes ago
- 9 hours ago
- 9 hours ago
- 6 days 8 hours ago
- 1 week ago
- 1 week 2 days ago
- 1 week 2 days ago
- 1 week 2 days ago