In software engineering, the "Don't Repeat Yourself" (DRY) principle is sacred. It's the simple but powerful idea that you should never duplicate code. Instead, you abstract common logic into a single, reusable function. This makes code cleaner, easier to maintain, and far less prone to bugs. So why, in the world of business automation, do we so often find ourselves repeating the same steps over and over?
Traditional Robotic Process Automation (RPA) tools, with their visual designers and screen-scraping focus, can often lead to "WET" (Write Everything Twice) workflows. You might build a bot to process an invoice from an email, then copy-paste most of that logic to create a second bot that processes an invoice from an SFTP server. When a change is needed—like an update to your accounting software's API—you now have to fix it in two places, doubling the work and the risk.
At rpa.do, we believe automation should be treated with the same discipline as modern software development. Our 'Business-as-Code' philosophy means applying proven principles like DRY to create resilient, scalable, and maintainable automations. Let’s explore how you can build a library of reusable logic with rpa.do to achieve true DRY-Automation.
Imagine you need to automate invoice processing. Your company receives invoices through two primary channels: a dedicated email inbox (invoices@company.com) and a partner's SFTP drop folder. The core logic for handling any invoice is the same:
With traditional tools, you might build two separate, monolithic bots.
The extract, validate, and create logic is duplicated. This model is inefficient and fragile. A small change in the validation rules or the QuickBooks API requires redundant, error-prone updates.
rpa.do shifts this paradigm. Instead of building monoliths, you create small, self-contained, and reusable blocks of logic—we'll call them functions for this post—that can be composed into powerful workflows by an Agent.
This is the core of our developer-first, API-driven approach. You define a piece of business logic once and then call it from anywhere, as many times as you need.
First, let's encapsulate the core invoice processing logic into a single, reusable function. This function's only job is to take invoice data, process it, and enter it into QuickBooks. It doesn't care where the invoice came from.
Using our SDK, you could define a function like this and register it with the rpa.do platform:
import { functions, services } from '@do/rpa';
import { QuickBooks } from '@do/services-quickbooks';
// Define a reusable function to process a single invoice
functions.define({
name: 'process_single_invoice',
description: 'Validates invoice data and creates a bill in QuickBooks.',
// The main logic for the function
async handler(invoiceData: { vendor: string, amount: number, invoiceId: string }) {
// 1. Validate data (example)
if (!invoiceData.vendor || invoiceData.amount <= 0) {
throw new Error('Invalid invoice data received.');
}
// 2. Securely get credentials and initialize service
const quickbooksApi = new QuickBooks({
auth: services.getSecret('QUICKBOOKS_API_KEY')
});
// 3. Create the bill
const result = await quickbooksApi.createBill({
vendorName: invoiceData.vendor,
totalAmount: invoiceData.amount,
invoiceNumber: invoiceData.invoiceId
});
console.log(`Successfully created bill with ID: ${result.billId}`);
return { success: true, billId: result.billId };
}
});
Here, services.getSecret('QUICKBOOKS_API_KEY') securely pulls credentials from the platform's built-in vault, keeping sensitive data out of your code. This function is now a testable, independent unit in your automation library.
With our reusable logic defined, our main Agent workflows become incredibly simple orchestrators. Their only job is to handle the source-specific details and then call the centralized function.
Workflow 1: Processing Email Invoices
An Agent can be configured to monitor an inbox. The workflow code is now clean and focused.
import { Agent } from '@do/rpa';
// This agent processes invoices from email
const emailAgent = new Agent('email-invoice-processor');
emailAgent.run({
// Trigger: New emails in the invoices inbox
source: {
type: 'email_inbox',
id: 'invoices@company.com'
},
// Task: For each invoice, call our reusable function
workflow: async (email) => {
// Let's assume an AI-powered service extracts structured data from the email/PDF
const invoiceData = await email.extractInvoiceData();
// Call the reusable function we defined earlier
await functions.run('process_single_invoice', invoiceData);
}
});
Notice the power of abstraction. The main workflow uses an extractInvoiceData() method—itself another potentially reusable AI-powered function—and then hands the structured data off to process_single_invoice.
Workflow 2: Processing SFTP Invoices
The agent for processing SFTP invoices looks very similar, but with a different source. The core call remains identical.
import { Agent } from '@do/rpa';
// This agent processes invoices from an SFTP drop
const sftpAgent = new Agent('sftp-invoice-processor');
sftpAgent.run({
// Trigger: New files in the SFTP directory
source: {
type: 'sftp_server',
directory: '/incoming/invoices'
},
// Task: For each file, call our reusable function
workflow: async (file) => {
const invoiceData = await file.extractInvoiceData();
// Call the EXACT SAME reusable function
await functions.run('process_single_invoice', invoiceData);
}
});
Now, if you need to update your QuickBooks integration or change a business validation rule, you only modify the process_single_invoice function. One change, instantly propagated to every workflow that uses it. That is the power of DRY-Automation.
Treating Robotic Process Automation as code unlocks the best practices of software development. By building a library of reusable, intelligent rpa.do functions, you benefit from:
This modular approach is the future of workflow automation. It's how you go beyond brittle bots to build an enterprise-grade automation engine powered by AI agents.
Ready to stop repeating yourself and start building Services-as-Software? Explore the rpa.do Intelligent Automation API and transform your business processes into simple, reliable code.