Using a Zenphi Flow to handle Flow Errors
Flows can error for a variety of reasons. Maybe a Connection needs re-authenticating, or a referenced file or folder no longer exists. By default, Zenphi will send an email alert to the publisher of the flow whenever a flow fails.
However, sometimes you might like to do more with the error. For example, you might like to create a new support ticket in your ticketing system, or log the error in a Google sheet.
Using the new Zenphi Mail trigger, we can now create a Zenphi Flow that is triggered whenever another flow has an error.
First, we need to create a new Flow that will be triggered by an incoming email. It’s best to do this in a separate/dedicated Zenphi Workspace. Otherwise an error in this flow could trigger itself in an endless loop.
Configure the trigger and specify an email alias. E.g. FlowErrors.
Select the Conditional Run tab and limit this flow to only run when receiving emails from the sender: noreply@zenphi.io. This will prevent it from being invoked by other senders.
Since this Flow will be receiving Zenphi Flow Error email alerts, we need to extract the key information from the email. The Flow Name, Workspace URL and a link to the Flow Run page.
We do this using the action Find Value With RegEx. We’re going to need one for each piece of information we want to extract from the HTML email body. I also created 3 workflow variables to store this information so I can use it later in the flow.
I’ve specified the RegEx patterns you will need below, however, if you ever need to make your own RegEx patterns, Gen AI is a great tool for this. I used Google AI studio, uploaded the content of an HTML email and asked the question “What is the RegEx expression to extract the flow name?”. Just like magic, AI gave me the RegEx pattern 🙂.
Patterns:
To extract the Workflow Name: There was an unexpected error with the flow '(?<WorkflowName>[^']+)'.
To extract the link to the Workflow Run: <a href="(?<FlowRunLink>[^"]+)".+>\s*View run details\s*<\/a>
To extract the Workspace URL: <span.+>Workspace: (?<WorkspaceURL>[^\s<]+) <\/span>
Now we have the key pieces of information, we can use the full power of Zenphi to do whatever we like. In my case, I posted to a Google Chat Support space.
Tip: To get the Space ID, navigate to the space in a browser and copy the ID from the URL.
Once you’ve finished adding your logic, publish the flow and make note of the email address.
Now, navigate to the Zenphi workspace where your production flows are running. Click the Settings cog and navigate to Flows Error Handling. In the Additional Emails field, add the email address of your error handling flow.
Now, whenever a Flow error occurs in this workspace, the Error Handling flow is triggered by the alert email and a new message is posted to our Google Chat Space. Of course, you can modify the Error Handling flow to do much, much more. Limited only by your imagination!