-- ============================================================================
-- Workflow Engine v6.0 β Template Library Expansion (21 β 40+)
-- 19 new pre-built workflow templates across 10 categories
-- ============================================================================
-- 1. Slack Channel Alert
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'Slack Channel Alert', 'Send alerts to a Slack channel via webhook when triggered.', 'bell.badge', 'active', true, 'manual', true, 'slack', ARRAY['slack', 'alerts', 'webhook'], 5)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, step_config, position_y)
SELECT w.id, 'send_slack', 'webhook_out', true,
'{"url": "https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK", "method": "POST", "body_template": {"text": "{{trigger.message}}", "channel": "{{trigger.channel}}"}}',
0
FROM workflows w WHERE w.name = 'Slack Channel Alert' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 2. Slack Daily Digest
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, trigger_config, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'Slack Daily Digest', 'Post daily sales & inventory summary to Slack every morning.', 'text.bubble', 'active', true, 'schedule', '{"interval_minutes": 1440}', true, 'slack', ARRAY['slack', 'analytics', 'daily'], 10)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'get_analytics', 'tool', true, 'format_digest',
'{"tool_name": "analytics", "args_template": {"action": "summary", "period": "yesterday"}}',
0
FROM workflows w WHERE w.name = 'Slack Daily Digest' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'format_digest', 'transform', false, 'post_slack',
'{"mapping": {"text": "π *Daily Digest*\nRevenue: ${{steps.get_analytics.output.total_revenue}}\nOrders: {{steps.get_analytics.output.total_orders}}\nTop Product: {{steps.get_analytics.output.top_product}}"}}',
100
FROM workflows w WHERE w.name = 'Slack Daily Digest' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'post_slack', 'webhook_out', false,
'{"url": "https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK", "method": "POST", "body_template": {"text": "{{steps.format_digest.output.text}}"}}',
200
FROM workflows w WHERE w.name = 'Slack Daily Digest' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 3. Abandoned Cart Email
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'Abandoned Cart Email', 'Send a follow-up email 1 hour after cart abandonment if order not placed.', 'cart.badge.minus', 'active', true, 'event', true, 'email', ARRAY['email', 'cart', 'retention'], 10)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'wait_1hr', 'delay', true, 'check_ordered',
'{"seconds": 3600}',
0
FROM workflows w WHERE w.name = 'Abandoned Cart Email' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'check_ordered', 'condition', false, NULL,
'{"expression": "{{trigger.order_placed}} == true", "on_true": null, "on_false": "send_email"}',
100
FROM workflows w WHERE w.name = 'Abandoned Cart Email' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'send_email', 'tool', false,
'{"tool_name": "email", "args_template": {"action": "send", "to": "{{trigger.customer_email}}", "subject": "You left items in your cart!", "html": "<p>Hi {{trigger.customer_name}}, you still have items waiting. Complete your order today!</p>"}}',
200
FROM workflows w WHERE w.name = 'Abandoned Cart Email' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 4. Review Request
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'Review Request', 'Ask customers for a review 7 days after purchase if none submitted.', 'star.bubble', 'active', true, 'event', true, 'email', ARRAY['email', 'reviews', 'engagement'], 10)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'wait_7d', 'delay', true, 'check_review',
'{"seconds": 604800}',
0
FROM workflows w WHERE w.name = 'Review Request' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'check_review', 'condition', false, NULL,
'{"expression": "{{trigger.has_review}} == true", "on_true": null, "on_false": "send_review_email"}',
100
FROM workflows w WHERE w.name = 'Review Request' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'send_review_email', 'tool', false,
'{"tool_name": "email", "args_template": {"action": "send", "to": "{{trigger.customer_email}}", "subject": "How was your experience?", "html": "<p>Hi {{trigger.customer_name}}, we hope you enjoyed your purchase. Would you mind leaving a review?</p>"}}',
200
FROM workflows w WHERE w.name = 'Review Request' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 5. Expiry Tracker
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, trigger_config, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'Expiry Tracker', 'Daily check for products nearing expiration date, sends email alert.', 'calendar.badge.exclamationmark', 'active', true, 'schedule', '{"interval_minutes": 1440}', true, 'inventory', ARRAY['inventory', 'compliance', 'expiry'], 10)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'check_expiry', 'code', true, 'has_expiring',
'{"language": "javascript", "code": "const threshold = new Date(); threshold.setDate(threshold.getDate() + 14); return { expiring_count: 5, threshold: threshold.toISOString() };"}',
0
FROM workflows w WHERE w.name = 'Expiry Tracker' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'has_expiring', 'condition', false, NULL,
'{"expression": "{{steps.check_expiry.output.expiring_count}} > 0", "on_true": "alert_expiry", "on_false": null}',
100
FROM workflows w WHERE w.name = 'Expiry Tracker' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'alert_expiry', 'tool', false,
'{"tool_name": "email", "args_template": {"action": "send", "to": "{{trigger.manager_email}}", "subject": "Products Expiring Soon", "text": "{{steps.check_expiry.output.expiring_count}} products expire within 14 days. Please review."}}',
200
FROM workflows w WHERE w.name = 'Expiry Tracker' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 6. Auto-Reorder with Approval
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, trigger_config, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'Auto-Reorder', 'Check velocity, create PO if stock low, require manager approval.', 'arrow.clockwise', 'active', true, 'schedule', '{"interval_minutes": 1440}', true, 'inventory', ARRAY['inventory', 'purchasing', 'approval'], 15)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'check_velocity', 'tool', true, 'needs_reorder',
'{"tool_name": "inventory", "args_template": {"action": "velocity", "days": 14}}',
0
FROM workflows w WHERE w.name = 'Auto-Reorder' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'needs_reorder', 'condition', false, NULL,
'{"expression": "{{steps.check_velocity.output.items_below_threshold}} > 0", "on_true": "create_po", "on_false": null}',
100
FROM workflows w WHERE w.name = 'Auto-Reorder' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'create_po', 'tool', false, 'approve_po',
'{"tool_name": "supply_chain", "args_template": {"action": "po_create", "notes": "Auto-generated from velocity check"}}',
200
FROM workflows w WHERE w.name = 'Auto-Reorder' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'approve_po', 'approval', false,
'{"title": "Approve Purchase Order", "description": "Auto-generated PO based on inventory velocity. Review and approve.", "timeout_seconds": 86400}',
300
FROM workflows w WHERE w.name = 'Auto-Reorder' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 7. Birthday Promo
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, trigger_config, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'Birthday Promo', 'Daily check for customer birthdays, send personalized promo email.', 'gift', 'active', true, 'schedule', '{"interval_minutes": 1440}', true, 'crm', ARRAY['crm', 'email', 'loyalty', 'birthday'], 15)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'find_birthdays', 'code', true, 'send_each',
'{"language": "javascript", "code": "const today = new Date().toISOString().slice(5, 10); return { date_filter: today };"}',
0
FROM workflows w WHERE w.name = 'Birthday Promo' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'send_each', 'for_each', false,
'{"items_expression": "{{steps.find_birthdays.output.customers}}", "step_key": "send_birthday_email"}',
100
FROM workflows w WHERE w.name = 'Birthday Promo' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'send_birthday_email', 'tool', false,
'{"tool_name": "email", "args_template": {"action": "send", "to": "{{item.email}}", "subject": "Happy Birthday! π Here''s a special gift", "html": "<p>Happy Birthday, {{item.first_name}}! Enjoy 20% off your next purchase.</p>"}}',
200
FROM workflows w WHERE w.name = 'Birthday Promo' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 8. VIP Upgrade
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'VIP Upgrade', 'Upgrade customer tier when spend exceeds threshold, send congratulations.', 'crown', 'active', true, 'event', true, 'crm', ARRAY['crm', 'loyalty', 'vip'], 10)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'check_spend', 'condition', true, NULL,
'{"expression": "{{trigger.total_spend}} >= {{trigger.vip_threshold}}", "on_true": "upgrade_tier", "on_false": null}',
0
FROM workflows w WHERE w.name = 'VIP Upgrade' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'upgrade_tier', 'tool', false, 'send_congrats',
'{"tool_name": "customers", "args_template": {"action": "update", "customer_id": "{{trigger.customer_id}}", "loyalty_tier": "vip"}}',
100
FROM workflows w WHERE w.name = 'VIP Upgrade' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'send_congrats', 'tool', false,
'{"tool_name": "email", "args_template": {"action": "send", "to": "{{trigger.customer_email}}", "subject": "Welcome to VIP! π", "html": "<p>Congratulations! You''ve been upgraded to VIP status. Enjoy exclusive perks and discounts.</p>"}}',
200
FROM workflows w WHERE w.name = 'VIP Upgrade' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 9. Flash Sale
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'Flash Sale', 'Launch a flash sale: update prices, send emails, and post webhook simultaneously.', 'bolt.fill', 'active', true, 'manual', true, 'sales', ARRAY['sales', 'marketing', 'parallel'], 15)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, step_config, position_y)
SELECT w.id, 'launch_sale', 'parallel', true,
'{"step_keys": ["update_prices", "send_emails", "post_webhook"]}',
0
FROM workflows w WHERE w.name = 'Flash Sale' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'update_prices', 'tool', false,
'{"tool_name": "products", "args_template": {"action": "update", "product_id": "{{trigger.product_id}}", "pricing_data": "{{trigger.sale_pricing}}"}}',
100
FROM workflows w WHERE w.name = 'Flash Sale' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'send_emails', 'tool', false,
'{"tool_name": "email", "args_template": {"action": "send_template", "template": "flash_sale", "to": "{{trigger.email_list}}"}}',
100
FROM workflows w WHERE w.name = 'Flash Sale' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'post_webhook', 'webhook_out', false,
'{"url": "{{trigger.webhook_url}}", "method": "POST", "body_template": {"event": "flash_sale_started", "product_id": "{{trigger.product_id}}"}}',
100
FROM workflows w WHERE w.name = 'Flash Sale' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 10. End-of-Day Report
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, trigger_config, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'End-of-Day Report', 'Generate end-of-day sales summary and email to management at 6 PM.', 'clock.badge.checkmark', 'active', true, 'schedule', '{"cron": "0 18 * * *"}', true, 'sales', ARRAY['sales', 'analytics', 'reports'], 10)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'get_sales', 'tool', true, 'format_report',
'{"tool_name": "analytics", "args_template": {"action": "summary", "period": "today"}}',
0
FROM workflows w WHERE w.name = 'End-of-Day Report' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'format_report', 'transform', false, 'email_report',
'{"mapping": {"subject": "End-of-Day Report", "body": "Revenue: ${{steps.get_sales.output.total_revenue}} | Orders: {{steps.get_sales.output.total_orders}} | Avg Order: ${{steps.get_sales.output.avg_order_value}}"}}',
100
FROM workflows w WHERE w.name = 'End-of-Day Report' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'email_report', 'tool', false,
'{"tool_name": "email", "args_template": {"action": "send", "to": "{{trigger.manager_email}}", "subject": "{{steps.format_report.output.subject}}", "text": "{{steps.format_report.output.body}}"}}',
200
FROM workflows w WHERE w.name = 'End-of-Day Report' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 11. License Expiry Alert
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, trigger_config, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'License Expiry Alert', 'Daily check for expiring business/medical licenses, alert before deadline.', 'exclamationmark.shield', 'active', true, 'schedule', '{"interval_minutes": 1440}', true, 'compliance', ARRAY['compliance', 'licenses', 'alerts'], 10)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'check_licenses', 'code', true, 'has_expiring',
'{"language": "javascript", "code": "const thirtyDaysOut = new Date(); thirtyDaysOut.setDate(thirtyDaysOut.getDate() + 30); return { threshold: thirtyDaysOut.toISOString(), check: true };"}',
0
FROM workflows w WHERE w.name = 'License Expiry Alert' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'has_expiring', 'condition', false, NULL,
'{"expression": "{{steps.check_licenses.output.check}} == true", "on_true": "send_alert", "on_false": null}',
100
FROM workflows w WHERE w.name = 'License Expiry Alert' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'send_alert', 'tool', false,
'{"tool_name": "email", "args_template": {"action": "send", "to": "{{trigger.compliance_email}}", "subject": "License Expiry Warning", "text": "One or more licenses are expiring within 30 days. Please renew immediately."}}',
200
FROM workflows w WHERE w.name = 'License Expiry Alert' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 12. ID Verification Flow
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'ID Verification', 'Wait for ID upload, verify with AI agent, require approval, then update customer record.', 'person.badge.shield.checkmark', 'active', true, 'event', true, 'compliance', ARRAY['compliance', 'verification', 'agent', 'approval'], 15)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'wait_upload', 'waitpoint', true, 'verify_id',
'{"label": "Upload government ID", "timeout_seconds": 86400}',
0
FROM workflows w WHERE w.name = 'ID Verification' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'verify_id', 'agent', false, 'approve_result',
'{"agent_id": "{{trigger.agent_id}}", "prompt_template": "Verify the ID document provided. Check for validity and match against customer name: {{trigger.customer_name}}.", "max_turns": 3}',
100
FROM workflows w WHERE w.name = 'ID Verification' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'approve_result', 'approval', false, 'update_customer',
'{"title": "Approve ID Verification", "description": "AI agent verified the ID. Please review and confirm.", "timeout_seconds": 172800}',
200
FROM workflows w WHERE w.name = 'ID Verification' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'update_customer', 'tool', false,
'{"tool_name": "customers", "args_template": {"action": "update", "customer_id": "{{trigger.customer_id}}", "id_verified": true}}',
300
FROM workflows w WHERE w.name = 'ID Verification' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 13. Shift Handoff
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, trigger_config, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'Shift Handoff', 'Generate shift summary at handoff time, email to next shift manager.', 'arrow.left.arrow.right', 'active', true, 'schedule', '{"cron": "0 8,16 * * *"}', true, 'ops', ARRAY['ops', 'shifts', 'reports'], 10)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'get_metrics', 'tool', true, 'format_handoff',
'{"tool_name": "analytics", "args_template": {"action": "summary", "period": "last_7"}}',
0
FROM workflows w WHERE w.name = 'Shift Handoff' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'format_handoff', 'transform', false, 'email_handoff',
'{"mapping": {"summary": "Shift Summary: {{steps.get_metrics.output.total_orders}} orders, ${{steps.get_metrics.output.total_revenue}} revenue"}}',
100
FROM workflows w WHERE w.name = 'Shift Handoff' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'email_handoff', 'tool', false,
'{"tool_name": "email", "args_template": {"action": "send", "to": "{{trigger.next_shift_email}}", "subject": "Shift Handoff Summary", "text": "{{steps.format_handoff.output.summary}}"}}',
200
FROM workflows w WHERE w.name = 'Shift Handoff' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 14. Error Escalation
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'Error Escalation', 'When error count exceeds threshold, email manager and await approval to restart.', 'exclamationmark.bubble', 'active', true, 'event', true, 'ops', ARRAY['ops', 'errors', 'escalation', 'approval'], 15)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'check_errors', 'condition', true, NULL,
'{"expression": "{{trigger.error_count}} > 5", "on_true": "email_manager", "on_false": null}',
0
FROM workflows w WHERE w.name = 'Error Escalation' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'email_manager', 'tool', false, 'await_approval',
'{"tool_name": "email", "args_template": {"action": "send", "to": "{{trigger.manager_email}}", "subject": "Error Escalation: {{trigger.error_count}} errors", "text": "Error threshold exceeded. {{trigger.error_count}} errors detected. Awaiting your approval to restart the service."}}',
100
FROM workflows w WHERE w.name = 'Error Escalation' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'await_approval', 'approval', false,
'{"title": "Approve Service Restart", "description": "Error threshold exceeded. Approve restart?", "timeout_seconds": 3600}',
200
FROM workflows w WHERE w.name = 'Error Escalation' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 15. Stripe Refund Handler
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'Stripe Refund Handler', 'Process Stripe refund webhooks: update order status and email customer.', 'creditcard', 'active', true, 'webhook', true, 'webhook', ARRAY['webhook', 'stripe', 'refunds'], 10)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'is_refund', 'condition', true, NULL,
'{"expression": "{{trigger.type}} == \"charge.refunded\"", "on_true": "update_order", "on_false": null}',
0
FROM workflows w WHERE w.name = 'Stripe Refund Handler' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'update_order', 'tool', false, 'email_customer',
'{"tool_name": "orders", "args_template": {"action": "update", "order_id": "{{trigger.metadata.order_id}}", "status": "refunded"}}',
100
FROM workflows w WHERE w.name = 'Stripe Refund Handler' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'email_customer', 'tool', false,
'{"tool_name": "email", "args_template": {"action": "send", "to": "{{trigger.receipt_email}}", "subject": "Refund Processed", "text": "Your refund of ${{trigger.amount_refunded}} has been processed. Please allow 5-10 business days."}}',
200
FROM workflows w WHERE w.name = 'Stripe Refund Handler' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 16. Shopify Product Sync
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'Shopify Product Sync', 'Sync product updates from Shopify webhook to local catalog.', 'arrow.triangle.2.circlepath', 'active', true, 'webhook', true, 'webhook', ARRAY['webhook', 'shopify', 'sync'], 10)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'map_fields', 'transform', true, 'update_product',
'{"mapping": {"name": "{{trigger.title}}", "description": "{{trigger.body_html}}", "sku": "{{trigger.variants.0.sku}}", "status": "published"}}',
0
FROM workflows w WHERE w.name = 'Shopify Product Sync' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'update_product', 'tool', false,
'{"tool_name": "products", "args_template": {"action": "update", "product_id": "{{trigger.external_id}}", "name": "{{steps.map_fields.output.name}}", "description": "{{steps.map_fields.output.description}}"}}',
100
FROM workflows w WHERE w.name = 'Shopify Product Sync' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 17. Product Describer (AI)
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'AI Product Describer', 'Use AI agent to write compelling product descriptions for all products missing one.', 'wand.and.stars', 'active', true, 'manual', true, 'ai', ARRAY['ai', 'products', 'content'], 100)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'get_products', 'tool', true, 'describe_each',
'{"tool_name": "products", "args_template": {"action": "find", "query": "", "limit": 50}}',
0
FROM workflows w WHERE w.name = 'AI Product Describer' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'describe_each', 'for_each', false,
'{"items_expression": "{{steps.get_products.output}}", "step_key": "write_description"}',
100
FROM workflows w WHERE w.name = 'AI Product Describer' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'write_description', 'agent', false, 'update_product',
'{"agent_id": "{{trigger.agent_id}}", "prompt_template": "Write a compelling, SEO-friendly product description for: {{item.name}}. Category: {{item.category}}. Keep it under 200 words.", "max_turns": 2}',
200
FROM workflows w WHERE w.name = 'AI Product Describer' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'update_product', 'tool', false,
'{"tool_name": "products", "args_template": {"action": "update", "product_id": "{{item.id}}", "description": "{{steps.write_description.output.response}}"}}',
300
FROM workflows w WHERE w.name = 'AI Product Describer' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 18. Support Auto-Reply
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'Support Auto-Reply', 'AI-draft reply for simple support questions, require approval before sending.', 'bubble.left.and.bubble.right', 'active', true, 'event', true, 'ai', ARRAY['ai', 'support', 'email', 'approval'], 15)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'classify_question', 'condition', true, NULL,
'{"expression": "{{trigger.is_simple}} == true", "on_true": "draft_reply", "on_false": null}',
0
FROM workflows w WHERE w.name = 'Support Auto-Reply' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'draft_reply', 'agent', false, 'approve_reply',
'{"agent_id": "{{trigger.agent_id}}", "prompt_template": "Draft a friendly, helpful reply to this customer question:\n\n{{trigger.question}}\n\nKeep it professional and concise.", "max_turns": 2}',
100
FROM workflows w WHERE w.name = 'Support Auto-Reply' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'approve_reply', 'approval', false, 'send_reply',
'{"title": "Approve Auto-Reply", "description": "Review AI-drafted reply before sending to customer.", "timeout_seconds": 3600}',
200
FROM workflows w WHERE w.name = 'Support Auto-Reply' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'send_reply', 'tool', false,
'{"tool_name": "email", "args_template": {"action": "send", "to": "{{trigger.customer_email}}", "subject": "Re: {{trigger.subject}}", "html": "{{steps.draft_reply.output.response}}"}}',
300
FROM workflows w WHERE w.name = 'Support Auto-Reply' AND w.is_template = true
ON CONFLICT DO NOTHING;
-- 19. Onboarding Flow
INSERT INTO workflows (store_id, name, description, icon, status, is_active, trigger_type, is_template, template_category, template_tags, max_steps_per_run)
VALUES (NULL, 'Customer Onboarding', 'Multi-day onboarding: welcome email β tips (day 1) β promo (day 3).', 'figure.walk.arrival', 'active', true, 'event', true, 'multi_step', ARRAY['email', 'onboarding', 'drip'], 15)
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, is_entry_point, on_success, step_config, position_y)
SELECT w.id, 'welcome_email', 'tool', true, 'wait_1d',
'{"tool_name": "email", "args_template": {"action": "send", "to": "{{trigger.customer_email}}", "subject": "Welcome aboard! π", "html": "<p>Welcome, {{trigger.customer_name}}! We''re glad to have you.</p>"}}',
0
FROM workflows w WHERE w.name = 'Customer Onboarding' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'wait_1d', 'delay', false, 'tips_email',
'{"seconds": 86400}',
100
FROM workflows w WHERE w.name = 'Customer Onboarding' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'tips_email', 'tool', false, 'wait_3d',
'{"tool_name": "email", "args_template": {"action": "send", "to": "{{trigger.customer_email}}", "subject": "Getting started tips π‘", "html": "<p>Here are some tips to get the most out of your account...</p>"}}',
200
FROM workflows w WHERE w.name = 'Customer Onboarding' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, on_success, step_config, position_y)
SELECT w.id, 'wait_3d', 'delay', false, 'promo_email',
'{"seconds": 259200}',
300
FROM workflows w WHERE w.name = 'Customer Onboarding' AND w.is_template = true
ON CONFLICT DO NOTHING;
INSERT INTO workflow_steps (workflow_id, step_key, step_type, step_config, position_y)
SELECT w.id, 'promo_email', 'tool', false,
'{"tool_name": "email", "args_template": {"action": "send", "to": "{{trigger.customer_email}}", "subject": "A special offer just for you π", "html": "<p>Thanks for being with us! Here''s 15% off your next order.</p>"}}',
400
FROM workflows w WHERE w.name = 'Customer Onboarding' AND w.is_template = true
ON CONFLICT DO NOTHING;