Process invoices and send to Slack
This tutorial walks through building an agent that processes PDF invoices, extracts structured data, and sends the results to Slack. The agent takes an uploaded invoice PDF, extracts key information like vendor details and line items, and posts a formatted summary to a Slack channel.
Interface
Blueprint
Slack message
This pattern is useful for automating accounts payable workflows, expense processing, and any scenario where you need to extract structured data from documents and route it to business systems. Once you complete this tutorial, you can continue enhancing the agent by adding tool calling with behaviors like validating invoices, flagging potential issues, and comparing invoices against historical data.
Prerequisites
Before building this agent, you need to set up a Slack webhook to send the invoice data to a Slack channel.
Follow the instructions in the Slack documentation to set up a webhook. The general steps are:
- Go to Slack API and create a new app
- Select “From scratch” and provide a name for your app
- Choose the Slack workspace where you want to build the agent
- Navigate to “Incoming Webhooks” in the left sidebar of the new app and activate webhooks
- Click “Add New Webhook to Workspace” and select the channel where invoices should be posted. You might need administrator permissions to add a webhook to a channel, depending on your Slack workspace settings.
- Copy the webhook URL - you’ll need this for the HTTP request block. The webhook URL will look like:
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
Agent overview
This agent processes invoices through the following steps:
- User uploads a PDF invoice file
- File is uploaded to Writer Cloud storage
- PDF content is extracted and parsed
- AI extracts structured invoice data such as vendor, amounts, line items.
- Formatted invoice summary is sent to Slack
Build the UI
The agent’s UI contains a file input for uploading invoices and a submit button.
Add a file input
Drag a File Input block to the canvas. In the block’s configuration menu, update the following:
- Label:
Invoice
- Allowed file types:
.pdf
- State element under Binding:
invoice
This allows users to upload PDF files and stores the file in the invoice
state variable.
Add a button to submit the request
Drag a Button block to the canvas. In the block’s configuration menu, update the following:
- Label:
Submit
Build the blueprint
The logic of the blueprint is as follows:
- The UI Trigger block starts the agent when the user clicks the submit button
- The Add files to Writer Cloud block uploads the invoice file to cloud storage
- The Parse PDF block extracts text content from the uploaded file
- The Structured Output block processes the PDF text and extracts invoice data as JSON
- The HTTP Request block sends the structured data to Slack
The finished blueprint contains the following blocks:
Add a UI Trigger block
Drag a UI Trigger block to the canvas. In the block’s configuration menu, update the following:
- Component Id: select the Submit button from the dropdown
- Trigger:
wf-click
This triggers the blueprint when the user clicks the Process Invoice button.
Add an Add files to Writer Cloud block
Drag an Add files to Writer Cloud block to the canvas. In the block’s configuration menu, update the following:
- Files:
@{invoice}
This uploads the invoice file from the invoice
state variable to Writer Cloud storage.
Add a Parse PDF block
Drag a Parse PDF tool block to the canvas. In the block’s configuration menu, update the following:
- File:
@{results.0.id}
This extracts the text content from the uploaded PDF file using the file information returned from the Add files to Writer Cloud block.
Add a Structured Output block
Drag a Structured Output block to the canvas. In the block’s configuration menu, update the following:
- Prompt:
- Input:
@{result}
- Model:
Palmyra X5
- JSON Schema: The following is an example JSON schema for the structured output. You can use this as a starting point, or create your own schema based on the invoice format you’d like to extract.
This processes the PDF text and extracts structured invoice data according to the JSON schema. The AI will identify and extract the relevant information from the invoice text.
Add an HTTP Request block to send to Slack
Drag an HTTP Request block to the canvas. In the block’s configuration menu, update the following:
- Method:
POST
- URL: Your Slack webhook URL
- Body:
This sends a formatted message to Slack with the key invoice details. The message uses Slack’s block kit format to create a structured, readable invoice summary.
Preview the agent
Navigate to the Preview tab to test the agent.
Upload a PDF invoice and click the Process Invoice button. The agent will upload the file, extract the invoice data, and send a summary to your configured Slack channel.
You can see the agent’s progress in the Logs tab, including the extracted JSON data and the Slack API response.
You should see a message in the Slack channel with the invoice data.
Add tool calling for invoice validation
You can enhance this agent by adding tool calling to validate invoices and flag potential issues. Here are some ways to extend the functionality:
- Check for missing required fields like tax ID or payment terms
- Compare against previous invoices from the same vendor to detect price discrepancies
- Validate amounts against purchase orders and company spending policies
- Flag duplicate invoice numbers or unusual payment terms
- Verify vendor details against your approved vendor list
To add these capabilities:
- Add a tool calling block after the structured output to analyze the extracted data
- Configure validation rules and checks in your custom Python code
- Update the Slack message to include any validation warnings or approvals
- Optionally trigger different workflows based on the validation results
Check out the tool calling tutorial to learn how to add these validation capabilities to your invoice processing agent.