Elsa v3 - Custom activity with blocking event

106 Views Asked by At

I'm trying to create Custom activity called Approval this activity functionality is to create an approval task in the backend db using external Api, send email to the approvers for approval, suspend the activity and based on the approval by approvers, it should then set the flow Approved or Declined.

Below is the custom Activity logic but its not complete. I'm unable to comeup with logic to suspend Activity. All of the examples says to create an Activity of type Event but that is only possible in the Workflow . Is it possible to suspend inside a custom activity without having to create a new Workflow?

[FlowNode("Approved","Declined")]
public class Approval : Activity
{
    [Input(
       Description = "The contract type to use when sending the request.",
       UIHint = InputUIHints.DropDown,
       UIHandlers = [typeof(ApprovalTypeUIHandler), typeof(RefreshUIHandler)]
   )]
    public Input<string> ApprovalType { get; set; }
    [Input(Description ="ReferenceId of the entity that is sent for approval.")]
    public Input<long> ReferenceId { get; set; }
    public Input<List<string>> Approvers { get; set; }

    public Approval(string approvalType) { ApprovalType = new (approvalType); }

    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
    {

        //call the externalApi to save tasks in the DB

        //send email to the approvers
                   
        // Suspend it until approvers approve/decline it. Create a bookmark. The created bookmark will be stored in the workflow state.
        var bookmark = context.CreateBookmark();

        // after approvers approval based on the state (Approved or Declined) choose the path
        //some how get this Approval state.??

        if (Approved)
            await context.CompleteActivityWithOutcomesAsync("Approved");
        else
            await context.CompleteActivityWithOutcomesAsync("Declined");
         
        //return base.ExecuteAsync(context);
    }
0

There are 0 best solutions below