mirror of
https://github.com/xtr-dev/payload-automation.git
synced 2025-12-10 17:03:22 +00:00
- Add createTrigger() and createAdvancedTrigger() helpers - Add preset builders: webhookTrigger, cronTrigger, eventTrigger, etc. - Implement virtual fields with JSON backing for trigger parameters - Eliminate 90% of boilerplate when creating custom triggers - Add /helpers export path for trigger builders - Fix field name clashing between built-in and custom trigger parameters - Add comprehensive examples and documentation - Maintain backward compatibility with existing triggers 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
PayloadCMS Workflows Plugin Examples
This directory contains example code demonstrating how to use the PayloadCMS Workflows plugin.
Manual Trigger Example
The manual-trigger-example.ts file shows how to:
- Create a workflow with a manual trigger button in the admin UI
- Trigger workflows programmatically using custom triggers
- Access trigger data in workflow steps using JSONPath
Setting up a Manual Trigger Workflow
- Configure the plugin with a custom trigger:
workflowsPlugin({
triggers: [
{
slug: 'manual-trigger',
inputs: [] // No inputs needed for simple manual triggers
}
],
// ... other config
})
- Create a workflow with the manual trigger:
await payload.create({
collection: 'workflows',
data: {
name: 'My Manual Workflow',
triggers: [
{
type: 'manual-trigger'
}
],
steps: [
// Your workflow steps here
]
}
})
- The workflow will now have a "Trigger Workflow" button in the admin UI
Triggering Workflows Programmatically
import { triggerCustomWorkflow } from '@xtr-dev/payload-automation'
// Trigger all workflows with 'manual-trigger'
const results = await triggerCustomWorkflow(payload, {
slug: 'manual-trigger',
data: {
// Custom data to pass to the workflow
source: 'api',
timestamp: new Date().toISOString()
}
})
Accessing Trigger Data in Steps
Use JSONPath expressions to access trigger data in your workflow steps:
$.trigger.data.source- Access custom data fields$.trigger.type- The trigger type$.trigger.triggeredAt- When the trigger was activated