BaileysEx (baileys_ex v0.1.0-alpha.7)

Copy Markdown View Source

Public facade for the BaileysEx connection runtime and major feature surfaces.

Quick Start

alias BaileysEx.Auth.NativeFilePersistence
alias BaileysEx.Connection.Transport.MintWebSocket

{:ok, persisted_auth} =
  NativeFilePersistence.use_native_file_auth_state("tmp/baileys_auth")
parent = self()

{:ok, connection} =
  BaileysEx.connect(
    persisted_auth.state,
    Keyword.merge(persisted_auth.connect_opts, [
      transport: {MintWebSocket, []},
      on_qr: fn qr -> IO.puts("Scan QR: #{qr}") end,
      on_connection: fn update ->
        IO.inspect({:connection, update})
        send(parent, {:connection_update, update})
      end
    ])
  )

_creds_unsubscribe =
  BaileysEx.subscribe_raw(connection, fn events ->
    if Map.has_key?(events, :creds_update) do
      {:ok, latest_auth_state} = BaileysEx.auth_state(connection)
      :ok = persisted_auth.save_creds.(latest_auth_state)
    end
  end)

receive do
  {:connection_update, %{connection: :open}} -> :ok
after
  30_000 -> raise "connection did not open"
end

unsubscribe =
  BaileysEx.subscribe(connection, fn
    {:message, message} -> IO.inspect(message, label: "incoming")
    {:connection, update} -> IO.inspect(update, label: "connection")
    _other -> :ok
  end)

unsubscribe.()
:ok = BaileysEx.disconnect(connection)

Persistence Backends

Use BaileysEx.Auth.NativeFilePersistence.use_native_file_auth_state/1 for the recommended durable file-backed setup in Elixir-first apps.

Use BaileysEx.Auth.FilePersistence.use_multi_file_auth_state/1 when you need the Baileys-compatible JSON multi-file auth layout and helper semantics.

Custom SQL/NoSQL backends remain supported through BaileysEx.Auth.Persistence, BaileysEx.Auth.KeyStore, and a matching signal_store_module. Advanced custom store modules must implement the explicit transaction-handle contract in BaileysEx.Signal.Store; the built-in helpers already wire the correct store for you.

Advanced callers can obtain the raw socket transport tuple via queryable/1 and pass it directly to the lower-level feature modules.

Outbound send_message/4 and send_status/3 use the built-in production Signal adapter by default when the auth state includes signed_identity_key, signed_pre_key, and registration_id. Use :signal_repository or :signal_repository_adapter only when you need to override that default.

Summary

Types

Opaque WAProto WebMessageInfo struct accepted by media download and retry helpers.

Functions

Archive or unarchive a chat via the app-state patch path.

Return the current auth state snapshot from the connection store.

Fetch a business catalog.

Delete one or more business products.

Fetch the business profile for a WhatsApp JID.

Clear a chat history via app-state sync.

Accept a legacy community invite code.

Fetch all participating communities.

Fetch linked groups for a community or subgroup.

Fetch community invite metadata without joining.

Fetch the current community invite code.

Switch whether only admins or all members can add participants to a community.

Add, remove, promote, or demote community participants.

Fetch the pending membership-approval request list for a community.

Revoke the current community invite code and return the new one.

Revoke a v4 community invite for a specific invited user.

Update a community announcement or locked setting.

Enable or disable disappearing messages for a community.

Start a connection runtime and optionally attach convenience callbacks.

Stop a running connection runtime.

Download media into memory.

Download media directly to a file path.

Return the connection event emitter pid.

Fetch the account blocklist.

Fetch the latest version published by Baileys' current Defaults/index.ts.

Fetch the latest WhatsApp Web client revision from web.whatsapp.com/sw.js.

Fetch profile status text for one or more JIDs.

Accept a legacy group invite code.

Fetch group invite metadata without joining.

Fetch the current group invite code.

Switch whether only admins or all members can add participants.

Add, remove, promote, or demote group participants.

