为 Microsoft 团队构建应用程序Building an app for Microsoft Teams

备注

希望快速入门吗?Looking to get started quickly? 您可以使用Microsoft 团队工具包和 Visual Studio Code生成团队应用程序。You can build Teams apps with the Microsoft Teams Toolkit and Visual Studio Code.

创建和分发在 Microsoft 团队平台上构建的应用程序涉及到确定要生成的内容、生成 web 服务、创建应用程序包以及将该包分发给目标最终用户。Creating and distributing an app built on the Microsoft Teams Platform involves deciding what to build, building your web services, creating an app package, and distributing that package to your target end users. 由组织的管理员决定谁可以访问和安装您的应用程序,并将由您的用户在任何特定的上下文中安装您的应用程序。It will be up to an organization's administrators to decide who can access and install your app, and it will be up to your users to install your app in any particular context.

设计出色的应用程序Design a great app

为 Microsoft 团队创建成功应用程序的最重要步骤是选择适当的组合扩展性点和要利用的 UI 元素。The most important step in creating a successful app for Microsoft Teams is choosing the right combination extensibility points and UI elements to take advantage of. 有时,这是一种非常简单的决策,但对于更复杂的应用,您应花大量时间来了解您尝试使用应用程序解决的问题,以及在用户可以与 Microsoft 团队客户端中的应用程序交互的各种方式之间映射您的解决方案。Sometimes, this is a fairly easy decision, but for more complex apps you should spend a good deal of time understanding the problem you're trying to solve with your app and mapping your solution across the various ways users can interact with your app in the Microsoft Teams client. 不要低估上下文和范围的重要性!Don't underestimate the importance of context and scope! 在一对一聊天中运行良好的会话自动程序在群聊天或频道对话过程中可能不起作用。A conversational bot that works very well in a one-to-one chat may not work at all as part of a group chat or channel conversation.

  1. 首先,了解团队客户端扩展性点和可用于您的应用程序的 UI 元素。First, understand the Teams client extensibility points and UI elements available for your app.

  2. 接下来,请务必了解你的用例Next, make sure you understand your use cases.

  3. 最后,将用例映射到团队平台功能Finally, map your use cases to Teams platform features.

在决定了应用程序将利用哪些扩展性点和功能后,您将需要考虑这些交互中的每一项。Once you've decided what extensibility points and features your app will take advantage of, you'll want to think through each of those interactions. 根据应用程序的设计,您可能需要查看以下内容:Depending on the design of your app, you might want to look at:

准备环境Prepare your environment

您需要确保您有一个可在其中上传和测试团队应用程序的环境。You need to make sure you have an environment where you can upload and test your Teams app. 如果您还没有已启用团队的 O365 订阅,并且可以将应用上传到它,则可以注册 O365 开发人员计划,从而为开发目的提供访问免费 Office 365 订阅的功能。If you don't already have an O365 subscription with Teams enabled and the ability to upload apps to it you can sign up for the O365 developer program which will give you access to a free Office 365 subscription for development purposes.

有关详细信息,请参阅准备您的 O365 环境See prepare your O365 environment for additional information.

运行和测试应用Build and test your app

生成和测试适用于 Microsoft 团队的应用程序与生成任何其他 web 应用程序没有什么不同。Building and testing your app for Microsoft Teams isn't much different than building any other web app. 主要区别在于,需要在应用程序包中使用应用程序清单将团队客户端连接到 web 服务。The primary difference is the need to use your app manifest in your app package to connect the Teams client to your web services. 每当您对应用程序清单进行更改时,您都需要重新上载应用程序包,并通过重新安装在团队中更新您的应用程序。Any time you make a change to your app manifest, you'll need to re-upload your app package, and update your app in Teams by re-installing it. 但是,在对 web 服务进行更改时,不需要在团队客户端中重新安装您的应用程序。Changes to your web service however, do not require you to re-install your app in the Teams client.

最初创建您的应用程序时,您将定期更新 web 服务和应用程序包,通常是在团队客户端中重新上载并多次安装应用程序(尤其是在初始安装应用程序期间)。When you're initially creating your app you'll regularly be updating both your web services and your app package, typically re-uploading and install the app in the Teams client multiple times (particularly during the initial setup of your app). 但是,由于你构建的稳定,更改应用清单的需求将会降低,并且你将主要对 web 服务进行更改。However, as what you're building stabilizes the need to alter your app manifest will decrease and you'll primarily be making changes to your web service.

生成 web 服务Build your web services

一旦您决定了用户如何与您的应用程序进行交互,它就会生成 web 服务以对其进行电源的时间。Once you've decided how users are going to interact with your app, its time to build the web services to power it. 根据您创建的内容,团队将提供各种 Sdk、模板、代码示例和生成器来帮助您入门,其中包括:Depending on what you're creating, Teams provides various SDKs, templates, code samples, and generators to help you get started, including:

