ExWapp.Client.API (ExWapp v0.1.2)

Copy Markdown View Source

Runtime-neutral operations for ExWapp.Client.

This module contains the high-level client workflow used by the public ExWapp facade. It coordinates transport adapters, client status updates, telemetry, tracing, and event emission without depending on a session process directly.

Summary

Functions

Returns a lazy stream over every locally retained message.

Connects a client through its configured transport adapter.

Creates a contact through the configured transport adapter.

Deletes a contact through the configured transport adapter.

Deletes selected local messages after durable wrapper persistence.

Returns a compact diagnostics map for logging, debugging, or health checks.

Disconnects a client through its configured transport adapter.

Downloads and decrypts a media reference through the configured transport.

Fetches one stored call log entry by call ID through the configured transport.

Fetches one chat by JID through the configured transport adapter.

Fetches one contact by JID through the configured transport adapter.

Gets locally retained messages for a chat through the configured transport.

Returns the most recent structured client error, if any.

Lists locally stored call log entries through the configured transport.

Lists chats through the configured transport adapter.

Lists contacts through the configured transport adapter.

Lists group chats through the configured transport adapter.

Starts pairing through the configured transport adapter.

Handles an inbound transport payload and emits any returned events.

Sends an audio message through the configured transport adapter.

Sends a WhatsApp contact card through the configured transport adapter.

Sends a document message through the configured transport adapter.

Sends WhatsApp's calendar event message through the configured transport.

Sends an image message through the configured transport adapter.

Sends a GPS location through the configured transport adapter.

Sends a text message from keyword options.

Returns the current client status.

Builds a lazy stream over locally retained messages.

Synchronizes contacts through the configured transport adapter.

Types

client_error()

@type client_error() :: {:error, ExWapp.Error.t(), ExWapp.Client.t()}

download_result()

@type download_result() ::
  {:ok, ExWapp.Client.t(), ExWapp.Media.Download.t()} | client_error()

message_result()

@type message_result() :: {:ok, ExWapp.Client.t(), String.t()} | client_error()

mutation_result()

@type mutation_result() :: {:ok, ExWapp.Client.t()} | client_error()

Functions

all_messages(client, jid, opts \\ [])

@spec all_messages(ExWapp.Client.t(), String.t(), keyword()) ::
  read_result(Enumerable.t())

Returns a lazy stream over every locally retained message.

connect(client)

@spec connect(ExWapp.Client.t()) :: {:ok, ExWapp.Client.t()} | client_error()

Connects a client through its configured transport adapter.

Emits client connect telemetry and records a status event when the transport succeeds.

create_contact(client, jid, name)

@spec create_contact(ExWapp.Client.t(), String.t(), String.t()) :: mutation_result()

Creates a contact through the configured transport adapter.

delete_contact(client, jid)

@spec delete_contact(ExWapp.Client.t(), String.t()) :: mutation_result()

Deletes a contact through the configured transport adapter.

delete_messages(client, jid, message_ids)

@spec delete_messages(ExWapp.Client.t(), String.t(), [String.t()]) ::
  mutation_result()

Deletes selected local messages after durable wrapper persistence.

diagnostics(client)

@spec diagnostics(ExWapp.Client.t()) :: map()

Returns a compact diagnostics map for logging, debugging, or health checks.

disconnect(client)

@spec disconnect(ExWapp.Client.t()) :: {:ok, ExWapp.Client.t()} | client_error()

Disconnects a client through its configured transport adapter.

download_media(client, ref, opts \\ [])

@spec download_media(ExWapp.Client.t(), ExWapp.Media.Ref.t(), keyword()) ::
  download_result()

Downloads and decrypts a media reference through the configured transport.

get_call(client, call_id)

@spec get_call(ExWapp.Client.t(), String.t()) :: read_result(ExWapp.Call.t())

Fetches one stored call log entry by call ID through the configured transport.

get_chat(client, jid)

@spec get_chat(ExWapp.Client.t(), String.t()) :: read_result(ExWapp.Chat.chat())

