Expand description
§botcore
A flexible and efficient bot engine framework for building event-driven bots in Rust.
§Overview
botcore
is a high-performance, type-safe framework for building event-driven bots in Rust.
It provides a modular architecture that makes it easy to create, test, and maintain bot
applications that can react to various events in real-time.
§Features
-
🚀 High Performance
- Built on top of Tokio for maximum concurrency
- Efficient event processing pipeline
- Configurable channel capacities for backpressure control
-
🔧 Modular Architecture
- Plug-and-play components
- Easy to extend and customize
- Clear separation of concerns
-
📊 Observability
- Built-in Prometheus metrics
- Performance monitoring
- Error tracking and reporting
§Architecture
The framework is built around three main traits:
Collector
: Sources that produce eventsStrategy
: Components that process events and decide on actionsExecutor
: Components that execute actions
These components are orchestrated by the Engine
, which manages
the flow of events and actions through the system.
§Quick Start
use botcore::{Engine, Result};
use botcore::types::{Collector, CollectorStream, Strategy, Executor};
use async_trait::async_trait;
use tokio_stream;
#[tokio::main]
async fn main() -> Result<()> {
// Create a new engine with custom channel capacities
let mut engine = Engine::<MyEvent, MyAction>::new()
.with_event_channel_capacity(1024)
.with_action_channel_capacity(1024);
// Add components
engine.add_collector(Box::new(MyCollector));
engine.add_strategy(Box::new(MyStrategy));
engine.add_executor(Box::new(MyExecutor));
// Run the engine
let mut join_set = engine.run().await?;
// Wait for all tasks to complete
while join_set.join_next().await.is_some() {}
Ok(())
}
§Modules
engine
: Core engine implementation that orchestrates event flowtypes
: Core traits and types for building botserror
: Error types and handlingmetrics
: Prometheus metrics for monitoring
§Error Handling
The crate uses a custom Result
type that wraps BotError
for comprehensive error handling. All errors are categorized and include context
for easier debugging.
§Metrics
The engine automatically collects Prometheus metrics for:
- Event processing latency
- Action execution latency
- Queue sizes
- Error counts
- Total events processed
- Total actions executed
§Best Practices
-
Event Design
- Keep events small and focused
- Include necessary context
- Use appropriate serialization
-
Strategy Implementation
- Handle state carefully
- Implement proper error handling
- Keep processing logic modular
-
Execution
- Implement retries for transient failures
- Handle rate limiting
- Log important state changes