请记住,您需要以一种方式承载 web 服务,从而使它们以公共方式通过 internet 访问(通常在云服务提供商(如 Azure)中),并通过 HTTPS 提供您的内容。Remember, you'll need to host your web services in a way that makes them publicly accessible over the internet (typically in a cloud service provider like Azure), and serve up your content over HTTPS.

创建应用包Create your app package

您还需要创建一个可在 Microsoft 团队中分发和安装的应用程序包。You'll also need to create an app package that can be distributed and installed in Microsoft Teams. 应用程序包包含两个图标和一个 JSON 清单文件,其中描述了您的应用程序的元数据、您的应用程序正在使用的扩展点以及指向这些扩展点的服务的指针。The app package contains two icons and a JSON manifest file describing the metadata for your app, the extension points your app is using, and pointers to the services powering those extension points.

在创建应用程序包时,可以选择手动创建,也可以使用应用程序工作室(即团队内的应用程序)来帮助您创建团队应用程序(我们知道,非常多元)。When creating your app package you can choose to create it manually, or use App Studio which is an app inside Teams that helps you make Teams apps (we know, very meta). 应用程序 Studio 将指导您创建您的应用程序清单,并可帮助您在 Bot 框架中注册你的 bot。App Studio will guide you through creating your app manifest, and can help you register your bot with the Bot Framework. 它还包含卡片设计器,可帮助您以可视化方式创建卡片和卡片操作,并将示例发送给团队中的自己。It also contains a card designer to help you visually create cards and card actions, and send examples to yourself in Teams.

分发应用程序Distributing your app

您有三个选项可用于分发 Microsoft 团队应用程序,具体取决于您的目标访问群体。You have three options for distributing your Microsoft Teams app, depending on your target audience.

  • 直接共享您的应用程序包。Share your app package directly. 您可以选择直接向用户共享您的应用程序包。You can choose to share your app package directly with users. 如果您的应用程序面向受限制的访问群体(只是几个团队或个人),以及在开发和测试应用过程中,这一点尤其有用。This is particularly useful if your app is directed towards a limited audience (just a couple of teams or individuals), and during development and testing of your app.

  • 将应用程序发布到组织应用程序目录。Publish your app to your organizational app catalog. 如果您的应用程序适用于特定组织(或者,如果您已经自定义了您的应用程序以满足组织的特定需求),租户管理员可将您的应用程序上传到组织的应用程序目录。If your app is applicable to a specific organization (or if you've customized your app to meet an organization's specific needs), a tenant administrator can upload your app to the organization's app catalog. 这使组织中的任何人都可以安装(但不会自动安装它)您的应用程序。This makes your app available for anyone in the organization to install (but does not automatically install it).

  • 将应用程序发布到公用应用商店。Publish your app to the public App Store. 如果您的应用程序适用于所有团队用户,则可以在公共应用商店中提交您的应用程序以供发布。If your app is intended for all Teams users everywhere, you can submit your app for publication in the public app store. 您需要执行严格的审阅过程,因此请确保您已将您的 t 与 t 相带点。You'll need to go through a rigorous review process, so make sure you've dotted your i's and crossed your t's.

分发您的应用程序时,您需要考虑的不仅仅是您所需的访问群体,而是要与之共享您的应用程序的组织中的 IT 策略。When distributing your app you need to take into consideration not just your desired audience, but the IT policies in place in the organization you want to share your app with. 每个组织都可以完全控制如何确定要将哪些应用程序上载到其组织应用程序目录,以及哪些应用程序可从应用商店进行安装。Each organization has complete control over determining which apps will be uploaded to their organizational app catalog, and which apps are available to install from the app store.

您创建的应用程序与您的用户安装的应用程序The app you create versus the app your users install

您的应用程序可以利用团队客户端中的多个扩展性点,并在各种范围内工作。Your app may take advantage of multiple extensibility points in the Teams client, and work in a variety of scopes. 分发给用户的应用程序包将全部定义为单个实体。Your app package you distribute to users will define all of these as a single entity. 但是,由于 Microsoft 团队中的所有应用安装都是特定于上下文的,因此并非始终为所有用户安装整个应用程序。However, because all app installations in Microsoft Teams are context-specific, the entirety of your app may not always be installed for all users.

例如,假设您的应用程序包含一个在个人对话和团队对话中工作的对话机器人,以及一个个人选项卡和一个频道选项卡。安装应用程序后,它将安装在特定的上下文中-如果用户在团队中安装了应用程序,则无需安装应用程序的个人部分。For example, imagine your app contains a conversational bot that works in both a personal and team conversations, as well as both a personal tab and a channel tab. When your app is installed, it will be installed in a specific context - if a user installs the app in a team, they have not necessarily installed the personal portion of your app. 首先,这可能有点令人困惑,只需记住永远不要指望应用程序的所有部分都将在任何给定的上下文中安装和配置。This can be a bit confusing at first, just remember to never expect that all portions of your app will be installed and configure in any given context.

入门教程Getting started tutorials