Fetches one chat by JID through the configured transport adapter.

get_contact(client, jid)

@spec get_contact(ExWapp.Client.t(), String.t()) ::
  read_result(ExWapp.Contact.t() | nil)

Fetches one contact by JID through the configured transport adapter.

get_messages(client, jid, opts \\ [])

@spec get_messages(ExWapp.Client.t(), String.t(), keyword()) ::
  read_result([ExWapp.Chat.message()])

Gets locally retained messages for a chat through the configured transport.

The :limit option accepts a non-negative integer or :all; :offset skips messages from the newest-first result.

last_error(client)

@spec last_error(ExWapp.Client.t()) :: ExWapp.Error.t() | nil

Returns the most recent structured client error, if any.

list_calls(client, opts \\ [])

@spec list_calls(
  ExWapp.Client.t(),
  keyword()
) :: read_result([ExWapp.Call.t()])

Lists locally stored call log entries through the configured transport.

Accepts the same options as ExWapp.Call.list/2 (:limit, :status, :since, ...).

list_chats(client)

@spec list_chats(ExWapp.Client.t()) :: read_result([ExWapp.Chat.chat()])

Lists chats through the configured transport adapter.

list_contacts(client)

@spec list_contacts(ExWapp.Client.t()) :: read_result([ExWapp.Contact.t()])

Lists contacts through the configured transport adapter.

list_groups(client)

@spec list_groups(ExWapp.Client.t()) :: read_result([ExWapp.Chat.chat()])

Lists group chats through the configured transport adapter.

pair(client)

@spec pair(ExWapp.Client.t()) :: {:ok, ExWapp.Client.t(), term()} | client_error()

Starts pairing through the configured transport adapter.

On success the client moves to :pairing and a QR event is emitted with the transport payload.

receive_message(client, payload, opts \\ [])

@spec receive_message(ExWapp.Client.t(), term(), keyword()) ::
  {:ok, ExWapp.Client.t(), [ExWapp.Event.t()]} | client_error()

Handles an inbound transport payload and emits any returned events.

send_audio(client, to, source, opts \\ [])

Sends an audio message through the configured transport adapter.

send_contact(client, to, display_name, vcard, opts \\ [])

@spec send_contact(ExWapp.Client.t(), String.t(), String.t(), String.t(), keyword()) ::
  message_result()

Sends a WhatsApp contact card through the configured transport adapter.

send_document(client, to, source, opts \\ [])

@spec send_document(ExWapp.Client.t(), String.t(), ExWapp.Media.source(), keyword()) ::
  message_result()

Sends a document message through the configured transport adapter.

send_event(client, to, name, start_time, opts \\ [])

@spec send_event(
  ExWapp.Client.t(),
  String.t(),
  String.t(),
  integer() | DateTime.t(),
  keyword()
) :: message_result()

Sends WhatsApp's calendar event message through the configured transport.

send_image(client, to, source, opts \\ [])

Sends an image message through the configured transport adapter.

send_location(client, to, latitude, longitude, opts \\ [])

@spec send_location(ExWapp.Client.t(), String.t(), number(), number(), keyword()) ::
  message_result()

Sends a GPS location through the configured transport adapter.

send_message(client, opts)

@spec send_message(
  ExWapp.Client.t(),
  keyword()
) :: message_result()

Sends a text message from keyword options.

Required options are :to and :text; remaining options are passed to ExWapp.Message.text/3.

status(client)

@spec status(ExWapp.Client.t()) :: ExWapp.Client.status()

Returns the current client status.

stream_messages(client, jid, opts \\ [])

@spec stream_messages(ExWapp.Client.t(), String.t(), keyword()) ::
  read_result(Enumerable.t())

Builds a lazy stream over locally retained messages.

The stream is oldest first by default and delegates cursor ownership to the configured adapter. It does not trigger remote WhatsApp history retrieval.

sync_contacts(client)

@spec sync_contacts(ExWapp.Client.t()) :: mutation_result()

Synchronizes contacts through the configured transport adapter.