Skip to main content

BotBuilder

Struct BotBuilder 

Source
pub struct BotBuilder<B = Missing, T = Missing, H = Missing, R = Missing> { /* private fields */ }
Expand description

Builder for Bot using the typestate pattern.

The four type parameters (B, T, H, R) track whether the required fields (backend, transport_factory, http_client, runtime) have been provided. The build() method is only available when all four are Provided, turning missing-field errors into compile-time errors.

Implementations§

Source§

impl<T, H, R> BotBuilder<Missing, T, H, R>

Source

pub fn with_backend( self, backend: Arc<dyn Backend>, ) -> BotBuilder<Provided, T, H, R>

Use a backend implementation for storage. This is the only way to configure storage - there are no defaults.

§Arguments
  • backend - The backend implementation that provides all storage operations
§Example
let backend = Arc::new(SqliteStore::new("whatsapp.db").await?);
let bot = Bot::builder()
    .with_backend(backend)
    .build()
    .await?;
Source§

impl<B, H, R> BotBuilder<B, Missing, H, R>

Source

pub fn with_transport_factory<F>( self, factory: F, ) -> BotBuilder<B, Provided, H, R>
where F: TransportFactory + 'static,

Set the transport factory for creating network connections. This is required to build a bot.

§Arguments
  • factory - The transport factory implementation
§Example
use whatsapp_rust_tokio_transport::TokioWebSocketTransportFactory;

let bot = Bot::builder()
    .with_backend(backend)
    .with_transport_factory(TokioWebSocketTransportFactory::new())
    .build()
    .await?;
Source§

impl<B, T, R> BotBuilder<B, T, Missing, R>

Source

pub fn with_http_client<C>(self, client: C) -> BotBuilder<B, T, Provided, R>
where C: HttpClient + 'static,

Configure the HTTP client used for media operations and version fetching.

§Arguments
  • client - The HTTP client implementation
§Example
use whatsapp_rust_ureq_http_client::UreqHttpClient;

let bot = Bot::builder()
    .with_backend(backend)
    .with_http_client(UreqHttpClient::new())
    .build()
    .await?;
Source§

impl<B, T, H> BotBuilder<B, T, H, Missing>

Source

pub fn with_runtime<Rt: Runtime>( self, runtime: Rt, ) -> BotBuilder<B, T, H, Provided>

Set the async runtime implementation to use.

This is required to build a bot.

Source§

impl<B, T, H, R> BotBuilder<B, T, H, R>

Source

pub fn on_event<F, Fut>(self, handler: F) -> Self
where F: Fn(Event, Arc<Client>) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,

Source

pub fn with_enc_handler<Eh>( self, enc_type: impl Into<String>, handler: Eh, ) -> Self
where Eh: EncHandler + 'static,

Register a custom handler for a specific encrypted message type

§Arguments
  • enc_type - The encrypted message type (e.g., “frskmsg”)
  • handler - The handler implementation for this type
§Returns

The updated BotBuilder

Source

pub fn with_version(self, version: (u32, u32, u32)) -> Self

Override the WhatsApp version used by the client.

By default, the client will automatically fetch the latest version from WhatsApp’s servers. Use this method to force a specific version instead.

§Arguments
  • version - A tuple of (primary, secondary, tertiary) version numbers
§Example
let bot = Bot::builder()
    .with_backend(backend)
    .with_version((2, 3000, 1027868167))
    .build()
    .await?;
Source

pub fn with_device_props( self, os_name: Option<String>, version: Option<AppVersion>, platform_type: Option<PlatformType>, ) -> Self

Override the device properties sent to WhatsApp servers. This allows customizing how your device appears on the linked devices list.

§Arguments
  • os_name - Optional OS name (e.g., “macOS”, “Windows”, “Linux”)
  • version - Optional app version as AppVersion struct
  • platform_type - Optional platform type that determines the device name shown on the phone’s linked devices list (e.g., Chrome, Firefox, Safari, Desktop)

Important: The platform_type determines what device name is shown on the phone. Common values: Chrome, Firefox, Safari, Edge, Desktop, Ipad, etc. If not set, defaults to Unknown which shows as “Unknown device”.

You can pass None for any parameter to keep the default value.

§Example
use waproto::whatsapp::device_props::{self, PlatformType};

