bmc_hub/docs/WORKFLOW_SYSTEM_GUIDE.md
Christian 3fb43783a6 feat: Implement Email Workflow System with comprehensive documentation and migration scripts
- Added Email Workflow System with automated actions based on email classification.
- Created database schema with tables for workflows, executions, and actions.
- Developed API endpoints for CRUD operations on workflows and execution history.
- Included pre-configured workflows for invoice processing, time confirmation, and bankruptcy alerts.
- Introduced user guide and workflow system improvements for better usability.
- Implemented backup system for automated backup jobs and notifications.
- Established email activity log to track all actions and events related to emails.
2025-12-15 12:28:12 +01:00

7.4 KiB

Email Workflow System - Brugervejledning

Oversigt

Email Workflow System automatiserer behandling af emails baseret på AI classification. Workflows består af multiple steps der udføres sekventielt når en email matcher specifikke kriterier.

🚀 Quick Start

1. Åbn Workflow Manager

Klik på "Workflow Management" knappen i email UI'et

2. Opret Workflow

Tre måder:

  • Fra Template: Klik "Templates" og vælg en forudbygget workflow
  • Fra Scratch: Klik "Ny Workflow" og byg selv
  • Dupliker Eksisterende: Klik "Dupliker" på en eksisterende workflow

3. Konfigurer Workflow

Basis Information

  • Navn: Beskrivende navn (fx "Leverandør Faktura Processing")
  • Beskrivelse: Detaljeret formål
  • Classification Trigger: Hvilken email type der trigger workflow
  • Confidence Threshold: Minimum AI confidence (0.60-0.80 anbefalet)
  • Prioritet: Lavere tal = højere prioritet (10 = meget høj)

Workflow Steps

Tilføj actions i den rækkefølge de skal udføres:

  1. Klik "Tilføj Step"
  2. Vælg action type fra dropdown
  3. Konfigurer action parameters
  4. Brug drag-and-drop til at ændre rækkefølge

4. Test Workflow

Klik "Test Workflow" før du gemmer for at verificere funktionalitet

5. Gem og Aktiver

Klik "Gem" og sørg for at enable switch er tændt

📋 Tilgængelige Actions

Linking Actions

Link emails til eksisterende data:

{
  "action": "link_to_vendor",
  "params": { "match_by": "email" }
}
{
  "action": "link_to_customer",
  "params": {}
}

Data Extraction

Ekstraher data fra emails/attachments:

{
  "action": "extract_invoice_data",
  "params": {}
}
{
  "action": "extract_tracking_number",
  "params": { "pattern": "CC[0-9]{4}" }
}

Ticket/Case Creation

Opret tickets automatisk:

{
  "action": "create_ticket",
  "params": {
    "module": "support_cases",
    "priority": "normal"
  }
}
{
  "action": "create_time_entry",
  "params": {}
}

Notifications

Send notifikationer:

{
  "action": "send_slack_notification",
  "params": {
    "channel": "#alerts",
    "message": "🚨 Vigtig email modtaget"
  }
}

Processing Control

Styr email status:

{
  "action": "mark_as_processed",
  "params": {}
}
{
  "action": "flag_for_review",
  "params": { "reason": "needs_manual_review" }
}

🎯 Workflow Templates

Invoice Processing

Automatisk behandling af leverandør fakturaer:

  • Link til vendor
  • Ekstraher faktura data
  • Marker som processed

Classification: invoice
Confidence: 0.70
Priority: 50

Time Confirmation

Auto-link time confirmations til sager:

  • Ekstraher CC#### nummer
  • Opret ticket
  • Marker som processed

Classification: time_confirmation
Confidence: 0.60
Priority: 30

Spam Handler

Håndter spam emails:

  • Flag for review
  • Marker som processed

Classification: spam
Confidence: 0.80
Priority: 10

Freight Note

Behandl fragtbreve:

  • Ekstraher tracking nummer
  • Link til kunde
  • Marker som processed

Classification: freight_note
Confidence: 0.65
Priority: 40

Bankruptcy Alert

Alert ved konkurs emails:

  • Send Slack notifikation
  • Flag for review
  • Marker som processed

Classification: bankruptcy
Confidence: 0.75
Priority: 5

Low Confidence Review

Fang emails med lav confidence:

  • Flag for manuel review

