Skip to content
Petkir Blog
XLinkedinBluesky

Unlocking Microsoft Teams Extensibility with Messaging Extensions - Search-based Extensions

Code, Teams6 min read

Microsoft Teams is continuously evolving to provide users with new ways to collaborate and streamline their work processes. One of the most powerful features for extending Teams' functionality is the ability to build Messaging Extensions. These extensions allow you to interact with external services and systems directly within the Teams interface. Among the different types of messaging extensions, Search-based Extensions are particularly useful for developers who want to enhance the search capabilities within Teams, enabling users to find relevant information, content, or services without leaving the chat interface.

In this blog post, we’ll take a deep dive into Search-based Extensions for Microsoft Teams, explore what they are, how to build them, and discuss some common use cases for developers.

What are Search-based Extensions?

Search-based Extensions are a type of Messaging Extension that allows users to search for and retrieve external data or content directly from within the Microsoft Teams chat interface. Instead of performing a traditional search within Teams or external services separately, users can enter a keyword or phrase within the message compose area, and the extension will return relevant results from an external system, such as a database, a document repository, or a third-party API.

When a user types a query into the message compose area, the search-based extension calls an external service and displays the results in a list or interactive format within the chat interface. This integration provides a seamless experience where users can access important content, share information, or interact with business systems without leaving Teams.

Key Components of a Search-based Extension

  1. Search Query: The search query entered by the user in the chat compose box. This query is passed to the backend service to retrieve relevant results.

  2. External Data Source: The search query is typically sent to an external service or database, such as a knowledge base, CRM system, or document management platform.

  3. Result Handling: Once the results are fetched from the external service, they are displayed within Teams. The results can be shown as a list of items or interactive elements that allow users to select and take actions on the items.

  4. Authentication: If the search involves accessing sensitive or restricted data, users may need to authenticate or authorize the search action using OAuth or other authentication mechanisms.

Requirements for Building Search-based Extensions

To develop a Search-based Messaging Extension, developers need the following:

  1. Teams Toolkit: The Teams Toolkit simplifies the process of building and deploying Teams apps, including Messaging Extensions. It provides templates and tools that streamline the creation of extensions and integration with external data sources.

  2. Microsoft 365 Developer Account: A Microsoft 365 Developer account is required to register and manage your app in Azure Active Directory and Microsoft Teams.

  3. Azure App Registration: To interact with Microsoft Teams and integrate your extension with external services, you’ll need to register your app in Azure AD to manage authentication and authorization.

  4. Backend API: A backend API (such as RESTful API or GraphQL) to handle the search query and retrieve results from external data sources. The API can connect to various systems, including CRM systems, knowledge bases, document management platforms, and more.

  5. App Manifest: The manifest file defines the configuration for your app, including the search-based extension, command names, and the actions it performs. This file must be updated to support the search functionality.

Building a Search-based Extension

Here’s how to build a basic search-based extension for Microsoft Teams:

Step 1: Set up the Development Environment

  • Install Teams Toolkit in Visual Studio Code.
  • Create a new Messaging Extension project using the toolkit, selecting the search-based extension template.
  • Register your app in the Azure Portal and configure authentication (if necessary).

Step 2: Define the Search Extension in the App Manifest

In the manifest.json file, define the search functionality. Here’s an example of how to specify a search-based extension:

{
"$schema": "https://developer.microsoft.com/json-schemas/teams/v1.15/MessagingExtension.schema.json",
"commands": [
{
"id": "searchExtension",
"title": "Search Knowledge Base",
"description": "Search articles in the knowledge base",
"type": "query",
"query": {
"command": "/search",
"parameters": [
{
"name": "query",
"type": "string",
"description": "Search term"
}
]
}
}
]
}

Step 3: Implement the Backend Service

The backend service will handle the search logic. For example, if you are searching a knowledge base, your backend might query a database or a third-party service. Here’s a basic Node.js implementation:

const express = require('express');
const app = express();
// Simulating a knowledge base search API
app.post('/search', (req, res) => {
const query = req.body.query;
const results = [
{ title: 'How to use Teams', description: 'Learn how to get started with Microsoft Teams.' },
{ title: 'Best practices for collaboration', description: 'Tips for successful team collaboration.' }
];
const filteredResults = results.filter(result => result.title.toLowerCase().includes(query.toLowerCase()));
res.json({
type: 'message',
text: `Found ${filteredResults.length} result(s) for "${query}":`,
attachments: filteredResults.map(result => ({
contentType: 'application/vnd.microsoft.card.hero',
content: {
title: result.title,
text: result.description
}
}))
});
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});

Step 4: Handle Authentication (If Necessary)

If your search extension accesses protected data, integrate OAuth 2.0 or other authentication mechanisms to ensure the security of the search query.

Step 5: Test and Deploy

Once your search extension is implemented, test it in Teams using the Teams Toolkit. Once you're satisfied with the functionality, deploy the app by uploading the manifest to the Teams App Store or distributing it within your organization.

Use Cases for Search-based Extensions

Search-based Messaging Extensions provide a rich set of use cases for developers looking to enhance Teams' functionality. Some of the most common use cases include:

  1. Knowledge Base Search: Allowing users to search for articles, FAQs, or documentation directly from within Teams to quickly find relevant information without leaving the chat interface.

  2. CRM Search: Enabling sales or customer service teams to search for customer data, contact information, or case history in a CRM system like Salesforce or Microsoft Dynamics 365.

  3. Document Search: Integrating with document management systems like SharePoint, OneDrive, or third-party file storage solutions to allow users to search for and retrieve files directly within Teams.

  4. Project Management Tools: Allowing users to search for tasks, milestones, or project updates in tools like Jira, Trello, or Asana, providing a streamlined way to manage tasks within Teams.

  5. Employee Directory: Allowing HR teams to search for employee information, roles, and contact details within the organization.

Conclusion

Search-based Messaging Extensions offer a powerful way to integrate external data sources with Microsoft Teams, allowing users to perform searches and retrieve relevant content without leaving the chat interface. These extensions provide a seamless and efficient way to enhance collaboration and improve productivity. Developers can use the Teams Toolkit and Microsoft Graph API to quickly build and deploy search-based extensions, creating robust, valuable tools that streamline workflows for users across different industries.