Asynchronous Background Task Integration for Botpr...
# 👀feature-requests
r
Implement a system that allows Botpress chatbots to initiate, manage, and integrate results from asynchronous background tasks during ongoing conversations. Key Components: 1. Background Task Initiation: - Enable chatbots to trigger background tasks without interrupting the conversation flow. - Allow tasks to run independently of the main conversation thread. 2. Asynchronous Data Retrieval: - Support both quick, synchronous data fetching and long-running, asynchronous processes. - Implement a mechanism for long polling or webhooks to handle extended operations. 3. Result Integration: - Develop a method to inject task results into the current conversation context. - Allow the chatbot to access and evaluate these results in real-time. 4. Intelligent Response Handling: - Enable the chatbot to decide whether to present the task results to the user based on relevance and conversation context. - Provide options for immediate or delayed presentation of results. 5. Conversation Continuity: - Ensure smooth conversation flow while background tasks are in progress. - Allow the bot to continue interacting with the user without waiting for task completion. 6. Task Status Monitoring: - Implement a system to track the status of ongoing background tasks. - Provide mechanisms for timeout handling and error management. Use Case Example: While a user is chatting with the bot about travel plans, the bot initiates a background task to check for flight deals. The task runs asynchronously, and when results are available, they are seamlessly integrated into the conversation. The bot then decides whether to present these deals based on the current context of the discussion. Benefits: - Enhanced user experience with more responsive and informed chatbots. - Ability to handle complex, time-consuming operations without disrupting conversations. - Increased flexibility in managing and utilizing external data sources and services.
l
r
I dunno about this timeout workaround, but i actually developed a polling system that works well and can even await for a few minutes also giving the user feedback while it happnes. This solves for me any long polling or external API, the downside it is a custom code i have to copy from one place to another If i need it in other bots.
I'm not clear what setTimeout will do here, since the request is still not returned and it stuck on a card that hangs. Are you suggesting to run a setTimeout function that will check if a request has been resolved, so how do you run a request not in a card in an async fashion? would love to see your solution in depth or show the code please 🙂 thanks
Actually the polling im doing is an external LLM call, so i will also try to use the custom llm feature i hear already integrated (didn't test it yet) to see if it does allow long time for the response... if it doesn't I will still need my custom solution
l
@rhythmic-jewelry-90685 the timeout in the demo bot is supposed to be a placeholder for some real API call, and while waiting for that API's response, the bot doesn't have to stop, and it can exhibit different behavior depending on some real-time parameter (in the example -- the time that has passed since the call was made), and then can change its behavior and utilize the data in its responses, once the data is retrieved. This is to illustrate that Botpress is asynchronous out of the box, and apart from lack of UI, you can get a large chunk of the mentioned behavior (background tasks running, asynchronously collecting data, showing different behavior once the data is collected etc.) just by using code blocks.
r
@limited-gpu-21450 Hey, It didn't work for me, or maybe i do not understand it properly, when i put code that takes too long to exit, the card hangs. I was not able to understand how to run code that runs "somewhere" and then resumes. I also tried setTimeout but it still runs in the context of the card and if does not resolve in 50 seconds the card hangs.
I did try with setTimeout before, it was to no avail, the axios request takes 2 minutes and it hangs the card. Lets consider setTimeout, runs in the background, to what card it belongs? if you transition to another card while the timeout is start, and it fails, which card does the running method belongs to? How would you treat errors in the process / logs / etc? If you want to prove your point and i will be glad to learn new ways to use botpress, please update you demo code not with a dummy setTimeout, but real reaquest to asset that takes 2 minutes to get.
5 Views