What are message extensions?
When you build a message extension, you build an app for Microsoft Teams that is extended across Microsoft 365. Extending the app enables it to show up in Microsoft Outlook and in Microsoft 365 Copilot as a plugin.
An extended Microsoft Teams app is referred to as a Microsoft 365 app. A Microsoft 365 app uses a common app manifest, app packaging format, and developer and admin tools that you use to build an app for Microsoft Teams.
A message extension is an app feature, and they use a bot to communicate between the user and the external system.
Message extension capabilities
The capabilities of your message extension, how it appears in the user interface and the interactions that it can support, are defined in the app manifest.
Commands and message handlers are capabilities that a message extension can have. A message extension can use a combination of search and action commands, and message handlers.
There are two types of commands:
- Search commands, allow users to search external systems and insert the results of that search into a message in the form of a card.
- Action commands, allow users to act on messages in Teams, displaying a modal pop-up that can be used to collect or display information.
Message handlers enable your message extension to unfurl links when a URL with a particular domain is pasted into the compose message box.
Search commands
Search commands are used to search external systems and return results as rich formatted cards. When building a Microsoft 365 Copilot message extension plugin, you need an app that contains a message extension search command.
How does a message extension work?
Message extensions use a bot registered with Bot Framework to communicate between a client and the external system.
Bot Framework is a platform provided by Microsoft, which gives you the tools and services you need to build, test, deploy, and manage bots.
A message extension consists of a bot resource, a Microsoft Entra app registration, and code that uses the Bot Framework SDK to handle user interactions.
The following image shows a high-level structure of a message extension:
The bot service registers a bot with the Bot Framework, and it receives requests from the client when the user interacts with the message extension. It sends requests on to a web service, which contains the bot code. The web service uses the bot app registration credentials in Microsoft Entra to authenticate with the bot service. It gathers data from the external system and returns the data back to the bot service, which is passed back to the client.
Suppose a user initiates a search using a message extension. The following sequence diagram shows the interactions:
- User opens the message extension in the client and enters a search query.
- The client sends a request to the bot service via a channel endpoint, containing information about the user query.
- The bot service sends a request to a messaging endpoint exposed on the web service to handle the user query.
- The messaging endpoint receives the request and invokes the bot adapter. The bot adapter uses the bot Microsoft Entra app registration credentials to secure communication between the web service and the bot service.
- The bot adapter invokes the
OnTeamsMessageExtensionQuery
method on the bot activity handler class, which contains the logic to handle the incoming request. - The bot activity handler gets data from the external system. It creates a
MessageExtensionResult
, which contains the external data as rich formatted cards and creates aMessageExtensionResponse
, which contains theMessageExtensionResult
. - The bot adapter receives the response from the bot activity handler and creates an HTTP response.
- The messaging endpoint returns the response to the bot service.
- The bot service returns the response via the channel endpoint back to the message extension.
- The message extension renders the response in the client and displays the search results to the user.
Whether your message extension supports, search or action commands, or link unfurling, the same flow occurs. The bot service forwards a request to your web service that handles and responds to it.