Microsoft Teams AI Bot: Enterprise Setup Guide
Build an AI assistant for Microsoft Teams with Bot Framework. SSO, compliance, and admin controls for enterprise.
Molted Team
Molted.cloud
Microsoft Teams dominates enterprise communication. Adding an AI assistant means your team gets intelligent help without leaving the Microsoft ecosystem. This guide covers building a Teams AI bot with the Bot Framework, handling enterprise requirements like SSO and compliance.
Why Teams for enterprise AI?
- Already deployed - Most enterprises use Teams
- SSO integration - Users authenticate with existing credentials
- Compliance - Meets enterprise security requirements
- Deep Microsoft integration - Connect to SharePoint, OneDrive, Outlook
- Admin controls - IT can manage the bot centrally
Architecture
Teams bots use the Microsoft Bot Framework:
- User sends message in Teams
- Teams routes to your bot endpoint
- Bot processes with AI and responds
- Response appears in Teams
Unlike Telegram or Discord, Teams requires HTTPS endpoints and Azure AD registration.
Prerequisites
- Microsoft 365 tenant with Teams
- Azure subscription (for Bot Registration)
- Admin consent to install custom apps
- Node.js 18+
Create Azure Bot Registration
- Go to Azure Portal
- Create a new "Azure Bot" resource
- Choose "Multi Tenant" for app type
- Note the App ID and create a client secret
- In Channels, add Microsoft Teams
Project setup
mkdir teams-ai-bot
cd teams-ai-bot
npm init -y
npm install botbuilder @anthropic-ai/sdk restify dotenvCreate .env:
MICROSOFT_APP_ID=your-app-id
MICROSOFT_APP_PASSWORD=your-client-secret
ANTHROPIC_API_KEY=your-anthropic-key
PORT=3978Basic Teams AI bot
require('dotenv').config();
const restify = require('restify');
const {
CloudAdapter,
ConfigurationServiceClientCredentialFactory,
createBotFrameworkAuthenticationFromConfiguration,
ActivityHandler,
TurnContext,
} = require('botbuilder');
const Anthropic = require('@anthropic-ai/sdk');
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
// Conversation storage
const conversations = new Map();
// Bot handler
class AIBot extends ActivityHandler {
constructor() {
super();
this.onMessage(async (context, next) => {
const userId = context.activity.from.id;
const text = context.activity.text?.trim();
if (!text) {
await next();
return;
}
// Get or create conversation
if (!conversations.has(userId)) {
conversations.set(userId, []);
}
const history = conversations.get(userId);
history.push({ role: 'user', content: text });
if (history.length > 20) {
history.splice(0, history.length - 20);
}
try {
// Show typing indicator
await context.sendActivity({ type: 'typing' });
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
system: `You are a helpful AI assistant in Microsoft Teams.
Keep responses professional and concise.
You can use markdown formatting.`,
messages: history,
});
const reply = response.content[0].text;
history.push({ role: 'assistant', content: reply });
await context.sendActivity(reply);
} catch (error) {
console.error('Error:', error);
await context.sendActivity('Sorry, I encountered an error. Please try again.');
}
await next();
});
this.onMembersAdded(async (context, next) => {
for (const member of context.activity.membersAdded) {
if (member.id !== context.activity.recipient.id) {
await context.sendActivity('Hello! I am an AI assistant. How can I help you today?');
}
}
await next();
});
}
}
// Create adapter
const credentialsFactory = new ConfigurationServiceClientCredentialFactory({
MicrosoftAppId: process.env.MICROSOFT_APP_ID,
MicrosoftAppPassword: process.env.MICROSOFT_APP_PASSWORD,
MicrosoftAppType: 'MultiTenant',
});
const botFrameworkAuthentication = createBotFrameworkAuthenticationFromConfiguration(null, credentialsFactory);
const adapter = new CloudAdapter(botFrameworkAuthentication);
// Error handler
adapter.onTurnError = async (context, error) => {
console.error('Bot error:', error);
await context.sendActivity('Sorry, something went wrong.');
};
const bot = new AIBot();
// Create server
const server = restify.createServer();
server.use(restify.plugins.bodyParser());
server.post('/api/messages', async (req, res) => {
await adapter.process(req, res, (context) => bot.run(context));
});
server.listen(process.env.PORT, () => {
console.log(`Bot listening on port ${process.env.PORT}`);
});Enterprise Teams AI
OpenClaw supports Teams with SSO and admin controls. Plugin install.
Start free trialCreate Teams app manifest
Create manifest.json:
{
"$schema": "https://developer.microsoft.com/json-schemas/teams/v1.16/MicrosoftTeams.schema.json",
"manifestVersion": "1.16",
"version": "1.0.0",
"id": "{{MICROSOFT_APP_ID}}",
"packageName": "com.yourcompany.aiteamsbot",
"developer": {
"name": "Your Company",
"websiteUrl": "https://yourcompany.com",
"privacyUrl": "https://yourcompany.com/privacy",
"termsOfUseUrl": "https://yourcompany.com/terms"
},
"name": {
"short": "AI Assistant",
"full": "AI Assistant for Teams"
},
"description": {
"short": "AI-powered assistant",
"full": "An intelligent assistant powered by Claude/GPT that helps with questions, content, and tasks."
},
"icons": {
"outline": "outline.png",
"color": "color.png"
},
"accentColor": "#7C3AED",
"bots": [
{
"botId": "{{MICROSOFT_APP_ID}}",
"scopes": ["personal", "team", "groupchat"],
"supportsFiles": false,
"isNotificationOnly": false,
"commandLists": [
{
"scopes": ["personal", "team", "groupchat"],
"commands": [
{
"title": "help",
"description": "Get help with using the assistant"
},
{
"title": "clear",
"description": "Clear conversation history"
}
]
}
]
}
],
"permissions": ["identity", "messageTeamMembers"],
"validDomains": ["your-bot-domain.com"]
}Deploy to Azure
Teams requires HTTPS. Options:
Azure App Service
# Install Azure CLI
az login
# Create resource group
az group create --name ai-bot-rg --location eastus
# Create App Service plan
az appservice plan create --name ai-bot-plan --resource-group ai-bot-rg --sku B1 --is-linux
# Create web app
az webapp create --name your-ai-bot --resource-group ai-bot-rg --plan ai-bot-plan --runtime "NODE:18-lts"
# Set environment variables
az webapp config appsettings set --name your-ai-bot --resource-group ai-bot-rg --settings \
MICROSOFT_APP_ID="your-app-id" \
MICROSOFT_APP_PASSWORD="your-secret" \
ANTHROPIC_API_KEY="your-key"
# Deploy
az webapp deployment source config-zip --name your-ai-bot --resource-group ai-bot-rg --src app.zipNgrok for development
npm install -g ngrok
ngrok http 3978Update your Bot Registration messaging endpoint to the ngrok URL.
Handle channel messages
this.onMessage(async (context, next) => {
const conversationType = context.activity.conversation.conversationType;
// In channels, only respond when mentioned
if (conversationType === 'channel') {
const mentionedBot = context.activity.entities?.some(
e => e.type === 'mention' && e.mentioned.id === context.activity.recipient.id
);
if (!mentionedBot) {
await next();
return;
}
// Remove @mention from text
const text = TurnContext.removeRecipientMention(context.activity);
// ... process with AI
}
// In personal/group chats, respond to all messages
// ... existing logic
});Adaptive Cards for rich responses
const { CardFactory } = require('botbuilder');
// Send formatted card
const card = CardFactory.adaptiveCard({
type: 'AdaptiveCard',
$schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
version: '1.5',
body: [
{
type: 'TextBlock',
text: 'AI Analysis Results',
weight: 'bolder',
size: 'large',
},
{
type: 'TextBlock',
text: aiResponse,
wrap: true,
},
],
actions: [
{
type: 'Action.Submit',
title: 'Ask follow-up',
data: { action: 'followup' },
},
],
});
await context.sendActivity({ attachments: [card] });Teams AI for enterprises
OpenClaw on Molted includes Teams plugin. Azure AD SSO, admin dashboard.
SSO authentication
For accessing user data or Microsoft Graph:
const { TeamsInfo } = require('botbuilder');
// Get user info
const member = await TeamsInfo.getMember(context, context.activity.from.id);
console.log(`User: ${member.name}, Email: ${member.email}`);
// For Graph API access, use MSAL
const { ConfidentialClientApplication } = require('@azure/msal-node');
const cca = new ConfidentialClientApplication({
auth: {
clientId: process.env.MICROSOFT_APP_ID,
clientSecret: process.env.MICROSOFT_APP_PASSWORD,
authority: 'https://login.microsoftonline.com/common',
},
});Compliance and security
- Data residency - Deploy in your region's Azure datacenter
- Audit logging - Log all AI interactions
- DLP integration - Check messages against DLP policies
- Retention - Respect Teams retention policies
OpenClaw for Teams
OpenClaw supports Microsoft Teams as a plugin:
- Pre-built Teams app manifest
- Azure AD SSO handled
- Admin consent flow
- Multi-tenant support
If your enterprise already uses OpenClaw, adding Teams is a configuration change.
Related guides
- Slack AI Chatbot - Alternative for Slack-first companies
- Discord AI Bot - For community/gaming servers
- Self-Hosted AI Guide - Compare all channel options
Enterprise AI assistant
OpenClaw for Microsoft Teams. SSO, compliance, admin controls built-in.
24-hour free trial · No credit card required · Cancel anytime