Microsoft Teams
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.
Prerequisites
Before proceeding, ensure the following prerequisites are met:
- Install MindsDB locally via Docker or use MindsDB Cloud.
- To connect Microsoft Teams to MindsDB, install the required dependencies following this instruction.
- Install or ensure access to Microsoft Teams.
Connection
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,
- Go to the Azure Portal and sign in with your Microsoft account.
- Locate the Microsoft Entra ID service and click on it.
- Click on App registrations and then click on New registration.
- Enter a name for your application and select the Accounts in this organizational directory only option for the Supported account types field.
- Keep the Redirect URI field empty and click on Register.
- Copy the Application (client) ID and record it as the
client_id
parameter, and copy the Directory (tenant) ID and record it as thetenant_id
parameter. - Click on Certificates & secrets and then click on New client secret.
- Enter a description for your client secret and select an expiration period.
- Click on Add and copy the generated client secret and record it as the
client_secret
parameter. - Click on Authentication and then click on Add a platform.
- Select Web and enter the following URLs in the Redirect URIs field:
https://cloud.mindsdb.com/verify-auth
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:
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.
Usage
Now, you can post a message to a chat:
You can also do the same for channels:
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.
Chatbot
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:
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:
Step 2.2: Create an Agent using the Conversational Model
Let’s create an agent using the conversational model created above:
Step 3: Create a Chatbot
Finally, create a chatbot using the agent and the Microsoft Teams data source created above:
The enable_dms
parameter is optional and is the initially supported mode of talking to a chatbot. A chatbot responds to direct messages.