pub struct Bot { /* private fields */ }Expand description
A configured WhatsApp session with its event handlers already wired, ready to be started.
This is the high-level entry point and what most applications should use.
Build one with Bot::builder: the typestate BotBuilder takes the
storage backend (the only required dependency with the default cargo
features), the pairing callbacks, and the message/event handlers, then
hands back a Bot.
Starting it is a single call. Bot::run drives the session on the
current task until logout or shutdown; Bot::spawn starts it on the
runtime instead and returns a BotHandle you can await, shut down
gracefully, or abort. Both consume the Bot, so handlers are registered
at build time, not afterwards.
let bot = Bot::builder()
.with_backend(SqliteStore::new("whatsapp.db").await?)
.on_message(|ctx| async move {
let _ = ctx.reply("pong").await;
})
.build()
.await?;
bot.run().await;Handlers registered through the builder (on_message, on_event, …)
receive typed Event payloads. Anything the
builder does not expose is reachable on the underlying client via
Bot::client, which stays valid after the bot is started.
Implementations§
Source§impl Bot
impl Bot
pub fn builder() -> BotBuilder<MissingBackend, Provided, Provided, Provided>
pub fn client(&self) -> Arc<Client> ⓘ
Sourcepub async fn run(self)
pub async fn run(self)
Run the bot on the current task until it shuts down (logout, or
Client::disconnect called on Bot::client from another task).
To run in the background instead, use Bot::spawn.
Coroutines are LocalCopy across crates: a consumer crate that awaits this future re-codegens the whole state machine graph behind it in its own binary. The boxed barrier below type-erases the graph in a plain (linker-shared) function, so callers poll through a vtable and the graph is compiled once, here. One allocation per process.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Bot
impl !Unpin for Bot
impl !UnsafeUnpin for Bot
impl !UnwindSafe for Bot
impl Freeze for Bot
impl Send for Bot
impl Sync for Bot
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read more