How to Integrate AI with Microsoft 365 and SharePoint
Your organisation runs on Microsoft 365. Documents live in SharePoint, communication happens in Teams, emails flow through Outlook, and data sits in Excel and Lists. How do you connect AI to all of this?
This is one of the most practical AI integration projects we see at Team 400. Nearly every Australian enterprise we work with uses Microsoft 365, and the platform's APIs make it one of the most accessible integration targets for custom AI solutions.
I'm Michael Ridland, founder of Team 400. Here's how we approach Microsoft 365 AI integration.
What Can AI Do with Microsoft 365?
Before getting into the technical details, here's what's possible.
Document intelligence across SharePoint. An AI assistant that can search, read, and answer questions about documents across your entire SharePoint environment. Not just keyword search - actual understanding of content.
Email triage and classification. AI that reads incoming emails, classifies them, extracts key information, and routes them to the right team or workflow.
Meeting intelligence. AI that processes Teams meeting transcripts to extract action items, decisions, and summaries.
Automated reporting. AI that pulls data from SharePoint Lists, Excel files, and other M365 data sources to generate regular reports or answer ad-hoc questions.
Document generation. AI that creates documents from templates using data from your M365 environment - contracts, proposals, reports.
Knowledge management. An AI-powered knowledge base built on your SharePoint document library, giving employees instant answers grounded in your organisation's actual documentation.
The Integration Architecture
Microsoft Graph API - Your Primary Integration Point
Microsoft Graph is the unified API for all of Microsoft 365. Everything you need to access lives here:
- SharePoint and OneDrive - Documents, lists, pages, sites
- Outlook - Emails, calendar, contacts
- Teams - Messages, channels, meetings, transcripts
- Excel - Workbooks, worksheets, tables
- Planner/To Do - Tasks and plans
- Azure AD (Entra ID) - Users, groups, permissions
The Graph API uses OAuth 2.0 authentication and returns JSON. It's well-documented and has SDKs for Python, .NET, JavaScript, and other languages.
Architecture Overview
Here's the typical architecture for an AI + M365 integration.
[User Interface]
↓ (Teams bot, web app, or Teams tab)
[AI Orchestration Layer]
↓
[LLM Service] [Microsoft Graph API]
(Azure OpenAI) (SharePoint, Outlook, Teams)
↓ ↓
[Vector Store] [M365 Data]
(Azure AI Search) (Documents, Emails, etc.)
The orchestration layer sits between the user and the AI/M365 services. It coordinates retrieval from Microsoft 365, feeds context to the LLM, and executes actions back through Graph API.
Authentication Patterns
Getting authentication right is the foundation. There are two main patterns.
Application permissions (daemon/service):
Your AI application authenticates as itself using a client ID and secret (or certificate). It can access data across the entire tenant without user interaction.
Use this for:
- Background processing (indexing SharePoint for a knowledge base)
- Scheduled tasks (daily email classification)
- System-to-system integration
from azure.identity import ClientSecretCredential
from msgraph import GraphServiceClient
credential = ClientSecretCredential(
tenant_id="your-tenant-id",
client_id="your-app-id",
client_secret="your-secret"
)
graph_client = GraphServiceClient(credential)
Important: Application permissions bypass user-level access controls. Your AI service can access everything in SharePoint. You must implement your own access filtering - more on this below.
Delegated permissions (on behalf of user):
Your AI application acts on behalf of the signed-in user. It can only access what that user can access.
Use this for:
- Interactive AI assistants (Teams bots, web apps)
- Any scenario where answers should respect user permissions
- User-facing search and Q&A
from azure.identity import OnBehalfOfCredential
credential = OnBehalfOfCredential(
tenant_id="your-tenant-id",
client_id="your-app-id",
client_secret="your-secret",
user_assertion=user_token # Token from the signed-in user
)
For most AI assistants, we use delegated permissions for user-facing interactions and application permissions for background indexing, with a security trimming layer to ensure answers respect access controls.
Integrating AI with SharePoint Documents
This is the most common integration pattern. Let's walk through it.
Step 1 - Index SharePoint Content
Build an indexing pipeline that reads documents from SharePoint and prepares them for AI retrieval.
Discovering documents:
# List all sites
sites = await graph_client.sites.get()
# List document libraries in a site
drives = await graph_client.sites.by_site_id(site_id).drives.get()
# List files in a library
items = await graph_client.drives.by_drive_id(drive_id).items.get()
Downloading and extracting text:
# Download file content
content = await graph_client.drives.by_drive_id(drive_id) \
.items.by_drive_item_id(item_id).content.get()
# For PDFs: Use Azure AI Document Intelligence for extraction
# For DOCX: Use python-docx
# For PPTX: Use python-pptx
Handling permissions:
For each document, capture the permission information so you can filter at query time.
# Get permissions for a file
permissions = await graph_client.drives.by_drive_id(drive_id) \
.items.by_drive_item_id(item_id).permissions.get()
Store the allowed users/groups with each document chunk in your vector store.
Incremental updates:
Use the SharePoint delta API to track changes since your last sync, rather than re-indexing everything each time.
# Get changes since last sync
delta = await graph_client.drives.by_drive_id(drive_id) \
.items.delta().get()
This keeps your index current without expensive full re-crawls.
Step 2 - Build the Vector Index
Once you've extracted text from SharePoint documents, chunk it and store it in Azure AI Search.
# Chunk the document
chunks = chunk_document(
text=document_text,
chunk_size=1000,
overlap=200
)
# Embed each chunk
embeddings = azure_openai_client.embeddings.create(
model="text-embedding-deployment",
input=[chunk.text for chunk in chunks]
)
# Index in Azure AI Search
for chunk, embedding in zip(chunks, embeddings.data):
search_client.upload_documents([{
"id": f"{document_id}_{chunk.index}",
"content": chunk.text,
"embedding": embedding.embedding,
"document_title": document_title,
"site_name": site_name,
"last_modified": last_modified,
"allowed_groups": permission_groups,
"source_url": document_url
}])
Step 3 - Query with Security Trimming
When a user asks a question, search only documents they have access to.
# Get user's group memberships
user_groups = await graph_client.me.member_of.get()
group_ids = [g.id for g in user_groups.value]
# Build security filter
security_filter = " or ".join(
[f"allowed_groups/any(g: g eq '{gid}')" for gid in group_ids]
)
# Search with filter
results = search_client.search(
search_text=question,
vector_queries=[vector_query],
filter=security_filter,
top=10
)
This ensures users only get answers from documents they're authorised to see.
Integrating AI with Outlook Email
Email Classification and Routing
Build an AI pipeline that monitors shared mailboxes and classifies incoming emails.
# Monitor a shared mailbox for new emails
messages = await graph_client.users.by_user_id(mailbox_id) \
.mail_folders.by_mail_folder_id("inbox") \
.messages.filter("isRead eq false").get()
for message in messages.value:
# Classify using Azure OpenAI
classification = await classify_email(
subject=message.subject,
body=message.body.content,
sender=message.from_address
)
# Route based on classification
if classification.category == "support":
await forward_to_team(message, "[email protected]")
elif classification.category == "billing":
await forward_to_team(message, "[email protected]")
Email Summarisation
For executives or busy teams, AI can summarise email threads.
# Get a conversation thread
messages = await graph_client.me.messages \
.filter(f"conversationId eq '{conversation_id}'") \
.order_by("receivedDateTime").get()
# Combine into a thread
thread_text = "\n\n".join([
f"From: {m.from_address.name} ({m.received_datetime})\n{m.body.content}"
for m in messages.value
])
# Summarise with Azure OpenAI
summary = await azure_openai_client.chat.completions.create(
model="gpt-4o-deployment",
messages=[
{"role": "system", "content": "Summarise this email thread. List key points, decisions, and action items."},
{"role": "user", "content": thread_text}
]
)
Integrating AI with Teams
Teams Bot
The most natural way to expose AI to users in a Microsoft 365 environment is through a Teams bot.
Bot Framework integration:
Use Microsoft Bot Framework to build a Teams bot that connects to your AI backend.
User message in Teams → Bot Framework → Your API → AI Orchestration → Response
The Bot Framework handles:
- Authentication with Teams
- Message formatting (adaptive cards, rich text)
- Conversation management
- Proactive messaging
Teams AI Library:
Microsoft's Teams AI Library (built on Bot Framework) simplifies building AI-powered bots for Teams. It handles prompt management, conversation history, and tool calling.
Meeting Intelligence
Process Teams meeting transcripts to extract value.
# Get meeting transcript
transcript = await graph_client.me.online_meetings \
.by_online_meeting_id(meeting_id).transcripts.get()
# Process with AI
analysis = await azure_openai_client.chat.completions.create(
model="gpt-4o-deployment",
messages=[
{"role": "system", "content": """
Analyse this meeting transcript and extract:
1. Key decisions made
2. Action items (with owner if mentioned)
3. Open questions
4. Brief summary (3-5 sentences)
"""},
{"role": "user", "content": transcript_text}
]
)
Microsoft 365 Copilot vs Custom AI Integration
You might be wondering: "Should we just use Microsoft 365 Copilot instead of building custom integrations?"
Microsoft 365 Copilot is good for:
- General-purpose productivity (summarise this document, draft this email)
- Individual user productivity
- Out-of-the-box M365 integration
- Organisations that want AI without custom development
Custom AI integration is better for:
- Industry-specific workflows (insurance claims, compliance checks, legal review)
- Multi-system integration (combining M365 data with ERP, CRM, databases)
- Custom business logic and rules
- Controlled, tested outputs for specific use cases
- Cost management (Copilot licences at $30/user/month can be expensive at scale)
Many of our clients use Copilot for general productivity and custom AI for their specific business processes. They're complementary, not competing.
Security Considerations for Australian Organisations
Data residency: Ensure your Azure OpenAI service and AI Search are deployed in Australian regions. M365 data already resides in Australian datacentres for most Australian tenants.
Permissions: Use the principle of least privilege for your AI application's Graph API permissions. Only request the scopes you need.
Data handling: When your AI processes M365 data, that data passes through your AI pipeline. Ensure your pipeline maintains the same security posture as M365 itself - encrypted in transit, encrypted at rest, access logged.
Consent: Depending on the permissions required, you may need admin consent for your AI application to access M365 data. Plan for this in your project timeline.
Audit logging: Log all AI interactions with M365 data. This is both a security requirement and useful for debugging and improvement.
Implementation Timeline
For a typical M365 AI integration project:
Weeks 1-2: Architecture design, Azure setup, Graph API permissions and authentication.
Weeks 3-4: SharePoint indexing pipeline, vector store setup, basic RAG query pipeline.
Weeks 5-6: User interface (Teams bot or web app), security trimming, testing.
Weeks 7-8: Email or Teams integration (if in scope), monitoring, go-live.
Ongoing: Index maintenance, model tuning, expanding to new document sources.
Getting Started
The best starting point is usually a SharePoint knowledge base - indexing your most-used document libraries and building a Q&A interface. This delivers immediate value and establishes the integration patterns you'll use for more advanced scenarios.
If you're looking to integrate AI with your Microsoft 365 environment, talk to our team. We specialise in building AI solutions on the Microsoft stack for Australian organisations. Explore our Azure AI consulting services and AI development capabilities to learn more about how we work.