AgentIM — Rust Multi-Channel IM Bridge
AgentIM is a Rust bridge that connects chat platforms to a local AI agent backend (Codex). It supports 8+ platforms through webhooks and long polling, with session persistence, context limits, and routing rules.AgentIM
Rust IM bridge — 8+ platforms, session persistence, health endpoints.
Supported Platforms
| Platform | Delivery | Verification |
|---|---|---|
| Telegram | Long polling (getUpdates) | Bot token |
| Discord | POST /discord | Ed25519 |
| Feishu/Lark | POST /feishu | Verification token + URL challenge |
| Slack | POST /slack | HMAC-SHA256 |
| DingTalk | POST /dingtalk | HMAC-SHA256 |
| LINE | POST /line | HMAC-SHA256 |
POST /qq | — | |
| WeChat Work | POST /wechatwork | — |
Tech Stack
| Component | Technology | Purpose |
|---|---|---|
| HTTP server | Axum 0.7 | Routing, middleware, webhooks |
| Async runtime | Tokio (full features) | Async I/O, timers, channels |
| HTTP client | Reqwest | Outbound API calls |
| Concurrency | DashMap | Lock-free concurrent state |
| CLI | Clap 4 | Command-line argument parsing |
| Logging | Tracing + Tracing-subscriber | Structured logging |
| Serialization | Serde + Serde_json | JSON codec |
| Error handling | Anyhow + Thiserror | Ergonomic error types |
| Auth | HMAC | Webhook signature verification |
Architecture
Key Design Patterns
Platform Abstraction
Each platform handler implements a common trait:Session Persistence
User sessions are stored inDashMap — a lock-free concurrent hashmap:
DashMap provides sharded locks internally, so concurrent reads/writes from multiple Tokio tasks don’t block each other. Much faster than
Mutex<HashMap> for IM workloads.Context Trimming
Chat history grows over time. AgentIM trims context to stay within token limits:Webhook Signature Verification
Each platform has its own signature scheme. AgentIM validates before processing:Routing Rules
Channel-based routing lets you direct messages to different behaviors:Docker Deployment
Health Endpoints
Best Practices
- Platform trait abstraction — Common interface per platform, easy to add new ones
- DashMap for concurrent state — Lock-free, fast for multi-platform message handling
- Context trimming — Keep history within token limits to avoid runaway memory
- Webhook signature verification — Always validate before trusting inbound messages
- Health + readiness endpoints — Let orchestrators (Docker, K8s) monitor service state
- Shared-secret auth — Simple but effective for internal service communication
- Tokio full features — IM bridges need timers, I/O, and sync — don’t trim the runtime
References
- AgentIM repo — Full source code
- Axum Docs
- DashMap
- Codex app-server transport
