-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update 15. Wait for result.md (#210)
added the description on how to handle webhook failures cases
- Loading branch information
1 parent
669fef4
commit 7318c8d
Showing
1 changed file
with
70 additions
and
2 deletions.
There are no files selected for viewing
72 changes: 70 additions & 2 deletions
72
docs/3. Product Features/03. Flows/2. Flow Actions/15. Wait for result.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,75 @@ | ||
> ### **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](https://api.glific.com/#89f5f6e6-9bdc-48c2-96c5-ad8c1f7a834b) 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. | ||
|
||
<img width="501" alt="image" src="https://github.com/user-attachments/assets/dde19cf2-7675-4b79-8fe4-c6a7509295da"/> | ||
|
||
### 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. | ||
|
||
<img width="501" alt="image" src="https://github.com/user-attachments/assets/30330d7d-2ba1-46c7-aa19-d95bf9165579"/> | ||
|
||
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](https://api.glific.com/#89f5f6e6-9bdc-48c2-96c5-ad8c1f7a834b) 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. | ||
|
||
<img width="501" alt="image" src="https://github.com/user-attachments/assets/d8e6b0b5-3506-42fc-abd2-7fca1d3caf30"/> | ||
|
||
## 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 | ||
|
||
<img width="504" alt="image" src="https://github.com/user-attachments/assets/bf1d167f-b18b-46f3-afd4-77a0031d2f7e"/> | ||
|
||
### 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](https://api.glific.com/#4a9a72a5-01d3-4af4-a7e0-7b50a67c6dac) to get the auth token for using other apis like resume flow api. | ||
- Use [get all flows](https://api.glific.com/#e0f1066e-471b-47de-b83d-0003387e9032) api with either name or uuid of the flow as filter for | ||
fetching the `Flow Id`. | ||
- Use [contacts apis](https://api.glific.com/#42b55eb3-e58e-488f-bc55-7f2510d81ce3) for fetching the contactId | ||
|
||
|
||
|
||
|
||
**The `Wait for result` node is used to get results from webhook results. If there is a delay in the response from webhook, then it will wait to get the result according to the time set in `Wait for result.` Earlier, the flow used to break if there was a delay in the response from the webhook. But now, it will not break and will wait for the result from the webhook. Resume flow API is used to make this feature, which will queue the request. If there is no webhook, then `Wait for result` will work as `Wait for time`** | ||
|
||
![image](https://user-images.githubusercontent.com/32592458/218254915-246fc560-c516-40c4-a29b-0d9a5ad69b21.png) |