import { ManifestBuilder, ManifestFunction, Workflow, workflowAction, } from '@rippling/rippling-sdk/lib/manifest'; const manifest = new ManifestBuilder({ key: 'workflow_creation', name: 'Workflow creation', description: 'Manual, scheduled, and Slack-triggered workflow examples', }); const workflowFn = new ManifestFunction(manifest, { apiName: 'follow_up', name: 'Follow up', description: 'Runs after a short delay', }); new Workflow(manifest, { definitionId: 'delayed_follow_up', title: 'Delayed follow up', trigger: { automation_event_type: 'AUTOMATION_EVENT_TYPE_MANUAL' }, graph: { root_node_id: 'wait', nodes: { wait: workflowAction('Sleep', { timeUnit: 'MINUTES', sleepTime: 5 }, { next: 'follow_up' }), follow_up: workflowAction( 'RunFunction', { function_id: workflowFn.getApiName(), parameters: {}, output_schema: {} }, { processing_context: { function_context: { function_api_name: workflowFn.getApiName() } } }, ), }, }, // For a single RunFunction node, `function: workflowFn` is the shorter alternative. }); const prepare = new ManifestFunction(manifest, { apiName: 'prepare_week', name: 'Prepare week', description: 'Computes the current UTC week window', code: `import { FunctionResponse } from '@rippling/rippling-sdk'; export async function onRipplingEvent() { const start = new Date(); start.setUTCHours(0, 0, 0, 0); start.setUTCDate(start.getUTCDate() - (start.getUTCDay() + 6) % 7); const end = new Date(start); end.setUTCDate(start.getUTCDate() + 7); return new FunctionResponse({ body: { startsAt: start.toISOString(), endsAt: end.toISOString() } }); }`, }); const finish = new ManifestFunction(manifest, { apiName: 'finish_weekly_run', name: 'Finish weekly run', description: 'Records the completion time of the workflow', code: `import { FunctionResponse } from '@rippling/rippling-sdk'; export async function onRipplingEvent() { return new FunctionResponse({ body: { completedAt: new Date().toISOString() } }); }`, }); new Workflow(manifest, { definitionId: 'weekly_window', title: 'Weekly window', description: 'Compute the weekly window, conditionally wait, and stamp completion', trigger: { automation_event_type: 'AUTOMATION_EVENT_TYPE_SCHEDULED', scheduled_trigger: { frequency: 'SCHEDULED_TRIGGER_FREQUENCY_TYPE_WEEKLY', timezone: 'UTC', supported_role_states: ['ROLE_STATE_ACTIVE'], weekly_schedule: { hour_of_day: 9, minute_of_hour: 30, day_of_week: [1] }, }, }, graph: { root_node_id: 'prepare', nodes: { prepare: workflowAction( 'RunFunction', { function_id: prepare.getApiName(), parameters: {}, output_schema: {} }, { processing_context: { function_context: { function_api_name: prepare.getApiName() } }, next: 'check_employees', }, ), check_employees: workflowAction( 'IfElse', { condition: { baseObject: 'Employee', rql: 'Count()' } }, { switch: { branches: [{ rql_formula: 'Count()', node_id: 'wait' }], default_node: 'finish' } }, ), wait: workflowAction('Sleep', { timeUnit: 'MINUTES', sleepTime: 5 }, { next: 'finish' }), finish: workflowAction( 'RunFunction', { function_id: finish.getApiName(), parameters: {}, output_schema: {} }, { processing_context: { function_context: { function_api_name: finish.getApiName(), summary: { text: 'Stamp the completion time' }, }, }, summary: { text: 'Complete the weekly window', bullets: [{ text: 'Record the UTC completion time' }], }, }, ), }, }, }); const recordReceipt = new ManifestFunction(manifest, { apiName: 'record_slack_receipt', name: 'Record Slack receipt', description: 'Returns a receipt timestamp for a matching Slack message', code: `import { FunctionResponse } from '@rippling/rippling-sdk'; export async function onRipplingEvent() { return new FunctionResponse({ body: { receivedAt: new Date().toISOString() } }); }`, }); new Workflow(manifest, { definitionId: 'slack_help_receipt', title: 'Slack help receipt', function: recordReceipt, trigger: { automation_event_type: 'AUTOMATION_EVENT_TYPE_INTEGRATION', integration_trigger: { provider: 'INTEGRATION_TRIGGER_PROVIDER_SLACK', slack_trigger: { event_type: 'SLACK_TRIGGER_EVENT_TYPE_MESSAGE_POSTED', // Replace this sample ID with a channel from your connected Slack workspace. channel_ids: ['C0123456789'], message_text_regex: '^help\\b', include_thread_replies: false, }, }, }, }); console.log(manifest.preview());