Progress Reporting
Keep users informed about long-running operations with progress indicators
Progress Reporting
When building bots that perform lengthy operations, it’s important to keep users informed about the bot’s progress. The lil’bots platform provides a simple yet powerful progress reporting mechanism that displays a progress bar to users while your bot is running.
How It Works
Progress reporting works by allowing your bot to send updates about its completion status. These updates are displayed to the user as a progress bar, helping them understand how far along the bot is in completing its task.
Progress is represented as a decimal value between 0 (not started) and 1 (completed).
Implementation
JavaScript Runtime
In JavaScript-based bots, you can use the updateProgress
function provided by the lilbots library:
Python Runtime
In Python-based bots, you can use the update_progress
function from the lilbots module:
Best Practices
1. Use Reasonable Update Frequency
Update progress at meaningful intervals. Updating too frequently (e.g., in tight loops) can create unnecessary network traffic, while updating too infrequently can leave users wondering if the bot is still working.
2. Handle Indeterminate Progress
For operations where you can’t determine precise progress, consider using fixed increments or milestone-based reporting:
3. Provide Additional Context (when possible)
In some cases, you might want to provide additional context alongside the progress update:
Example: File Processing Bot
Here’s a complete example of a bot that processes multiple files and reports progress:
Limitations
- Progress values must be between 0 and 1 (inclusive). Values outside this range will be clamped.
- The progress bar is a visual indicator only and doesn’t affect the execution of your bot.
- Progress updates are best-effort and might be delayed or dropped in case of network issues.
Remember that the progress reporting feature is particularly useful for bots that perform long-running tasks, helping to provide users with confidence that your bot is working as expected.