Table of Contents

SOW Analyzer – Teams Bot Application

1. Purpose and Scope

This document provides full technical documentation for the SOW Analyzer Teams Bot application. It is intended for:

This document describes:

2. Functional Description

The SOW Analyzer is a document ingestion and analysis system exposed through Microsoft Teams.

Users interact with the system by uploading a PDF Statement of Work directly into a 1:1 Teams chat with a bot. The system:

  1. Validates the uploaded file
  2. Downloads the PDF securely
  3. Compares the document against known SOW templates
  4. Uses Azure OpenAI to generate a structured comparison
  5. Returns a summarized analysis to the user

At no point does the system store uploaded SOWs long-term.

3. High-Level System Flow

3.1 Request Lifecycle

User uploads PDF in Teams
 → Teams stores file in OneDrive/SharePoint
 → Teams sends attachment metadata to bot
 → Bot validates + downloads file
 → Bot POSTs PDF to analyzer endpoint
 → Analyzer extracts text and compares templates
 → Azure OpenAI produces structured diff
 → Result returned to Teams

3.2 Key Constraints

4. Tenant and Identity Model

4.1 Tenant Separation

Component Tenant
———-——–
Teams users CDW Tenant
Bot App Registration CDW Tenant
Azure Bot Service Azure Tenant
Web App (FastAPI) Azure Tenant
Azure OpenAI Azure Tenant
Blob Storage (templates) Azure Tenant

4.2 Bot Identity

The bot uses a single-tenant App Registration in the CDW Tenant.

This App Registration:

Required environment variables:

MicrosoftAppId
MicrosoftAppPassword
MicrosoftAppTenantId

The bot will reject any token whose AppId does not match `MicrosoftAppId`.

5. Teams Integration Details

5.1 Teams App Manifest

Key configuration:

"bots": [
  {
    "botId": "<MicrosoftAppId>",
    "scopes": ["personal"],
    "supportsFiles": true
  }
]

5.2 Supported Interaction Types

Interaction Supported
———————–
1:1 Chat YES
Group Chat NO
Channel NO
Adaptive Cards Optional
Message Extensions NO

5.3 File Upload Behavior

Teams uploads files to OneDrive or SharePoint, then sends metadata to the bot.

Expected attachment type:

application/vnd.microsoft.teams.file.download.info

The bot does not receive raw bytes directly.

6. Source Code Breakdown

6.1 app.py

Purpose

Acts as the FastAPI entry point for:

Endpoints

POST /api/messages

POST /analyze-sow

Important Behavior

6.2 teams_bot.py

Purpose

Implements all Teams bot logic.

Major Responsibilities

Adapter Initialization

BotFrameworkAdapterSettings(
  MicrosoftAppId,
  MicrosoftAppPassword,
  channel_auth_tenant=MicrosoftAppTenantId
)

This enforces:

on_turn() Execution Flow

1. Trust incoming service URL 2. Ignore non-message activities 3. Extract attachments 4. If no attachment → return silently 5. Extract filename + download URL 6. Enforce `.pdf` extension 7. Download file bytes 8. Validate PDF magic bytes (`%PDF`) 9. POST file to analyzer 10. Format and send result

PDF Enforcement

Two layers:

File Size Enforcement

Maximum allowed size enforced before analysis.

Storage Behavior

6.3 gpt_compare_multi.py

Purpose

Performs AI-driven comparison between uploaded SOW and known templates.

Responsibilities

Output Schema

{
  "chosen_template_title": "string",
  "summary": "string",
  "missing_sections": [],
  "extra_sections": [],
  "changed_clauses": {}
}

AI Safety

6.4 layout_client.py

Purpose

Provides access to stored SOW templates.

Storage

Important Notes

7. Data Handling and Retention

7.1 Uploaded PDFs

7.2 External Storage

7.3 Logging

8. Error Handling

User-Facing Errors

Condition Message
——————
Non-PDF upload “I can only analyze PDF files”
Download failure “I couldn’t download the file”
Analyzer failure “Analysis failed”

Internal Errors

9. Security Model

Authentication

Authorization

Data Protection

10. Operational Considerations

Deployment

Scaling

Monitoring

11. Known Limitations

12. Compliance Summary

The system:

13. Maintenance Notes

Future enhancements may include: