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.
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.
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
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).
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.