In today's fast-paced digital landscape, business events happen in real-time, and your team needs to know about them instantly. A new customer signs up, a major sale closes, or a subscription is renewed. How do you pipe these critical signals from one service, like Stripe, to your team's communication hub, like Slack?
Traditionally, this might involve setting up a dedicated server, managing a complex web of webhook handlers, or wrestling with generic serverless configurations. It's often brittle, hard to monitor, and overkill for what should be a simple task.
What if you could treat that integration not as a piece of infrastructure to maintain, but as a single, self-contained unit of logic? This is the core principle of Business as Code, and it’s made possible by action.do.
Let's explore how to connect Stripe and Slack with a single, reliable, and scalable atomic action.
Before we dive into the code, let's clarify what we mean by an "atomic action" on the .do platform.
An atomic action is a self-contained, single-purpose function designed to perform one specific task flawlessly. Think of it as a micro-task:
By encapsulating logic into these atomic units, you create building blocks that are incredibly easy to manage, test, and compose into larger, more intelligent automations.
Our goal is simple: when a successful payment is processed in Stripe, we want to immediately send a formatted message to our team's #sales channel in Slack.
This is the perfect candidate for an action.do. It's a single, repeatable task that connects two distinct services. The action will act as the intelligent glue, receiving data from Stripe and executing the logic to communicate with Slack.
With the .do SDK, defining this integration is remarkably straightforward. We're not just writing a script; we're defining a structured, reusable component of our business.
Here’s what our notify-slack-on-sale action looks like:
import { Do } from '@do-sdk/core';
// Define an atomic action to send a notification to Slack
const notifySlackOnSale = Do.action('notify-slack-on-sale', {
// Define the expected inputs with clear types
inputs: {
customerEmail: 'string',
amount: 'number',
paymentId: 'string',
},
handler: async ({ inputs, context }) => {
// Secrets like webhook URLs are securely managed by the .do platform
// and injected at runtime.
const slackWebhookUrl = context.secrets.SLACK_WEBHOOK_URL;
const message = `🎉 New Sale!
- Customer: ${inputs.customerEmail}
- Amount: $${(inputs.amount / 100).toFixed(2)}
- Stripe ID: ${inputs.paymentId}`;
// Use fetch to send the data to the Slack Incoming Webhook
const response = await fetch(slackWebhookUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: message }),
});
if (!response.ok) {
// The platform provides built-in observability to catch and alert on failures.
console.error('Failed to send Slack notification');
return { success: false, error: 'Slack API error' };
}
// Return a structured result
return { success: true, messageSent: true };
},
});
// To execute, you would call this action from a Stripe webhook handler.
// For example, in a serverless endpoint that receives the webhook:
//
// await notifySlackOnSale.run({
// customerEmail: stripeEvent.data.object.customer_details.email,
// amount: stripeEvent.data.object.amount_total,
// paymentId: stripeEvent.data.object.id
// });
Let's break down what's happening here:
At first glance, this might look similar to a standard serverless function. However, an action.do is purpose-built for creating agentic workflows. The difference lies in the ecosystem.
Unlike a generic serverless function, an action.do is a first-class citizen in a system designed for business automation. It comes with:
This single atomic action is powerful on its own, but its true potential is realized when it becomes part of a larger process.
An action.do is designed to be atomic. To orchestrate multiple actions, you use a workflow.do. For example, a successful Stripe sale could trigger a workflow that:
This approach creates a clean separation of concerns. Each action does one thing well, and the workflow orchestrates them into a robust, stateful, and observable business process. You are no longer just scripting tasks; you are building an intelligent agent that executes your business logic.
Ready to stop wrestling with infrastructure and start building flawless automations? Transform your business logic into composable, atomic actions and unlock the power of agentic workflows on the .do platform.