Invoice generator and delivery via Gmail
Invoice generation and email notification based on Airtable records
graph TD
%%{init: {'theme': 'mc','layout': 'elk'}}%%
Airtable-nub7s[Compra por procesar]
style Airtable-nub7s stroke:#a170ff
GmailMesageComponent-m5njd[<div><img alt="logo" src="/_astro/gmail.CLxyIGOu.svg" style="height: 20px !important;width: 20px !important"/></div>Notificar por gmail]
style GmailMesageComponent-m5njd stroke:#a170ff
ParseData-lnctx[<div><img alt="logo" src="/_astro/braces.Djq0PW4_.svg" style="height: 20px !important;width: 20px !important"/></div>Parse Data]
style ParseData-lnctx stroke:#a170ff
Airtable-oaruy[Marcar como atendido]
style Airtable-oaruy stroke:#a170ff
Loop-v9i9s[Loop]
style Loop-v9i9s stroke:#a170ff
LoopEnd-0246r[Loop End]
style LoopEnd-0246r stroke:#a170ff
OpenAIModel-glwa8[<div><img alt="logo" src="/_astro/openAI.BhmuxEs3.svg" style="height: 20px !important;width: 20px !important"/></div>OpenAI]
style OpenAIModel-glwa8 stroke:#a170ff
AdvancedAgent-bbgal[Agent2]
style AdvancedAgent-bbgal stroke:#a170ff
Airtable-nub7s -.- Loop-v9i9s
linkStyle 0 stroke:#a170ff
Loop-v9i9s -.- ParseData-lnctx
linkStyle 1 stroke:#a170ff
LoopEnd-0246r -.- Loop-v9i9s
linkStyle 2 stroke:#a170ff
AdvancedAgent-bbgal -.- LoopEnd-0246r
linkStyle 3 stroke:#a170ff
ParseData-lnctx -.- AdvancedAgent-bbgal
linkStyle 4 stroke:#a170ff
GmailMesageComponent-m5njd -.- AdvancedAgent-bbgal
linkStyle 5 stroke:#a170ff
Airtable-oaruy -.- AdvancedAgent-bbgal
linkStyle 6 stroke:#a170ff
OpenAIModel-glwa8 -.- AdvancedAgent-bbgal
linkStyle 7 stroke:#a170ff
Invoice Generation and Email Delivery Workflow
🧩 Overview
This workflow automates the creation and dispatch of invoices for sales records stored in Airtable. It reads unprocessed orders, formats each record into an email body, sends the invoice via Gmail, and marks the order as handled. The process repeats until all eligible records are processed, ensuring a fully automated, end‑to‑end invoicing pipeline.
⚙️ Main Features
- Automated record retrieval from Airtable, filtering for unprocessed orders.
- Iterative processing of each order using a loop construct.
- Dynamic email generation by an AI model that formats order details.
- Seamless email delivery through Gmail.
- Automated status update in Airtable to mark orders as completed.
- Error‑handled agent that coordinates tool usage and maintains state.
🔄 Workflow Steps
| Component Name | Role in the Workflow | Key Inputs | Key Outputs |
|---|---|---|---|
| Airtable Reader | Retrieves sales records that have not yet been processed. | Airtable base, table, and filter {atendido}="false". |
List of record objects containing order details. |
| Loop | Iterates over the list of records, providing one record to downstream steps. | Record list from Airtable Reader. | Current record (item) for each iteration. |
| Parse Data | Transforms a record into a plain‑text message using a defined template. | Current record data. | Formatted text string for the agent. |
| Advanced Agent | Uses the formatted text to decide actions: send an invoice email and update the record status. | Parsed text message. | Response object summarising agent actions. |
| Gmail Send | Sends the invoice email via Gmail using the recipient address and message body from the agent. | Email address, subject, and body. | Confirmation of email sent. |
| Airtable Updater | Updates the atendido field of the processed record to indicate completion. |
Record ID and updated field values. | Updated record confirmation. |
| Loop End | Signals the end of the current iteration and feeds the next record back into the Loop. | Processed data from the agent. | Next item for the Loop. |
🧠 Notes
- The workflow relies on Airtable API credentials for reading and updating records and on Google‑Mail API credentials for sending emails.
- The OpenAI LLM is used within the Advanced Agent to generate the invoice text; it can be swapped with any compatible language model.
- All operations are performed in batch mode; the loop processes records one by one, ensuring that each order is fully handled before the next is processed.
- The system assumes the Airtable table contains the fields:
nombre_usuario,correo_electronico,producto,cantidad,precio_unitario,total,atendido, andfecha_pedido. - The
atendidofield must be a simple string flag (true/false). - Errors during email sending or record updating trigger a retry policy defined in the agent’s configuration.
- No internal configuration values (e.g., API keys, token strings) appear in the documentation to preserve security.