STOP Manually Processing Invoices — Try This AI Automation (n8n tutorial)

AI WorkshopAbout 5 min readJun 25, 2025Watch original
THE SUMMARYAI-generated

Key Concepts:

  • Invoice automation
  • Human-in-the-loop approach
  • Telegram trigger
  • Switch node (document, image, text processing)
  • Llama Parse (document parsing API)
  • Status check loop (pending, success, error)
  • Basic LLM chain (data extraction)
  • Google Sheets integration (data storage)
  • Google Drive integration (file storage)
  • Interactive user communication (reply keyboard)

1. Demo and Overview

  • The video demonstrates a system for automating invoice processing with human interaction using Telegram.
  • The automation handles invoices in image, PDF, and text formats.
  • The workflow pauses at key steps, awaiting user confirmation before proceeding.
  • Example: An invoice from Zilker Electronics is uploaded as an image, processed, and the extracted data (invoice number, date, total amount) is presented to the user for verification.
  • The user is prompted to confirm the data and then select a payment method (card, bank, or cash).
  • Based on the user's input, the system updates a Google Sheet and moves the invoice file to a Google Drive folder.

2. Workflow Setup and Telegram Trigger

  • The tutorial begins with importing a pre-built workflow template into n8n.
  • The workflow is initiated by a Telegram trigger, which listens for incoming messages.
  • Alternative triggers like WhatsApp or Twilio (for phone integration) can be used.

3. Switch Node for File Type Handling

  • A switch node is used to route the incoming invoice based on its file type (document, image, or text).
  • The node examines the JSON.message.document property from the Telegram message to determine the file type.
  • Example: A PDF invoice is uploaded, and the switch node identifies it as a "document," routing it to the appropriate processing path.

4. Document Processing Path (PDF)

  • Data Cleaning: An "Edit Field" node (Set node) extracts and cleans relevant data from the Telegram message, including the chat ID and file ID.
  • User Notification: A message is sent back to the user via Telegram, confirming that the PDF has been received and is being processed.
  • File Download: The Telegram node downloads the PDF file using the file ID.
  • Llama Parse Integration: The downloaded file is uploaded to Llama Parse, a document parsing API provided by Llama Index.
    • Llama Index is described as a platform for building AI knowledge assistants, offering document parsing capabilities.
    • The API endpoint used for uploading is API.cloud.lamaindex/I API parsing and upload.
  • Status Check Loop:
    • After uploading, the workflow retrieves the parsing job's status from Llama Parse using another API endpoint.
    • A switch node checks the status:
      • If "pending," a "Wait" node pauses the workflow for 1 second before rechecking the status.
      • If "success," the workflow proceeds to the next step.
      • If "error" or "canceled," the workflow stops.
  • Data Extraction with LLM Chain:
    • Once the status is "success," the parsed document data is retrieved from Llama Parse.
    • A basic LLM chain is used to extract specific information (invoice number, date, total amount, tax) from the parsed data.
    • The LLM chain uses a system prompt to instruct the AI on how to extract the data accurately.
    • An output parser defines the desired JSON format for the extracted data.
  • Google Sheets Update: The extracted data is then added to a Google Sheet.

5. Human-in-the-Loop Interaction

  • A message is sent to the user via Telegram, displaying the extracted invoice data and asking for confirmation.
  • The message includes a "reply keyboard" with "Yes" and "No" options, enabling interactive communication.
  • The reply_keyboard option within the Telegram node is used to create these interactive buttons.

6. Handling User Confirmation and Payment Method

  • A switch node routes the workflow based on the user's "Yes" or "No" response.
  • If "Yes," the workflow proceeds to ask the user for the payment method (card, cash, or bank).
  • Another switch node routes the workflow based on the selected payment method.

7. Updating Google Sheets with Payment Method

  • The workflow retrieves the user's payment method selection.
  • It identifies the correct row in the Google Sheet to update.
  • An "Edit Field" node cleans the data and adds the payment method.
  • The Google Sheet is updated with the payment method.
  • A confirmation message is sent to the user via Telegram.

8. File Management in Google Drive

  • The workflow retrieves the original invoice file from Telegram.
  • The file is moved to a designated folder in Google Drive for archival purposes.

9. Use Cases and Applications

  • The demonstrated invoice automation can be adapted for various other applications, including:
    • Expense approval
    • Document processing
    • Payroll management
    • Approving business-related expenses
  • The human-in-the-loop approach allows for managerial approval or rejection of documents.

10. Community and Collaboration

  • The video encourages viewers to join the n8n community to collaborate on workflow improvements and share ideas.
  • A bi-weekly challenge offers prizes for creating useful workflows.

11. Notable Quotes

  • "I'm going to show you how to completely automate your invoice processing with a human in the loop approach meaning that you will have the ability to interact with this automation right from your phone."
  • "Llama index it says build AI knowledge assistance over your enterprise and this is one of the most popular um tools out there again because it it's used in enterprise solution it's used for uh small businesses mediumsiz businesses it has a lot of different um integrations and a lot of different options when it comes to like for example the framework um it has um document parsing and this is one of my favorite uh document parsers because it is very widely used"

12. Conclusion

The video provides a detailed walkthrough of building an automated invoice processing system with human-in-the-loop interaction using n8n, Telegram, Llama Parse, and Google Sheets/Drive. It highlights the flexibility and adaptability of the workflow for various business processes requiring user input and approval. The emphasis on community collaboration and continuous improvement encourages viewers to leverage the template as a foundation for building custom solutions.

AI summaries can miss context or contain errors. Check important details against the original video.

Go a little deeper.

Have a question about this video? Load its transcript to open the video chat.