Triggers.do - Elegant Event-Driven Automation
Seamless event-driven automation with elegant, type-safe triggers
Overview
Triggers.do is a core primitive of the .do ecosystem, providing a clean, type-safe interface for creating and managing event-based triggers. These triggers initiate workflows and functions in response to events, enabling seamless automation across your business processes.
The Challenge
Event-driven automation presents several challenges:
- Event Detection: Identifying and capturing relevant events across diverse systems
- Conditional Logic: Determining precisely when to initiate processes
- Scheduling: Executing triggers at specific times with reliability
- Data Transformation: Converting event data into actionable inputs
- Error Handling: Gracefully managing failures in event processing
The Solution
Triggers.do provides an elegant, type-safe interface for event-driven automation:
- Unified Event Handling: Consistent patterns for events from any source
- Declarative Conditions: Simple, powerful conditions for trigger activation
- Reliable Scheduling: Precise time-based triggers with built-in reliability
- Seamless Data Mapping: Transform event data into structured inputs
- Elegant Error Recovery: Graceful failure modes with retry capabilities
Key Features
- Elegant API Design - Clean, intuitive interfaces for event-driven automation
- Type-Safe Events - Strongly-typed event data for reliable processing
- Flexible Trigger Conditions - Powerful, declarative conditions for precise activation
- Seamless Integration - Works with all .do services
- Comprehensive Event Sources - Support for webhooks, schedules, and system events
Elegant API Design
Triggers.do provides a clean, intuitive interface for event-driven automation:
import { Triggers } from 'triggers.do'
// Simple initialization with default settings
const triggers = new Triggers()
// Or with custom configuration
const triggers = new Triggers({
apiKey: process.env.TRIGGERS_API_KEY,
baseUrl: process.env.TRIGGERS_API_URL || 'https://triggers.do',
})
Creating Triggers
// Create a webhook trigger with elegant configuration
const webhookTrigger = await triggers.create({
name: 'New GitHub Issue',
type: 'webhook',
source: 'github',
event: 'issues.opened',
// Elegant condition for trigger activation
condition: {
'payload.repository.full_name': 'drivly/ai',
'payload.issue.labels': { contains: 'bug' },
},
// Define the target workflow to execute
target: {
type: 'workflow',
id: 'bug-triage-workflow',
// Map event data to workflow inputs
input: {
issueTitle: '{{payload.issue.title}}',
issueBody: '{{payload.issue.body}}',
issueUrl: '{{payload.issue.html_url}}',
reporter: '{{payload.issue.user.login}}',
},
},
})
// Create a schedule trigger with minimal configuration
const scheduleTrigger = await triggers.create({
name: 'Daily Report',
type: 'schedule',
// Simple cron expression
schedule: '0 9 * * 1-5', // Weekdays at 9am
target: {
type: 'function',
id: 'generateDailyReport',
input: {
date: '{{now | date: "YYYY-MM-DD"}}',
format: 'pdf',
},
},
})
Managing Triggers
// List all triggers with simple pagination
const allTriggers = await triggers.list({ limit: 10, page: 1 })
// Get a specific trigger by ID
const trigger = await triggers.get('trigger-id')
// Update a trigger with minimal configuration
await triggers.update('trigger-id', {
condition: {
'payload.repository.full_name': 'drivly/ai',
'payload.issue.labels': { contains: ['bug', 'high-priority'] },
},
})
// Delete a trigger when no longer needed
await triggers.delete('trigger-id')
Integration with the .do Ecosystem
Triggers.do is designed to work seamlessly with other .do services:
import { Workflow } from 'workflows.do'
import { AI } from 'functions.do'
import { Triggers } from 'triggers.do'
// Define an AI function using functions.do
const ai = AI({
analyzeBugReport: {
title: 'string',
body: 'string',
severity: 'Low | Medium | High',
category: 'UI | Backend | Performance | Security',
estimatedEffort: 'string',
},
})
// Define a workflow using workflows.do
const workflow = new Workflow({
name: 'Bug Triage',
steps: [
{
name: 'Analyze Bug',
function: 'analyzeBugReport',
input: {
title: '{{trigger.issueTitle}}',
body: '{{trigger.issueBody}}',
},
},
{
name: 'Create Task',
action: 'jira.createIssue',
input: {
project: 'AI',
type: 'Bug',
title: '{{trigger.issueTitle}}',
description: '{{trigger.issueBody}}',
priority: '{{steps.analyzeBug.severity}}',
labels: ['github', '{{steps.analyzeBug.category}}'],
},
},
],
})
// Create a trigger using triggers.do
const triggers = new Triggers()
const trigger = await triggers.create({
name: 'GitHub Issue Trigger',
type: 'webhook',
source: 'github',
event: 'issues.opened',
target: {
type: 'workflow',
id: workflow.id,
input: {
issueTitle: '{{payload.issue.title}}',
issueBody: '{{payload.issue.body}}',
issueUrl: '{{payload.issue.html_url}}',
},
},
})
Installation
npm install triggers.do
# or
yarn add triggers.do
# or
pnpm add triggers.do
The .do Ecosystem
Triggers.do is a core primitive of the .do ecosystem, designed to work seamlessly with other .do services:
- apis.do - The foundational SDK and unified API Gateway
- functions.do - Strongly-typed AI functions
- workflows.do - Business process orchestration
- agents.do - Autonomous digital workers
- actions.do - External system operations
- searches.do - Contextual data retrieval
Last updated on