Skip to the content.

Human (User) Workflow Sample

This sample demonstrates how to create workflows that require human interaction using the WorkflowCore.Users extension.

What this sample shows

The Workflow

public class HumanWorkflow : IWorkflow
{
    public void Build(IWorkflowBuilder<object> builder)
    {
        builder
            .StartWith(context => ExecutionResult.Next())
            .UserTask("Do you approve", data => @"domain\bob")
                .WithOption("yes", "I approve").Do(then => then
                    .StartWith(context => Console.WriteLine("You approved"))
                )
                .WithOption("no", "I do not approve").Do(then => then
                    .StartWith(context => Console.WriteLine("You did not approve"))
                )
                .WithEscalation(x => TimeSpan.FromSeconds(20), x => @"domain\frank", action => action
                    .StartWith(context => Console.WriteLine("Escalated task"))
                    .Then(context => Console.WriteLine("Sending notification..."))
                    )
            .Then(context => Console.WriteLine("end"));
    }
}

How it works

  1. Task Assignment: The workflow creates a user task with the prompt “Do you approve” and assigns it to domain\bob

  2. User Options: Two options are provided:
    • “yes” with label “I approve” - executes approval workflow
    • “no” with label “I do not approve” - executes rejection workflow
  3. Escalation: If the task is not completed within 20 seconds, it automatically escalates to domain\frank and executes the escalation workflow

  4. User Interaction: The program demonstrates how to:
    • Get open user actions using host.GetOpenUserActions(workflowId)
    • Display options to the user
    • Publish user responses using host.PublishUserAction(key, user, value)

Key Features

Dependencies

This sample requires the WorkflowCore.Users extension package, which provides the human workflow capabilities.

Use Cases

This pattern is useful for: