In this section, we present how to connect Microsoft Teams to MindsDB.

Microsoft Teams is the ultimate messaging app for your organization—a workspace for real-time collaboration and communication, meetings, file and app sharing, and even the occasional emoji! All in one place, all in the open, all accessible to everyone.

The Microsoft Teams handler allows you to read and send messages to a Microsoft Teams channel or chat. It also allows you to create a chatbot that will respond to messages.


Before proceeding, ensure the following prerequisites are met:

  1. Install MindsDB locally via Docker or use MindsDB Cloud.
  2. To connect Microsoft Teams to MindsDB, install the required dependencies following this instruction.
  3. Install or ensure access to Microsoft Teams.


This handler was implemented using msal for authentication and Requests to submit requests to the Microsoft Graph API.

The Microsoft Teams handler is initialized with the following parameters:

  • client_id: The client ID of the registered Microsoft Entra ID application.
  • client_secret: The client secret of the registered Microsoft Entra ID application.
  • tenant_id: The tenant ID of the registered Microsoft Entra ID application.

Microsoft Entra ID was previously known as Azure Active Directory (Azure AD).

The parameters given above can be obtained by registering an application in Entra ID by following these steps,

  1. Go to the Azure Portal and sign in with your Microsoft account.
  2. Locate the Microsoft Entra ID service and click on it.
  3. Click on App registrations and then click on New registration.
  4. Enter a name for your application and select the Accounts in this organizational directory only option for the Supported account types field.
  5. Keep the Redirect URI field empty and click on Register.
  6. Copy the Application (client) ID and record it as the client_id parameter, and copy the Directory (tenant) ID and record it as the tenant_id parameter.
  7. Click on Certificates & secrets and then click on New client secret.
  8. Enter a description for your client secret and select an expiration period.
  9. Click on Add and copy the generated client secret and record it as the client_secret parameter.
  10. Click on Authentication and then click on Add a platform.
  11. Select Web and enter the following URLs in the Redirect URIs field:
    • http://localhost:47334/verify-auth (for local development)

You can find more information about creating app registrations here.

To connect to Microsoft Teams using MindsDB, the following CREATE DATABASE statement can be used:

CREATE DATABASE teams_datasource
WITH ENGINE = 'teams',
  "client_id": "your-client-id",
  "client_secret": "your-client-secret",
  "tenant_id": "your-tenant-id"

When the above is statement is executed with the given parameters, the handler will open a browser window and prompt you to sign in with your Microsoft account.

The handler will then act (via the app registration) as the signed in user and will submit requests to the Microsoft Graph API. This is done using the concept of delegated permissions.


Now, you can post a message to a chat:

INSERT INTO teams_datasource.chat_messages (chatId, body_content)
('your-chat-id', 'Hello from MindsDB!');

You can also do the same for channels:

SELECT * FROM teams_datasource.channels
INSERT INTO teams_datasource.channel_messages (channelIdentity_teamId, channelIdentity_channelId, body_content)
('your-team-id', 'your-channel-id', 'Hello from MindsDB!');

Supported Tables

The following tables are supported by the Microsoft Teams handler:

  • chats: chats that the signed in user is a member of.
  • chat_messages: messages sent to the signed in user’s chats.
  • channels: channels that the signed in user is a member of.
  • channel_messages: messages sent to the signed in user’s channels.


While the Microsoft Teams handler allows you to read/send messages to a chat or channel as shown above, it is also possible to create a chat bot that will listen to messages sent to a chat or channel and respond to them.

Step 1: Create a Microsoft Teams Data Source

As shown above, create a database with the new teams engine by passing in the required parameters:

CREATE DATABASE teams_datasource
WITH ENGINE = 'teams',
  "client_id": "your-client-id",
  "client_secret": "your-client-secret",
  "tenant_id": "your-tenant-id"

The chat bot will assume the identity of the user who signed in with their Microsoft account when the database was created.

Step 2: Create an Agent

An agent is created by combining a conversational model, like LlamaIndex, with a set of Skills.

Here, we will create an agent without any skills, however, it is possilbe to create agents with skills such as the ability to answer questions from a knowledge base.

Step 2.1: Create a Conversational Model

Create a conversational model using either the LangChain or LlamaIndex integrations. Given below is an example of a conversational model created using the LlamaIndex integration:

CREATE ML_ENGINE llama_index_engine
FROM llama_index
USING openai_api_key='your-openai-api-key';
CREATE MODEL llama_index_convo_model
PREDICT answer
  engine = 'llama_index_engine',
  mode = 'conversational',
  prompt = 'answer users questions as a helpful assistant',
  user_column = 'question',
  assistant_column = 'answer';

Step 2.2: Create an Agent using the Conversational Model

Let’s create an agent using the conversational model created above:

CREATE AGENT convo_agent
    model = 'llama_index_convo_model',

Step 3: Create a Chatbot

Finally, create a chatbot using the agent and the Microsoft Teams data source created above:

CREATE CHATBOT teams_chatbot
    database = 'teams_datasource',
    agent = 'convo_agent',
    enable_dms = true

The enable_dms parameter is optional and is the initially supported mode of talking to a chatbot. A chatbot responds to direct messages.