Fetch the pending join-request list for a group.

Revoke the current group invite code and return the new one.

Revoke a v4 group invite for a specific invited user.

Update a group announcement or locked setting.

Enable or disable disappearing messages for a group.

Mute a chat until the given Unix timestamp, or pass nil to unmute.

Fetch newsletter metadata by :jid or :invite key.

React to a newsletter message or remove an existing reaction.

Check which phone numbers are registered on WhatsApp.

Subscribe to a contact or group presence feed.

Return the underlying socket transport tuple used by feature modules.

Send read receipts for the provided message keys using current privacy settings.

Remove the profile picture for yourself or a group.

Request a phone-number pairing code from the active socket.

Send a message to a WhatsApp JID through the coordinator-managed runtime.

Send an availability or chatstate update.

Send a status update through the status@broadcast fanout path.

Send a WAM analytics buffer or BaileysEx.WAM.BinaryInfo through the active socket.

Return the wrapped Signal store for the connection when present.

Star or unstar one or more messages in a chat.

Subscribe to friendly high-level events.

Subscribe to raw buffered event maps.

Upload and set the business cover photo.

Set the default disappearing-message duration in seconds.

Update the app-state privacy toggle that disables server-side link previews.

Request media re-upload and return the updated message with refreshed URLs.

Update online-visibility privacy.

Update the current account push name via app-state sync.

Types

connection()

@type connection() :: GenServer.server()

unsubscribe_fun()

@type unsubscribe_fun() :: (-> :ok)

web_message_info()

@type web_message_info() :: struct()

Opaque WAProto WebMessageInfo struct accepted by media download and retry helpers.

Functions

archive_chat(connection, jid, archive?, last_messages, opts \\ [])

@spec archive_chat(connection(), String.t(), boolean(), list(), keyword()) ::
  :ok | {:error, term()}

Archive or unarchive a chat via the app-state patch path.

auth_state(connection)

@spec auth_state(connection()) :: {:ok, map()} | {:error, :store_not_available}

Return the current auth state snapshot from the connection store.

creds_update events are mirrored into the store before public subscribers run, so callers can safely read auth_state/1 from inside those callbacks.

business_catalog(connection, opts \\ [])

