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
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.
Teams bots use the Microsoft Bot Framework:
Unlike Telegram or Discord, Teams requires HTTPS endpoints and Azure AD registration.
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=3978require('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.
Coming soonCreate 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"]
}Teams requires HTTPS. Options:
# 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.zipnpm install -g ngrok
ngrok http 3978Update your Bot Registration messaging endpoint to the ngrok URL.
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
});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.
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',
},
});OpenClaw supports Microsoft Teams as a plugin:
If your enterprise already uses OpenClaw, adding Teams is a configuration change.
OpenClaw for Microsoft Teams. SSO, compliance, admin controls built-in.
24-hour free trial · no credit card · cancel anytime
Run ChatGPT or Claude on WhatsApp with Baileys. Complete self-hosted setup guide with code examples and deployment options.
Build an AI-powered Telegram bot using grammY framework. Step-by-step tutorial with Claude and GPT integration.
Add an AI assistant to your Slack workspace with the Bolt SDK. Thread support, slash commands, and enterprise features.
ENCORE DEBOUT ?