Skip to main content
Defined in: testing/chaos.ts:445 An IProvider that wraps another one and delivers its traffic adversarially (see the module docs and ChaosOptions). Pass it to new Bot({ provider }) and keep driving the wrapped provider (chaos.inner.incoming(...)). Optional provider capabilities (typing, markRead, downloadMedia, …) are exposed only when the wrapped provider has them, so feature detection in the Bot keeps working.

Type Parameters

Implements

Constructors

Constructor

Defined in: testing/chaos.ts:493

Parameters

Returns

ChaosProvider<P>

Throws

when an option is out of range.

Properties

inner

Defined in: testing/chaos.ts:447 The wrapped provider (drive it to simulate inbound traffic).

id

Defined in: testing/chaos.ts:449 Same id as the wrapped provider (store namespaces stay unchanged).

Implementation of

IProvider.id

capabilities

Defined in: testing/chaos.ts:451 Same capabilities object as the wrapped provider.

Implementation of

IProvider.capabilities

seed

Defined in: testing/chaos.ts:453 Seed in use.

log

Defined in: testing/chaos.ts:455 Everything the kit injected, in order.

delivered

Defined in: testing/chaos.ts:457 Every inbound event actually delivered to listeners (copies and replays included), in delivery order.

ingest?

Defined in: testing/chaos.ts:459 Push ingress for webhook transports (Cloud API POST, Telegram/Discord webhook, Discord interaction endpoint). The host HTTP server calls this with the raw body (and, optionally, the request headers for signature checks); the provider normalizes and emits via onEvent. May return a value the host can use as the HTTP status (e.g. 200 accepted / 403 bad signature). Socket-first providers (Baileys, Discord gateway) omit it.

Parameters

Returns

unknown

Implementation of

IProvider.ingest

downloadMedia?

Defined in: testing/chaos.ts:460 Lazy media retrieval behind one signature for every download model.

Parameters

Returns

Promise<Buffer<ArrayBufferLike> | ReadableStream>

Implementation of

IProvider.downloadMedia

serializeMediaRef?

Defined in: testing/chaos.ts:461 Durable journaling (BotConfig.durability): turn a live MediaRef into a JSON-safe, versioned reference that rehydrateMediaRef can rebuild in another process, so a replayed message (crash recovery, background retry) can still download its media. Synchronous, cheap and side-effect free; a throw counts as “not durable”. Return undefined for a ref that must not be journaled (e.g. view-once media). Never include credentials: the result is stored at rest with the inbound record.

Parameters

Returns

| SerializedMediaRef | undefined

Implementation of

IProvider.serializeMediaRef

rehydrateMediaRef?

Defined in: testing/chaos.ts:462 Rebuild the MediaRef of a replayed message from what serializeMediaRef wrote. ref is the journaled ref without its token. Pure decoding: it must not need the transport to be connected. stored comes from storage and is UNTRUSTED: reject an invalid, unknown-version or tampered value with a ProviderError.

Parameters

Returns

| MediaRef | Promise<MediaRef>

Implementation of

IProvider.rehydrateMediaRef

getMessage?

Defined in: testing/chaos.ts:463 Read-back seam for poll aggregation, quote-body resolution, retry decrypt. Providers that don’t need it no-op / omit it. Replaces the constructor- injected getMessage callback baked into BaileysProvider today.

Parameters

Returns

Promise< | InboundMessage<unknown> | undefined>

Implementation of

IProvider.getMessage

markRead?

Defined in: testing/chaos.ts:464

Parameters

Returns

Promise<void>

Implementation of

IProvider.markRead

typing?

Defined in: testing/chaos.ts:465

Parameters

Returns

Promise<void>

Implementation of

IProvider.typing

deleteMessage?

Defined in: testing/chaos.ts:466

Parameters

Returns

Promise<void>

Implementation of

IProvider.deleteMessage

editMessage?

Defined in: testing/chaos.ts:467

Parameters

Returns

Promise<SendResult<unknown>>

Implementation of

IProvider.editMessage

sendDraft?

Defined in: testing/chaos.ts:468 Show (or update) an ephemeral, not-yet-sent preview of a message being generated. Same draftId → the same draft is updated in place. A draft is NOT a message: the caller must still send() the final text. Only for providers with capabilities.streaming === 'draft'; rejects (typed error) where the transport refuses drafts (e.g. Telegram groups), and the caller then falls back to edits or chunks.