// Show as "Chrome" on linked devices
let bot = Bot::builder()
    .with_backend(backend)
    .with_device_props(
        Some("macOS".to_string()),
        Some(device_props::AppVersion {
            primary: Some(2),
            secondary: Some(0),
            tertiary: Some(0),
            ..Default::default()
        }),
        Some(PlatformType::Chrome),
    )
    .build()
    .await?;

// Show as "Desktop" on linked devices
let bot = Bot::builder()
    .with_backend(backend)
    .with_device_props(None, None, Some(PlatformType::Desktop))
    .build()
    .await?;
Source

pub fn with_pair_code(self, options: PairCodeOptions) -> Self

Configure pair code authentication to run automatically after connecting.

When set, the pair code request will be sent automatically after establishing a connection, and the pairing code will be dispatched via Event::PairingCode. This runs concurrently with QR code pairing - whichever completes first wins.

§Arguments
  • options - Configuration for pair code authentication
§Example
use whatsapp_rust::pair_code::{PairCodeOptions, PlatformId};

let bot = Bot::builder()
    .with_backend(backend)
    .with_transport_factory(transport)
    .with_http_client(http_client)
    .with_pair_code(PairCodeOptions {
        phone_number: "15551234567".to_string(),
        show_push_notification: true,
        custom_code: Some("ABCD1234".to_string()),
        platform_id: PlatformId::Chrome,
        platform_display: "Chrome (Linux)".to_string(),
    })
    .on_event(|event, client| async move {
        match event {
            Event::PairingCode { code, timeout } => {
                println!("Enter this code on your phone: {}", code);
            }
            _ => {}
        }
    })
    .build()
    .await?;
Source

pub fn skip_history_sync(self) -> Self

Skip processing of history sync notifications from the phone.

When enabled, the client will acknowledge all incoming history sync notifications (so the phone considers them delivered) but will not download or process any historical data (INITIAL_BOOTSTRAP, RECENT, FULL, PUSH_NAME, etc.). A debug log entry is emitted for each skipped notification. This is useful for bot use cases where message history is not needed.

Default: false (history sync is processed normally).

§Example
let bot = Bot::builder()
    .with_backend(backend)
    .with_transport_factory(transport)
    .with_http_client(http_client)
    .skip_history_sync()
    .build()
    .await?;
Source

pub fn with_push_name(self, name: impl Into<String>) -> Self

Set an initial push name on the device before connecting.

This is included in the ClientPayload during registration, allowing the mock server to deterministically assign phone numbers based on push name (same push name = same phone, enabling multi-device testing).

Source

pub fn with_cache_config(self, config: CacheConfig) -> Self

Configure cache TTL and capacity settings.

By default, all caches match WhatsApp Web behavior. Use this method to customize cache durations for your use case.

§Example
use whatsapp_rust::{CacheConfig, CacheEntryConfig};

// Disable TTL for group and device caches (good for bots with few groups)
let bot = Bot::builder()
    .with_backend(backend)
    .with_transport_factory(transport)
    .with_http_client(http_client)
    .with_cache_config(CacheConfig {
        group_cache: CacheEntryConfig::new(None, 1_000),
        device_cache: CacheEntryConfig::new(None, 5_000),
        ..Default::default()
    })
    .build()
    .await?;
Source§

impl BotBuilder<Provided, Provided, Provided, Provided>

Source

pub async fn build(self) -> Result<Bot, BotBuilderError>

Auto Trait Implementations§

§

impl<B, T, H, R> Freeze for BotBuilder<B, T, H, R>

§

impl<B = Missing, T = Missing, H = Missing, R = Missing> !RefUnwindSafe for BotBuilder<B, T, H, R>

§

impl<B, T, H, R> Send for BotBuilder<B, T, H, R>
where B: Send, T: Send, H: Send, R: Send,

§

impl<B, T, H, R> Sync for BotBuilder<B, T, H, R>
where B: Sync, T: Sync, H: Sync, R: Sync,

§

impl<B, T, H, R> Unpin for BotBuilder<B, T, H, R>
where B: Unpin, T: Unpin, H: Unpin, R: Unpin,

§

impl<B, T, H, R> UnsafeUnpin for BotBuilder<B, T, H, R>

§

impl<B = Missing, T = Missing, H = Missing, R = Missing> !UnwindSafe for BotBuilder<B, T, H, R>

Blanket Implementations§

Source§

impl<T> AggregateExpressionMethods for T

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more