How to Program a Manual Approval Step into a Workflow?

This topic was automatically generated from Slack. You can find the original thread here.

Hello; how can one program a manual approval step into a workflow? Ideally, the workflow pauses, a text or email is sent to me, a response is returned, like “approved”, and then the workflow continues.

could probably achieve this using two workflows, the first (main) workflow would have a “pause” step and send an email

the second (approval) workflow would be triggered via an email

the reply-to address of the email sent from the main workflow would be the trigger address of the approval workflow

can you tell @U06LFHJB4T1 about how $.flow.suspend() and how they can use it to build an “approval” workflow? Their original question:

Hello; how can one program a manual approval step into a workflow? Ideally, the workflow pauses, a text or email is sent to me, a response is returned, like “approved”, and then the workflow continues.

To implement a manual approval step in a Pipedream workflow using $.flow.suspend(), you can follow the example provided in the Pipedream documentation. This method allows you to pause the workflow until you manually approve or cancel the continuation of the workflow. Here’s how you can do it: export default defineComponent({ async run({ $ }) { // Suspend the workflow and generate URLs for manual approval or cancellation const { resume_url, cancel_url } = $.flow.suspend(); // Send an email with the approval and cancellation links $.send.email({ subject: "Please approve this important workflow", text: `Click here to approve the workflow: ${resume_url}, and cancel here: ${cancel_url}`, }); // The workflow is suspended here. It will resume or cancel based on your action on the email links. }, }); In this example, when the workflow reaches the step with $.flow.suspend(), it pauses. An email is sent to you with two links: one to resume (approve) the workflow and another to cancel it. Clicking on the resume link continues the workflow from where it was suspended, while clicking on the cancel link stops the workflow entirely. This method is effective for creating workflows that require manual intervention or approval before proceeding with further actions. For more details, please visit Pipedream’s documentation on suspending workflows.

is that legit? The email piece will actually work? Link and all?

Yep!

Give it a whirl

Another key component here I forgot to mention is that the email should include the previous image and caption that was generated (which is what is being approved) but also allow for an edit to either one, which obviously complicates things.

You may need to modify the code example based on what you need to do, but you can also define html code instead of text and pass that to $.send.email() : Email - Pipedream

There would need to be a trigger somehow with the original workflow to “redo” things, no?

This approach would keep the logic in a single workflow. So once the step calls $.flow.suspend(), the workflow’s execution is paused until either you call the resume or cancel endpoints, which are returned via those URLs in the example code, or at the timeout that you specify (can be 30 minutes, or 24 hours, or whatever you want, from 1ms to 1 year).

Righttt, so do you have any suggestions on what I should look into if I want to make this work with edits?

Sorry, what needs to be edited?

That which would be sent in the email for approval; for example, a caption

Say it’s not approved. It needs edits

What should happen if something needs edits?

And is that different than just not approving?

It would be more than not approving, yes.

So, here is the workflow, simplified:

  1. An article is sent to Pipedream via email and webhook
  2. The article is summarized, and a caption is produced
  3. The caption is sent for approval
  4. The caption is approved OR the caption is revised and sent back
  1. The flow continues

Got it, I think multiple workflows might make things easier? I know $.flow.rerun() supports passing context back, so you could theoretically send your edit via an “approve with this edit” type of link, but I don’t think suspend does.