Quick overview
This workflow captures employee receipt photos or PDFs from Telegram, uses OpenAI to extract structured expense data, validates it against policy and past claims in Google Sheets, and then drafts (or logs) the expense in Xero with an approval loop via Telegram.
How it works
- Triggers when a Telegram bot receives a message and checks whether it contains a receipt photo or document.
- Downloads the receipt file from Telegram and sends it to the OpenAI Chat Completions API (vision) to extract receipt fields as JSON.
- Normalizes the extracted data, generates a deterministic receipt key, and asks the employee for missing details if required fields are not present.
- Reads prior entries from a Google Sheets “Expenses” sheet and applies policy checks (limits, tax ID requirement, duplicates, weekend meals) to decide whether approval is needed.
- If approval is required, sends the expense details to a finance Telegram chat with Approve/Reject links and waits for the decision via a resume webhook.
- Appends the approved or rejected expense record to Google Sheets and notifies the employee of the outcome.
- For approved expenses, creates a DRAFT accounts payable invoice in Xero and alerts finance if the Xero draft creation fails.
Setup
- Connect Telegram credentials, create a bot, and ensure employees can send receipt photos/PDFs to it (and set YOUR_FINANCE_CHAT_ID for approvals).
- Add an HTTP Header Auth credential for the OpenAI API request (API key) used to call the Chat Completions endpoint.
- Connect Google Sheets OAuth credentials and replace YOUR_SPREADSHEET_ID with your spreadsheet containing an “Expenses” sheet.
- Ensure the “Expenses” sheet includes columns used by the workflow (for example: receipt_key, employee, merchant, date, total, currency, tax_id, category, policy_reason, approval_status, decided_at, received_at).
- Connect Xero OAuth2 credentials, set YOUR_XERO_EXPENSE_CODE, and update the policy LIMITS in the code step to match your company rules.