Parameters

Returns

Promise<void>

Implementation of

IProvider.sendDraft

acknowledgeInteraction?

Defined in: testing/chaos.ts:469

Parameters

Returns

Promise<void>

Implementation of

IProvider.acknowledgeInteraction

canRenderForm?

Defined in: testing/chaos.ts:470 Whether a form OutboundContent for form (and opts.nativeId) can be rendered natively right now, e.g. whether a WhatsApp Flow is mapped to it. Only consulted when capabilities.forms === 'native'; when it returns false, an auto-mode flow().form() asks field by field without sending (and failing) a form message first. Absent = every form is renderable.

Parameters

Returns

boolean

Implementation of

IProvider.canRenderForm

textFormatFor?

Defined in: testing/chaos.ts:471 Rich-text dialect of one chat, for providers that serve several channels with different markup through one instance (e.g. Twilio: whatsapp: chats render WhatsApp markup, SMS chats render none). Return undefined when the chat’s format is unknown; the core then falls back to capabilities.textFormat. Exposed as ctx.textFormat. Must be synchronous and cheap (it runs once per inbound message). Absent = every chat uses capabilities.textFormat.

Parameters

Returns

TextFormat | undefined

Implementation of

IProvider.textFormatFor

Methods

start()

Defined in: testing/chaos.ts:534

Returns

Promise<void>

Implementation of

IProvider.start

stop()

Defined in: testing/chaos.ts:537 Cancels every pending delivery, buffered or held event, then stops the wrapped provider.

Returns

Promise<void>

Implementation of

IProvider.stop

onEvent()

Defined in: testing/chaos.ts:547 Subscribe to the normalized event stream. Returns an unsubscriber.

Parameters

Returns

() => void

Implementation of

IProvider.onEvent

send()

Defined in: testing/chaos.ts:558 Send through the wrapped provider unless chaos decides this attempt fails (scripted attempts, probability, or the connection is down), in which case it rejects with a typed ProviderError and nothing reaches the wrapped provider’s outbox.

Parameters

Returns

Promise<SendResult<unknown>>

Implementation of

IProvider.send

disconnect()

Defined in: testing/chaos.ts:577 Simulate a connection drop: emits { state: 'closed', reason }, then holds inbound and fails sends (per options) until reconnect. A finite downtimeMs schedules the reconnect automatically; the default for a manual drop is to stay down until reconnect() is called.

Parameters

Returns

void

reconnect()

Defined in: testing/chaos.ts:602 End a simulated drop: emits connecting then ready, redelivers the last replayOnReconnect events (offline-sync duplicates), then delivers what was held while down, in arrival order.

Returns

void

replay()

Defined in: testing/chaos.ts:621 Redeliver (fresh copies of) the last count delivered inbound events — an explicit webhook retry.

Parameters

Returns

void

flush()

Defined in: testing/chaos.ts:630 Deliver whatever sits in the reorder window right now (permuted as configured).

Returns

void

settle()

Defined in: testing/chaos.ts:648 Wait (real timers) until no chaos delivery, reorder flush, scheduled reconnect or delayed send is pending, plus one macrotask so listeners can dispatch. Events held by an indefinite drop do not count as pending.

Parameters

Returns

Promise<void>

Throws

if still busy after timeoutMs (default 5000).

Accessors

selfId

Get Signature

Defined in: testing/chaos.ts:524 The wrapped provider’s self id (null when it has none: never undefined, see IProvider.selfId).
Returns
string | null The bot’s own user id once connected (for group mention matching). Optional.

Implementation of

IProvider.selfId

connection

Get Signature

Defined in: testing/chaos.ts:526 The wrapped provider’s debug connection handle.
Returns
unknown A single primary connection handle for DEBUGGING ONLY. Not a structural guarantee of exactly one connection (Discord may hold many shard sockets). Core must NOT reach through this for behavior.

Implementation of

IProvider.connection

connected

Get Signature

Defined in: testing/chaos.ts:528 false while a simulated drop is in effect.
Returns
boolean

sendAttempts

Get Signature

Defined in: testing/chaos.ts:530 Number of send() calls so far (failed ones included).
Returns
number

pending

Get Signature

Defined in: testing/chaos.ts:532 Scheduled deliveries, reorder/reconnect timers and delayed sends still outstanding.
Returns
number