Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
9.5 KiB
Automation Hub: Creating TypeScript Workflows
Introduction
The Automation Hub provides a powerful interface for creating, managing, and monitoring TypeScript-based workflows. This guide will walk you through the practical steps of using the Automation Hub to create and manage your workflows.
Table of Contents
- Automation Hub Overview
- Creating a New Workflow
- Using the Workflow Editor
- Testing and Validating Workflows
- Managing Workflow Versions
- Attaching Workflows to Events
- Monitoring Workflow Executions
- Using Workflow Templates
- Best Practices
Automation Hub Overview
The Automation Hub consists of four main sections:
- Template Library: Browse and use predefined workflow templates
- Workflows: Create, edit, and manage your custom workflows
- Events Catalog: Configure event triggers for your workflows
- Logs & History: Monitor workflow executions and troubleshoot issues
To access the Automation Hub, navigate to the main menu and select "Automation Hub".
Creating a New Workflow
Step 1: Navigate to the Workflows Section
- Open the Automation Hub
- Click on the "Workflows" tab in the navigation menu
Step 2: Create a New Workflow
- Click the "Create Workflow" button in the top-right corner
- You'll be taken to the workflow editor page
Step 3: Fill in Workflow Metadata
Complete the following fields in the metadata section:
- Workflow Name: Enter a descriptive name for your workflow
- Description: Provide a clear description of what the workflow does
- Version: Set the initial version (default is 1.0.0)
- Tags: Add relevant tags to categorize your workflow
- Active: Toggle to set whether the workflow is active or inactive
Using the Workflow Editor
The workflow editor provides a TypeScript code editor with specialized features for workflow development.
Editor Features
- Syntax Highlighting: TypeScript syntax is highlighted for readability
- Code Completion: Intelligent suggestions for workflow context methods and properties
- Error Checking: Real-time validation of your TypeScript code
- Code Snippets: Pre-built snippets for common workflow patterns
Using Code Snippets
- Type a keyword or press Ctrl+Space to see available snippets
- Select a snippet from the dropdown menu
- The snippet will be inserted with placeholders for customization
Available snippets include:
- Basic Workflow Structure
- Process Trigger Event
- Execute Action
- Parallel Actions
- Conditional Logic
- Error Handling
Workflow Structure
Every workflow must follow this basic structure:
async function workflow(context: WorkflowContext): Promise<void> {
const { actions, data, events, logger } = context;
// Initial state
context.setState('initial');
// Workflow implementation
// Final state
context.setState('completed');
}
Key Components to Include
-
State Management: Always set and update workflow states
context.setState('initial'); // Later context.setState('processing'); // Finally context.setState('completed'); -
Event Handling: Process the trigger event that started the workflow
const triggerEvent = context.input.triggerEvent; -
Action Execution: Perform actions to interact with systems
const result = await actions.someAction({ param: 'value' }); -
Error Handling: Include try/catch blocks for robustness
try { await actions.riskyOperation(); } catch (error) { logger.error('Operation failed', error); } -
Logging: Add logs for monitoring and debugging
logger.info('Workflow started'); logger.debug('Processing data', someData); logger.error('Error occurred', error);
Testing and Validating Workflows
Using the Test Button
- Click the "Test" button in the editor toolbar
- The system will validate your workflow code
- Results will be displayed, including:
- Syntax errors
- Structure validation
- Security warnings
- Best practice recommendations
Understanding Validation Results
- Success: Your workflow code is valid and can be saved
- Warnings: Potential issues that should be reviewed but won't prevent saving
- Errors: Critical issues that must be fixed before saving
Common Validation Warnings
- Missing error handling (try/catch blocks)
- Not using context.setState to track workflow state
- Security concerns like accessing process.env or using eval()
Managing Workflow Versions
Creating a New Version
- Open an existing workflow
- Make your changes
- Update the version number in the metadata section
- Click "Save Workflow"
- A new version will be created while preserving the previous versions
Using the Versions Dialog
- Click the "Versions" button in the workflow editor
- A dialog will open showing all versions of the workflow
- For each version, you can see:
- Version number
- Creation date
- Created by
- Whether it's the current active version
Setting the Active Version
- Open the Versions dialog
- Find the version you want to activate
- Click "Set as Active"
- The selected version will become the active one used for new workflow executions
Attaching Workflows to Events
Step 1: Navigate to the Events Catalog
- Open the Automation Hub
- Click on the "Events Catalog" tab
Step 2: Find an Event
Browse or search for the event you want to attach a workflow to.
Step 3: Attach a Workflow
- Click the "Attach Workflow" button next to the event
- Select a workflow from the dropdown menu
- Configure parameter mapping if needed
- Click "Save" to create the attachment
Parameter Mapping
When attaching a workflow to an event, you can map event data to workflow parameters:
- Select an event field from the dropdown
- Select the corresponding workflow parameter
- Add any transformation logic if needed
- Repeat for all required parameters
Monitoring Workflow Executions
Step 1: Navigate to Logs & History
- Open the Automation Hub
- Click on the "Logs & History" tab
Step 2: Browse Workflow Executions
The Logs & History section shows all workflow executions with:
- Workflow name
- Trigger event
- Execution status
- Start and end times
- Duration
Step 3: View Execution Details
- Click on a workflow execution to see details
- The details view includes:
- State transitions
- Action executions and results
- Events received and emitted
- Log messages
- Error information (if any)
Using the Workflow Visualizer
- Click the "Visualize" button for a workflow execution
- A visual representation of the workflow will be displayed
- The visualization shows:
- States and transitions
- Actions and their status
- Events and their flow
- Current state (for active workflows)
Using Workflow Templates
Step 1: Browse the Template Library
- Open the Automation Hub
- Click on the "Template Library" tab
- Browse available templates by category or use the search function
Step 2: Preview a Template
- Click the "Preview" button on a template
- Review the template code and description
Step 3: Create a Workflow from a Template
- Click "Create Workflow from Template"
- You'll be taken to the workflow editor with the template code pre-loaded
- Customize the workflow as needed
- Save the workflow with your changes
Available Template Categories
- Approval Workflows
- Request and Fulfillment Workflows
- Review and Feedback Workflows
- Onboarding and Provisioning Workflows
- Incident Management Workflows
Best Practices
Workflow Design
- Start Simple: Begin with a clear, focused workflow
- Use Descriptive Names: Name workflows, states, and variables clearly
- Include Comments: Document complex logic and decisions
- Handle Errors: Always include error handling
- Test Thoroughly: Validate your workflow before deploying
Performance Optimization
- Use Parallel Execution: Run independent actions in parallel
- Minimize Data Storage: Store only necessary data
- Optimize State Transitions: Use meaningful states but don't overdo it
- Consider Workflow Size: Break complex workflows into smaller ones
Security Considerations
- Avoid Unsafe Patterns: Don't use eval(), Function(), or access process.env
- Validate Inputs: Check input data before processing
- Limit Scope: Keep workflows focused on their specific purpose
- Follow Least Privilege: Only request necessary permissions
Maintenance Tips
- Version Properly: Use semantic versioning (MAJOR.MINOR.PATCH)
- Document Changes: Add comments explaining version changes
- Test Before Activating: Always test new versions before setting them active
- Monitor Executions: Regularly check the Logs & History section
Conclusion
The Automation Hub provides a powerful environment for creating and managing TypeScript-based workflows. By following this guide, you can effectively create, test, and monitor workflows that automate your business processes.
For more detailed information on TypeScript workflow development, refer to the TypeScript Workflow Creation Guide.