Classification: general
Confidence: 0.30
Priority: 200

🔧 Advanced Features

Import/Export

Export: Download workflow som JSON fil (del med andre systemer)
Import: Upload JSON workflow fil

Duplicate

Kopier eksisterende workflow og tilpas - spar tid!

Test Mode

Test workflow på specifik email uden at gemme ændringer

JSON Editor

Switch til JSON view for direkte editing af workflow configuration

Drag & Drop

Omarranger workflow steps ved at trække i dem

📊 Monitoring

Execution History

Se alle workflow executions med:

  • Status (completed/failed)
  • Execution time
  • Steps completed
  • Error messages

Statistics

Per-workflow stats:

  • Total executions
  • Success rate
  • Failure count
  • Last executed

Debugging

Hvis workflow fejler:

  1. Tjek execution history for error message
  2. Verificer action parameters
  3. Test workflow på sample email
  4. Tjek confidence threshold

⚙️ Best Practices

Prioritering

  • 1-20: Kritiske workflows (bankruptcy alerts, spam)
  • 21-50: Almindelige workflows (invoices, time confirmations)
  • 51-100: Low-priority workflows
  • 100+: Catch-all workflows

Confidence Thresholds

  • 0.80+: Kun meget sikre matches
  • 0.70-0.80: Standard range (anbefalet)
  • 0.60-0.70: Acceptér mere usikkerhed
  • <0.60: Kun til catch-all workflows

Workflow Design

  1. Start med linking: Link til vendor/customer først
  2. Extract data: Hent data fra attachments
  3. Create tickets: Opret tickets hvis nødvendigt
  4. Notify: Send notifikationer
  5. Cleanup: Marker som processed til sidst

Testing

  • Test altid nye workflows på sample emails
  • Start med enabled = false og test grundigt
  • Monitor execution history i de første dage
  • Juster confidence threshold baseret på resultater

🚨 Common Issues

Workflow kører ikke

  • Tjek om workflow er enabled
  • Verificer classification trigger matcher email classification
  • Tjek confidence threshold (for høj?)
  • Se om højere prioritet workflow har stop_on_match = true

Action fejler

  • Tjek execution history for error message
  • Verificer action parameters er korrekte
  • Tjek om required data er tilgængelig (fx PDF attachment)
  • Test action individuelt

Duplikering af actions

  • Workflows med stop_on_match = true stopper andre workflows
  • Tjek om flere workflows matcher samme email
  • Brug prioritering til at styre rækkefølge

🔄 Migration fra Rules

Email Rules systemet er deprecated. Migrer til workflows:

  1. Identificer aktive rules
  2. Opret tilsvarende workflow (brug templates som udgangspunkt)
  3. Test workflow grundigt
  4. Disable original rule
  5. Monitor execution history

Se /docs/EMAIL_RULES_TO_WORKFLOWS_MIGRATION.md for detaljer.

📚 Yderligere Dokumentation

  • Actions Reference: Klik "Quick Guide" i Actions tab
  • Architecture: Se app/services/email_workflow_service.py
  • API Endpoints: /api/docs for komplet API reference
  • Migration Guide: /docs/EMAIL_RULES_TO_WORKFLOWS_MIGRATION.md

💡 Tips & Tricks

Template Modificering

Start med template og tilpas:

  1. Vælg template der ligner din use case
  2. Rediger navn og beskrivelse
  3. Tilføj/fjern steps efter behov
  4. Juster confidence og prioritet
  5. Test og gem

Multi-Step Workflows

Build komplekse workflows:

Step 1: Link to vendor
Step 2: Extract invoice data
Step 3: Create case if amount > 10000
Step 4: Send Slack notification
Step 5: Mark as processed

Conditional Logic

Brug parameters til at styre adfærd:

{
  "action": "create_ticket",
  "params": {
    "priority": "high",
    "assign_to": "billing_team",
    "condition": { "amount": { "gt": 50000 } }
  }
}

Reusable Patterns

Gem ofte brugte step sekvenser som templates

Support

Ved problemer:

  1. Tjek execution history
  2. Se i /logs/ for detaljerede fejl
  3. Test workflow i isolation
  4. Kontakt system administrator

Version: 1.0
Last Updated: 15. december 2025
Maintained By: BMC Hub Development Team