@spec business_catalog(
  connection(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Fetch a business catalog.

business_collections(connection, jid \\ nil, limit \\ 51, opts \\ [])

@spec business_collections(connection(), String.t() | nil, pos_integer(), keyword()) ::
  {:ok, map()} | {:error, term()}

Fetch business catalog collections.

business_order_details(connection, order_id, token, opts \\ [])

@spec business_order_details(connection(), String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Fetch business order details.

business_product_create(connection, product, opts \\ [])

@spec business_product_create(connection(), map(), keyword()) ::
  {:ok, map()} | {:error, term()}

Create a business product.

business_product_delete(connection, product_ids, opts \\ [])

@spec business_product_delete(connection(), [String.t()], keyword()) ::
  {:ok, %{deleted: non_neg_integer()}} | {:error, term()}

Delete one or more business products.

business_product_update(connection, product_id, updates, opts \\ [])

@spec business_product_update(connection(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, term()}

Update a business product.

business_profile(connection, jid, opts \\ [])

@spec business_profile(connection(), String.t(), keyword()) ::
  {:ok, map() | nil} | {:error, term()}

Fetch the business profile for a WhatsApp JID.

clear_chat(connection, jid, last_messages, opts \\ [])

@spec clear_chat(connection(), String.t(), list(), keyword()) ::
  :ok | {:error, term()}

Clear a chat history via app-state sync.

community_accept_invite(connection, code, opts \\ [])

@spec community_accept_invite(connection(), String.t(), keyword()) ::
  {:ok, String.t() | nil} | {:error, term()}

Accept a legacy community invite code.

community_accept_invite_v4(connection, key, invite_message, opts \\ [])

@spec community_accept_invite_v4(connection(), String.t() | map(), map(), keyword()) ::
  {:ok, String.t() | nil} | {:error, term()}

Accept a v4 community invite.

community_create(connection, subject, description \\ nil, opts \\ [])

@spec community_create(connection(), String.t(), String.t() | nil, keyword()) ::
  {:ok, map()} | {:error, term()}

Create a community.

community_create_group(connection, subject, participants, parent_community_jid, opts \\ [])

@spec community_create_group(
  connection(),
  String.t(),
  [String.t()],
  String.t(),
  keyword()
) ::
  {:ok, map() | nil} | {:error, term()}

Create a linked subgroup inside a community.

community_fetch_all_participating(connection, opts \\ [])

@spec community_fetch_all_participating(
  connection(),
  keyword()
) :: {:ok, %{required(String.t()) => map()}} | {:error, term()}

Fetch all participating communities.

community_fetch_linked_groups(connection, jid, opts \\ [])

@spec community_fetch_linked_groups(connection(), String.t(), keyword()) ::
  {:ok,
   %{community_jid: String.t(), is_community: boolean(), linked_groups: [map()]}}
  | {:error, term()}

Fetch linked groups for a community or subgroup.

community_get_invite_info(connection, code, opts \\ [])

@spec community_get_invite_info(connection(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Fetch community invite metadata without joining.

community_invite_code(connection, community_jid, opts \\ [])

@spec community_invite_code(connection(), String.t(), keyword()) ::
  {:ok, String.t() | nil} | {:error, term()}

Fetch the current community invite code.

community_join_approval_mode(connection, community_jid, mode, opts \\ [])

@spec community_join_approval_mode(connection(), String.t(), :on | :off, keyword()) ::
  :ok | {:error, term()}

Toggle join-approval mode for a community.

community_leave(connection, community_jid, opts \\ [])

@spec community_leave(connection(), String.t(), keyword()) :: :ok | {:error, term()}

Leave a community.

community_member_add_mode(connection, community_jid, mode, opts \\ [])

@spec community_member_add_mode(
  connection(),
  String.t(),
  :admin_add | :all_member_add,
  keyword()
) :: :ok | {:error, term()}

Switch whether only admins or all members can add participants to a community.

community_metadata(connection, community_jid, opts \\ [])

@spec community_metadata(connection(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Fetch community metadata.

community_participants_update(connection, community_jid, jids, action, opts \\ [])

@spec community_participants_update(
  connection(),
  String.t(),
  [String.t()],
  :add | :remove | :promote | :demote,
  keyword()
) :: {:ok, [map()]} | {:error, term()}

Add, remove, promote, or demote community participants.

community_request_participants_list(connection, community_jid, opts \\ [])

@spec community_request_participants_list(connection(), String.t(), keyword()) ::
  {:ok, [map()]} | {:error, term()}

Fetch the pending membership-approval request list for a community.

community_request_participants_update(connection, community_jid, jids, action, opts \\ [])

@spec community_request_participants_update(
  connection(),
  String.t(),
  [String.t()],
  :approve | :reject,
  keyword()
) :: {:ok, [map()]} | {:error, term()}

Approve or reject pending community membership requests.

community_revoke_invite(connection, community_jid, opts \\ [])

@spec community_revoke_invite(connection(), String.t(), keyword()) ::
  {:ok, String.t() | nil} | {:error, term()}

Revoke the current community invite code and return the new one.

community_revoke_invite_v4(connection, community_jid, invited_jid, opts \\ [])

@spec community_revoke_invite_v4(connection(), String.t(), String.t(), keyword()) ::
  :ok | {:error, term()}

Revoke a v4 community invite for a specific invited user.

community_setting_update(connection, community_jid, setting, opts \\ [])

@spec community_setting_update(
  connection(),
  String.t(),
  :announcement | :not_announcement | :locked | :unlocked,
  keyword()
) :: :ok | {:error, term()}

Update a community announcement or locked setting.

community_toggle_ephemeral(connection, community_jid, expiration, opts \\ [])

@spec community_toggle_ephemeral(
  connection(),
  String.t(),
  non_neg_integer(),
  keyword()
) ::
  :ok | {:error, term()}

Enable or disable disappearing messages for a community.

community_update_description(connection, community_jid, description, opts \\ [])

@spec community_update_description(
  connection(),
  String.t(),
  String.t() | nil,
  keyword()
) ::
  :ok | {:error, term()}

Update or clear a community description.

community_update_subject(connection, community_jid, subject, opts \\ [])

@spec community_update_subject(connection(), String.t(), String.t(), keyword()) ::
  :ok | {:error, term()}

Update a community subject.

connect(auth_state, opts \\ [])

@spec connect(
  term(),
  keyword()
) :: {:ok, pid()} | {:error, term()}

Start a connection runtime and optionally attach convenience callbacks.

Pass a real :transport such as {BaileysEx.Connection.Transport.MintWebSocket, []} when you want an actual WhatsApp connection. Without it, the default transport returns {:error, :transport_not_configured}.

Use BaileysEx.Auth.NativeFilePersistence.use_native_file_auth_state/1 for the recommended durable built-in file setup.

Use BaileysEx.Auth.FilePersistence.use_multi_file_auth_state/1 when you want the Baileys-compatible JSON multi-file helper instead.

Custom persistence backends remain supported through BaileysEx.Auth.Persistence plus a compatible signal_store_module. Advanced custom store modules must follow the explicit transaction-handle contract in BaileysEx.Signal.Store.

Supported callback options:

  • :on_connection receives each connection_update payload
  • :on_qr receives QR strings extracted from connection_update
  • :on_message receives each message from messages_upsert
  • :on_event receives the raw buffered event map

These convenience callbacks stay attached for the lifetime of the connection runtime. Use subscribe/2 or subscribe_raw/2 when you need an explicit unsubscribe handle.

create_call_link(connection, type, event \\ nil, opts \\ [])

@spec create_call_link(connection(), :audio | :video, map() | nil, keyword()) ::
  {:ok, String.t() | nil} | {:error, term()}

Create an audio or video call link.

delete_chat(connection, jid, last_messages, opts \\ [])

@spec delete_chat(connection(), String.t(), list(), keyword()) ::
  :ok | {:error, term()}

Delete a chat via app-state sync.

delete_message_for_me(connection, jid, message_key, timestamp, delete_media? \\ false, opts \\ [])

@spec delete_message_for_me(
  connection(),
  String.t(),
  map(),
  integer(),
  boolean(),
  keyword()
) ::
  :ok | {:error, term()}

Delete a specific message for the current device.

disconnect(connection)

@spec disconnect(connection()) :: :ok | {:error, term()}

Stop a running connection runtime.

download_media(message, opts \\ [])

@spec download_media(
  map(),
  keyword()
) :: {:ok, binary()} | {:error, term()}

Download media into memory.

download_media_to_file(message, path, opts \\ [])

@spec download_media_to_file(map(), Path.t(), keyword()) ::
  {:ok, Path.t()} | {:error, term()}

Download media directly to a file path.

event_emitter(connection)

@spec event_emitter(connection()) ::
  {:ok, pid()} | {:error, :event_emitter_not_available}

Return the connection event emitter pid.

fetch_blocklist(connection, opts \\ [])

@spec fetch_blocklist(
  connection(),
  keyword()
) :: {:ok, [String.t()]} | {:error, term()}

Fetch the account blocklist.

fetch_latest_baileys_version(opts \\ [])

@spec fetch_latest_baileys_version(keyword()) :: map()

Fetch the latest version published by Baileys' current Defaults/index.ts.

fetch_latest_wa_web_version(opts \\ [])

@spec fetch_latest_wa_web_version(keyword()) :: map()

Fetch the latest WhatsApp Web client revision from web.whatsapp.com/sw.js.

fetch_status(connection, jids, opts \\ [])

@spec fetch_status(connection(), [String.t()], keyword()) ::
  {:ok, [map()]} | {:error, term()}

Fetch profile status text for one or more JIDs.

group_accept_invite(connection, code, opts \\ [])

@spec group_accept_invite(connection(), String.t(), keyword()) ::
  {:ok, String.t() | nil} | {:error, term()}

Accept a legacy group invite code.

group_accept_invite_v4(connection, key, invite_message, opts \\ [])

@spec group_accept_invite_v4(connection(), String.t() | map(), map(), keyword()) ::
  {:ok, String.t() | nil} | {:error, term()}

Accept a v4 group invite.

group_create(connection, subject, participants, opts \\ [])

@spec group_create(connection(), String.t(), [String.t()], keyword()) ::
  {:ok, map()} | {:error, term()}

Create a group.

group_fetch_all_participating(connection, opts \\ [])

@spec group_fetch_all_participating(
  connection(),
  keyword()
) :: {:ok, %{required(String.t()) => map()}} | {:error, term()}

Fetch all participating groups.

group_get_invite_info(connection, code, opts \\ [])

@spec group_get_invite_info(connection(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Fetch group invite metadata without joining.

group_invite_code(connection, group_jid, opts \\ [])

@spec group_invite_code(connection(), String.t(), keyword()) ::
  {:ok, String.t() | nil} | {:error, term()}

Fetch the current group invite code.

group_join_approval_mode(connection, group_jid, mode, opts \\ [])

@spec group_join_approval_mode(connection(), String.t(), :on | :off, keyword()) ::
  :ok | {:error, term()}

Toggle join-approval mode for a group.

group_leave(connection, group_jid)

@spec group_leave(connection(), String.t()) :: :ok | {:error, term()}

Leave a group.

group_member_add_mode(connection, group_jid, mode, opts \\ [])

@spec group_member_add_mode(
  connection(),
  String.t(),
  :admin_add | :all_member_add,
  keyword()
) ::
  :ok | {:error, term()}

Switch whether only admins or all members can add participants.

group_metadata(connection, group_jid, opts \\ [])

@spec group_metadata(connection(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Fetch group metadata.

group_participants_update(connection, group_jid, jids, action, opts \\ [])

@spec group_participants_update(
  connection(),
  String.t(),
  [String.t()],
  :add | :remove | :promote | :demote,
  keyword()
) :: {:ok, [map()]} | {:error, term()}

Add, remove, promote, or demote group participants.

group_request_participants_list(connection, group_jid, opts \\ [])

@spec group_request_participants_list(connection(), String.t(), keyword()) ::
  {:ok, [map()]} | {:error, term()}

Fetch the pending join-request list for a group.

group_request_participants_update(connection, group_jid, jids, action, opts \\ [])

@spec group_request_participants_update(
  connection(),
  String.t(),
  [String.t()],
  :approve | :reject,
  keyword()
) :: {:ok, [map()]} | {:error, term()}

Approve or reject pending group join requests.

group_revoke_invite(connection, group_jid, opts \\ [])

@spec group_revoke_invite(connection(), String.t(), keyword()) ::
  {:ok, String.t() | nil} | {:error, term()}

Revoke the current group invite code and return the new one.

group_revoke_invite_v4(connection, group_jid, invited_jid, opts \\ [])

@spec group_revoke_invite_v4(connection(), String.t(), String.t(), keyword()) ::
  :ok | {:error, term()}

Revoke a v4 group invite for a specific invited user.

group_setting_update(connection, group_jid, setting, opts \\ [])

@spec group_setting_update(
  connection(),
  String.t(),
  :announcement | :not_announcement | :locked | :unlocked,
  keyword()
) :: :ok | {:error, term()}

Update a group announcement or locked setting.

group_toggle_ephemeral(connection, group_jid, expiration, opts \\ [])

@spec group_toggle_ephemeral(connection(), String.t(), non_neg_integer(), keyword()) ::
  :ok | {:error, term()}

Enable or disable disappearing messages for a group.

group_update_description(connection, group_jid, description, opts \\ [])

@spec group_update_description(connection(), String.t(), String.t() | nil, keyword()) ::
  :ok | {:error, term()}

Update or clear a group description.

group_update_subject(connection, group_jid, subject, opts \\ [])

@spec group_update_subject(connection(), String.t(), String.t(), keyword()) ::
  :ok | {:error, term()}

Update a group subject.

mark_chat_read(connection, jid, read?, last_messages, opts \\ [])

@spec mark_chat_read(connection(), String.t(), boolean(), list(), keyword()) ::
  :ok | {:error, term()}

Mark a chat read or unread.

mute_chat(connection, jid, duration, opts \\ [])

@spec mute_chat(connection(), String.t(), integer() | nil, keyword()) ::
  :ok | {:error, term()}

Mute a chat until the given Unix timestamp, or pass nil to unmute.

newsletter_admin_count(connection, newsletter_jid, opts \\ [])

@spec newsletter_admin_count(connection(), String.t(), keyword()) ::
  {:ok, non_neg_integer()} | {:error, term()}

Fetch newsletter admin count.

newsletter_change_owner(connection, newsletter_jid, new_owner_jid, opts \\ [])

@spec newsletter_change_owner(connection(), String.t(), String.t(), keyword()) ::
  :ok | {:error, term()}

Change the newsletter owner.

newsletter_create(connection, name, description \\ nil, opts \\ [])

@spec newsletter_create(connection(), String.t(), String.t() | nil, keyword()) ::
  {:ok, map()} | {:error, term()}

Create a newsletter.

newsletter_delete(connection, newsletter_jid, opts \\ [])

@spec newsletter_delete(connection(), String.t(), keyword()) :: :ok | {:error, term()}

Delete a newsletter.

newsletter_demote(connection, newsletter_jid, user_jid, opts \\ [])

@spec newsletter_demote(connection(), String.t(), String.t(), keyword()) ::
  :ok | {:error, term()}

Demote a newsletter admin.

newsletter_fetch_messages(connection, newsletter_jid, count, opts \\ [])

@spec newsletter_fetch_messages(connection(), String.t(), pos_integer(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Fetch newsletter message history.

newsletter_follow(connection, newsletter_jid, opts \\ [])

@spec newsletter_follow(connection(), String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Follow a newsletter.

newsletter_metadata(connection, type, key, opts \\ [])

@spec newsletter_metadata(connection(), :invite | :jid, String.t(), keyword()) ::
  {:ok, map() | nil} | {:error, term()}

Fetch newsletter metadata by :jid or :invite key.

newsletter_mute(connection, newsletter_jid, opts \\ [])

@spec newsletter_mute(connection(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Mute a newsletter.

newsletter_react_message(connection, newsletter_jid, server_id, reaction \\ nil, opts \\ [])

@spec newsletter_react_message(
  connection(),
  String.t(),
  String.t(),
  String.t() | nil,
  keyword()
) :: :ok | {:error, term()}

React to a newsletter message or remove an existing reaction.

newsletter_remove_picture(connection, newsletter_jid, opts \\ [])

@spec newsletter_remove_picture(connection(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Remove the newsletter picture.

newsletter_subscribe_updates(connection, newsletter_jid, opts \\ [])

@spec newsletter_subscribe_updates(connection(), String.t(), keyword()) ::
  {:ok, %{duration: String.t()} | nil} | {:error, term()}

Subscribe to live newsletter updates.

newsletter_subscribers(connection, newsletter_jid, opts \\ [])

@spec newsletter_subscribers(connection(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Fetch newsletter subscriber counts.

newsletter_unfollow(connection, newsletter_jid, opts \\ [])

@spec newsletter_unfollow(connection(), String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Unfollow a newsletter.

newsletter_unmute(connection, newsletter_jid, opts \\ [])

@spec newsletter_unmute(connection(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Unmute a newsletter.

newsletter_update(connection, newsletter_jid, updates, opts \\ [])

@spec newsletter_update(connection(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, term()}

Update newsletter metadata.

newsletter_update_description(connection, newsletter_jid, description, opts \\ [])

@spec newsletter_update_description(connection(), String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Update the newsletter description.

newsletter_update_name(connection, newsletter_jid, name, opts \\ [])

@spec newsletter_update_name(connection(), String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Update the newsletter name.

newsletter_update_picture(connection, newsletter_jid, content, opts \\ [])

@spec newsletter_update_picture(connection(), String.t(), term(), keyword()) ::
  {:ok, map()} | {:error, term()}

Update the newsletter picture.

on_whatsapp(connection, phone_numbers, opts \\ [])

@spec on_whatsapp(connection(), [String.t()], keyword()) ::
  {:ok, [%{exists: boolean(), jid: String.t()}]} | {:error, term()}

Check which phone numbers are registered on WhatsApp.

pin_chat(connection, jid, pin?, opts \\ [])

@spec pin_chat(connection(), String.t(), boolean(), keyword()) ::
  :ok | {:error, term()}

Pin or unpin a chat.

presence_subscribe(connection, jid, opts \\ [])

@spec presence_subscribe(connection(), String.t(), keyword()) ::
  :ok | {:error, term()}

Subscribe to a contact or group presence feed.

privacy_settings(connection, opts \\ [])

@spec privacy_settings(
  connection(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Fetch privacy settings.

profile_picture_url(connection, jid, type \\ :preview, opts \\ [])

@spec profile_picture_url(
  connection(),
  String.t(),
  BaileysEx.Feature.Profile.picture_type(),
  keyword()
) ::
  {:ok, String.t() | nil} | {:error, term()}

Fetch a profile picture URL.

queryable(connection)

@spec queryable(connection()) ::
  {:ok, {module(), pid()}} | {:error, :socket_not_available}

Return the underlying socket transport tuple used by feature modules.

read_messages(connection, keys, opts \\ [])

@spec read_messages(connection(), [map()], keyword()) :: :ok | {:error, term()}

Send read receipts for the provided message keys using current privacy settings.

reject_call(connection, call_id, caller_jid, opts \\ [])

@spec reject_call(connection(), String.t(), String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Reject an inbound call.

remove_business_cover_photo(connection, cover_id, opts \\ [])

@spec remove_business_cover_photo(connection(), String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Remove the business cover photo.

remove_profile_picture(connection, jid, opts \\ [])

@spec remove_profile_picture(connection(), String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Remove the profile picture for yourself or a group.

request_pairing_code(connection, phone_number, opts \\ [])

@spec request_pairing_code(connection(), binary(), keyword()) ::
  {:ok, binary()} | {:error, term()}

Request a phone-number pairing code from the active socket.

send_message(connection, jid, content, opts \\ [])

@spec send_message(
  connection(),
  String.t() | BaileysEx.JID.t(),
  map() | struct(),
  keyword()
) ::
  {:ok, map()} | {:error, term()}

Send a message to a WhatsApp JID through the coordinator-managed runtime.

By default, connect/2 builds the production Signal adapter when the auth state includes signed_identity_key, signed_pre_key, and registration_id. Use :signal_repository or :signal_repository_adapter only to override it.

send_presence_update(connection, type, to_jid \\ nil, opts \\ [])

@spec send_presence_update(
  connection(),
  BaileysEx.Feature.Presence.presence(),
  String.t() | nil,
  keyword()
) :: :ok | {:error, term()}

Send an availability or chatstate update.

send_status(connection, content, opts \\ [])

@spec send_status(connection(), map(), keyword()) :: {:ok, map()} | {:error, term()}

Send a status update through the status@broadcast fanout path.

By default, connect/2 builds the production Signal adapter when the auth state includes signed_identity_key, signed_pre_key, and registration_id. Use :signal_repository or :signal_repository_adapter only to override it.

send_wam_buffer(connection, binary_info)

@spec send_wam_buffer(connection(), binary() | BaileysEx.WAM.BinaryInfo.t()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Send a WAM analytics buffer or BaileysEx.WAM.BinaryInfo through the active socket.

signal_store(connection)

@spec signal_store(connection()) ::
  {:ok, BaileysEx.Signal.Store.t()} | {:error, :signal_store_not_available}

Return the wrapped Signal store for the connection when present.

star_messages(connection, jid, messages, star?, opts \\ [])

@spec star_messages(connection(), String.t(), [map()], boolean(), keyword()) ::
  :ok | {:error, term()}

Star or unstar one or more messages in a chat.

subscribe(connection, handler)

@spec subscribe(connection(), (tuple() -> term())) ::
  unsubscribe_fun() | {:error, :event_emitter_not_available}

Subscribe to friendly high-level events.

The handler receives:

  • {:connection, update} for connection lifecycle updates
  • {:message, message} for each incoming message
  • {:presence, update} for presence updates
  • {:call, payload} for call events
  • {:event, name, payload} for all other event payloads

subscribe_raw(connection, handler)

@spec subscribe_raw(connection(), (map() -> term())) ::
  unsubscribe_fun() | {:error, :event_emitter_not_available}

Subscribe to raw buffered event maps.

update_block_status(connection, jid, action, opts \\ [])

@spec update_block_status(connection(), String.t(), :block | :unblock, keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Block or unblock a user.

update_business_cover_photo(connection, photo, opts \\ [])

@spec update_business_cover_photo(connection(), term(), keyword()) ::
  {:ok, String.t()} | {:error, term()}

Upload and set the business cover photo.

update_business_profile(connection, profile_data, opts \\ [])

@spec update_business_profile(connection(), map(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Update the business profile payload.

update_call_privacy(connection, value, opts \\ [])

@spec update_call_privacy(connection(), atom() | String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Update call-add privacy.

update_default_disappearing_mode(connection, duration, opts \\ [])

@spec update_default_disappearing_mode(connection(), non_neg_integer(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Set the default disappearing-message duration in seconds.

update_groups_add_privacy(connection, value, opts \\ [])

@spec update_groups_add_privacy(connection(), atom() | String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Update group-add privacy.

update_last_seen_privacy(connection, value, opts \\ [])

@spec update_last_seen_privacy(connection(), atom() | String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Update last-seen privacy.

update_media_message(connection, message, opts \\ [])

@spec update_media_message(connection(), web_message_info(), keyword()) ::
  {:ok, web_message_info()} | {:error, term()}

Request media re-upload and return the updated message with refreshed URLs.

Sends a retry request, waits for the matching messages_media_update event, decrypts the response, and applies the refreshed directPath/url.

Options

  • :timeout — milliseconds to wait for the media update event (default 10_000)

update_messages_privacy(connection, value, opts \\ [])

@spec update_messages_privacy(connection(), atom() | String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Update who can message you.

update_online_privacy(connection, value, opts \\ [])

@spec update_online_privacy(connection(), atom() | String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Update online-visibility privacy.

update_profile_name(connection, name, opts \\ [])

@spec update_profile_name(connection(), String.t(), keyword()) ::
  :ok | {:error, term()}

Update the current account push name via app-state sync.

update_profile_picture(connection, jid, image_data, dimensions \\ nil, opts \\ [])

@spec update_profile_picture(connection(), String.t(), term(), map() | nil, keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Update the profile picture for yourself or a group.

update_profile_picture_privacy(connection, value, opts \\ [])

@spec update_profile_picture_privacy(connection(), atom() | String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Update profile-picture privacy.

update_profile_status(connection, status, opts \\ [])

@spec update_profile_status(connection(), String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Update the account status text.

update_read_receipts_privacy(connection, value, opts \\ [])

@spec update_read_receipts_privacy(connection(), atom() | String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Update read-receipt privacy.

update_status_privacy(connection, value, opts \\ [])

@spec update_status_privacy(connection(), atom() | String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Update status/story privacy.