bob_chat/lib.rs
1//! # Bob Chat
2//!
3//! Platform-agnostic chat abstractions for the
4//! [Bob Agent Framework](https://github.com/longcipher/bob).
5//!
6//! ## Overview
7//!
8//! `bob-chat` provides the structured chat layer that sits between chat
9//! platform APIs (Slack, Discord, Telegram, CLI, etc.) and the agent loop.
10//! It ships a trait-based adapter model, a central event-driven orchestrator
11//! ([`ChatBot`]), and rich message primitives.
12//!
13//! ## Features
14//!
15//! - **[`ChatAdapter`] trait** — implement once per platform; covers posting, editing, deleting,
16//! reactions, ephemeral messages, DMs, modals, file uploads, and event streaming.
17//! - **[`ChatBot`] orchestrator** — register adapters and typed handlers, then call
18//! [`ChatBot::run`] to poll all adapters concurrently and dispatch events.
19//! - **[`ChatEvent`]** — seven event variants (Message, Mention, Reaction, Action, SlashCommand,
20//! ModalSubmit, ModalClose).
21//! - **[`ThreadHandle`]** — scoped handle passed to handlers for replying, subscribing to threads,
22//! and managing ephemeral messages with DM fallback.
23//! - **Rich messages** — [`CardElement`] (buttons, sections, images, fields) with a plain-text
24//! fallback renderer.
25//! - **Modals** — [`ModalElement`] with text inputs, selects, and radio selects.
26//! - **Emoji** — [`WellKnownEmoji`] (35 variants) with platform-specific format maps and a
27//! custom-emoji escape hatch.
28//! - **Streaming** — [`TextStream`] and [`fallback_stream`] for progressive message delivery via
29//! post-then-edit.
30//! - **Attachments** — [`Attachment`], [`FileUpload`] for file handling.
31//! - **Error types** — [`ChatError`] with adapter, transport, rate-limit, auth, not-found,
32//! not-supported, and closed variants.
33//!
34//! ## Module Map
35//!
36//! | Module | Purpose |
37//! |--------|---------|
38//! | [`adapter`] | `ChatAdapter` trait definition |
39//! | [`bot`] | `ChatBot` orchestrator and handler registration |
40//! | [`card`] | Card/rich-message element types |
41//! | [`emoji`] | Emoji types and well-known mappings |
42//! | [`error`] | `ChatError` enum |
43//! | [`event`] | `ChatEvent` variants and event structs |
44//! | [`file`](mod@file) | Attachment and file upload types |
45//! | [`message`] | Message types (postable, incoming, sent, ephemeral) |
46//! | [`modal`] | Modal form dialog types |
47//! | [`stream`] | Streaming text types |
48//! | [`thread`] | `ThreadHandle` for in-handler interaction |
49//!
50//! ## Quick Start
51//!
52//! ```rust,no_run
53//! use bob_chat::{ChatBot, ChatBotConfig};
54//!
55//! # async fn example() -> Result<(), bob_chat::ChatError> {
56//! let mut bot = ChatBot::new(ChatBotConfig::default());
57//!
58//! // Register a mention handler.
59//! bot.on_mention(|thread, message| async move {
60//! let _ = thread.post("Hello! You said: ".to_owned() + &message.text).await;
61//! });
62//!
63//! // Add platform adapters and run.
64//! // bot.add_adapter(my_slack_adapter);
65//! // bot.run().await?;
66//! # Ok(())
67//! # }
68//! ```
69
70pub mod adapter;
71pub mod bot;
72pub mod card;
73pub mod emoji;
74pub mod error;
75pub mod event;
76pub mod file;
77pub mod message;
78pub mod modal;
79pub mod stream;
80pub mod thread;
81
82#[cfg(test)]
83pub(crate) mod test_utils;
84
85pub use adapter::ChatAdapter;
86/// Re-export channel types from `bob_core` for convenience.
87pub use bob_core::channel::{Channel, ChannelError, ChannelMessage, ChannelOutput};
88pub use bot::{ChatBot, ChatBotConfig};
89pub use card::{
90 ActionElement, ActionsElement, ButtonElement, ButtonStyle, CardChild, CardElement,
91 FieldElement, FieldsElement, ImageElement, SectionElement, TextElement, TextStyle,
92 render_card_as_text,
93};
94pub use emoji::{DefaultEmojiResolver, EmojiFormats, EmojiResolver, EmojiValue, WellKnownEmoji};
95pub use error::ChatError;
96pub use event::{
97 ActionEvent, ChatEvent, ModalCloseEvent, ModalSubmitEvent, ReactionEvent, SlashCommandEvent,
98};
99pub use file::{Attachment, AttachmentKind, FileUpload};
100pub use message::{
101 AdapterPostableMessage, Author, EphemeralMessage, IncomingMessage, PostableMessage, SentMessage,
102};
103pub use modal::{
104 ModalChild, ModalElement, RadioSelectElement, SelectElement, SelectOption, TextInputElement,
105};
106pub use stream::{StreamOptions, TextStream, fallback_stream};
107pub use thread::ThreadHandle;