Wait for result
1 minute read
Beginner
“Wait for Result” Node
Handle webhooks that take longer time to execute via the wait for result node.
Introduction
Webhooks
are a common way of integrating different systems and automating workflows.
However, some webhook calls may take longer to execute than others, and the default timeout for a webhook call (5 sec) in a flow may not be sufficient.
In such cases, it is necessary to use a different approach to handle longer webhook calls
.
To address this issue, we have created a new node called Wait for Results
that allows you to pause a flow until a longer webhook call is completed at your side (Not Glific).
This document explains how to use the Wait for Results node in your flows and provides steps for implementing it.
Using the Wait for Results Node
The Wait for Results node allows you to pause a flow until a longer webhook call is completed.
When you define this node in your flow, the flow will pause at that node for the amount of time we set(minimum of 1 min to maximum upto days), and once the Resume Flow API call is made, the flow will resume for the same contact.
You can use this action for multiple purposes, but a longer webhook is a common use case.
Example Flow
Here is an example flow that uses the Wait for Results node to handle a longer webhook call.
We have added a time of 15 mins
for the flow to pause while the long webhook call is completed.
But if the webhook call gets completed before 15 mins
, then the flow will resume.
In the above flow, the webhook with url https://longwebhook.com might be a task that have to do multiple tasks probably and take a few mins.
So here orgs can instantly return a 200
so that the flow will move to Wait for result.
Once the flow is in Wait for result it will wait for 15 mins
as we declared above.
Now once the required tasks are done from org’s backend (for ex querying from RAG model), they can hit Glific’s Resume flow for a contact from their backend with the flowId, contactId and the results we need to send back to the flow, so that we can use those in the subsequent nodes as shown in the fourth and last node in the above flow.
Sending and Saving the flow results
In our flow, the webhook node results are stored in the result
variable as shown in the second node of the flow.
So we have to send the results inside a result
key from the api too as shown in the above postman snippet.
NOTE: The value of result
param in the api should be a valid stringified json like
References
Prerequisites needed for using resume flow api.
Api url would be "https://api.shortcode.glific.com/ where shortcode is your glific subdomain, for ex https://api.xxxxxx.glific.com/".
- Use login api to get the auth token for using other apis like resume flow api.
- Use get all flows api with either name or uuid of the flow as filter for
fetching the
Flow Id
. - Use contacts apis for fetching the contactId