App Store Architecture
All app integrations are managed through the app store system (~/workspace/source/packages/app-store/):
Categories
- Capture: Apps for capturing receipts and documents (Slack, WhatsApp)
- Accounting: Apps for exporting data (Fortnox, Xero, QuickBooks)
Slack
Connect Slack to receive transaction notifications and upload receipts directly from channels.Features
- Transaction notifications in chosen channel
- Invoice notifications (paid/overdue)
- Receipt upload via file sharing
- Smart matching with approval workflow
- Thread-based match confirmations
Configuration
OAuth Scopes
Required Slack scopes:See:
~/workspace/source/packages/app-store/src/slack/server/oauth.ts:16-27Implementation Details
Location:~/workspace/source/packages/app-store/src/slack/
OAuth Flow
OAuth Flow
The Slack OAuth flow:
- User clicks “Connect” in Midday app store
onInitializeopens popup with Slack OAuth URL- User authorizes app in Slack
- Slack redirects to callback URL with code
- Backend exchanges code for access token
- Connection stored in database
- Popup posts message to parent window
- Parent window refreshes app list
~/workspace/source/packages/app-store/src/slack/initialize.tsFile Upload Processing
File Upload Processing
When a user shares a file in a channel with the Midday bot:
- Slack sends
file_sharedevent - Bot downloads file via
url_private_download - Extract data using OCR/document processing
- Match to transactions
- Reply in thread with match suggestion
- User clicks Confirm/Decline button
~/workspace/source/packages/app-store/src/slack/server/events/file-share.tsNotification Examples
Settings
Slack app settings (~/workspace/source/packages/app-store/src/slack/config-base.ts:14-42):
- Transactions: Get notified when new transactions are added
- Invoices: Get notified when invoices are paid or overdue
- Match Suggestions: Get notified when receipts are matched or need review
Features
- Forward receipts via WhatsApp messages
- Send photos or PDF documents
- Automatic data extraction
- Match notifications via WhatsApp
- One-tap approve/decline buttons
Configuration
Configure Webhook
Set webhook URL in Meta Developer Portal:Verify token must match
WHATSAPP_VERIFY_TOKEN.Implementation Details
Location:~/workspace/source/packages/app-store/src/whatsapp/
Connection Flow
Connection Flow
- User clicks “Connect” in Midday app store
- App generates unique inbox ID
- Shows QR code and connection text
- User sends inbox ID to WhatsApp number
- Webhook receives message with inbox ID
- Backend creates WhatsApp connection
- Sends confirmation message to user
~/workspace/source/apps/api/src/rest/routers/webhooks/whatsapp/index.ts:252-332Receipt Processing
Receipt Processing
When a user sends an image or document:
- WhatsApp webhook receives message
- Verify user is connected
- Check file type is allowed (image/jpeg, image/png, application/pdf)
- React with hourglass emoji (⏳) to indicate processing
- Trigger upload job with media ID
- Job downloads file from WhatsApp
- Extract data using OCR
- Match to transactions
- Send match notification with approve/decline buttons
- React with checkmark (✓) on success
~/workspace/source/apps/api/src/rest/routers/webhooks/whatsapp/index.ts:337-401Match Buttons
Match Buttons
Webhook Events
WhatsApp Business API sends webhooks for:- Text Messages: Connection codes, commands
- Image Messages: Receipt photos
- Document Messages: Receipt PDFs
- Interactive Buttons: Match approvals/declines
Allowed File Types
Settings
WhatsApp settings (~/workspace/source/packages/app-store/src/whatsapp/config-base.ts:14-33):
- Receipt Processing: Automatically process receipts sent via WhatsApp
- Match Notifications: Get notified when receipts are matched or need review
Fortnox
Connect Fortnox to export transactions and receipts to your Swedish accounting system.Fortnox integration is currently in Beta.
Features
- Manual transaction export as vouchers
- Automatic receipt attachments
- Swedish BAS account mapping
- Finalized voucher creation
Configuration
Get OAuth Credentials
Register app in Fortnox Developer Portal and get:
- Client ID
- Client Secret
- Redirect URI
Implementation Details
Location:~/workspace/source/packages/app-store/src/fortnox/
Export Flow
Export Flow
- User reviews and categorizes transactions in Midday
- Selects transactions to export
- Clicks “Export to Fortnox”
- Midday creates vouchers via Fortnox API
- Attaches receipts to vouchers
- Vouchers created as finalized entries
Account Mapping
Account Mapping
Transaction categories map to Fortnox accounts using Swedish BAS:
- Meals & Entertainment → BAS account 6260
- Office Supplies → BAS account 6110
- Travel → BAS account 6230
- etc.
Settings
Fortnox has no user settings - it’s a pure export integration.App Management
Checking Installation Status
Getting App Settings
Updating Settings
Disconnecting Apps
Security
OAuth Security
All OAuth flows use:- State parameter for CSRF protection
- Secure token storage
- Token encryption at rest
- Automatic token refresh
Webhook Verification
All webhooks verify signatures:Error Handling
OAuth Errors
Webhook Errors
Webhook handlers log errors but return 200 to prevent retries:Testing
Local Webhook Testing
Use ngrok or similar to test webhooks locally:Mock Webhooks
Use the service’s test webhook features:- Slack: App settings → Event Subscriptions → Resend event
- WhatsApp: Send test message from Business Manager