ExWapp.Message (ExWapp v0.1.2)

Copy Markdown View Source

User-facing WhatsApp message struct.

This is the high-level value applications pass to ExWapp, similar to how an email library exposes a mail struct instead of making users call MIME builders directly.

Summary

Types

High-level message categories supported by the public API.

t()

Runtime-neutral message value passed into transport adapters.

Functions

Builds an audio message from bytes, a filesystem path, or a pre-uploaded reference.

Builds a single WhatsApp contact card message.

Builds a document message from bytes, a filesystem path, or a pre-uploaded reference.

Builds a WhatsApp calendar event message.

Builds an image message from bytes, a filesystem path, or a pre-uploaded reference.

Builds a static GPS location message.

Builds a read receipt message for one or more message IDs.

Builds a plain text message.

Builds a typing indicator message.

Types

message_type()

@type message_type() ::
  :text
  | :typing
  | :read_receipt
  | :image
  | :audio
  | :document
  | :location
  | :contact
  | :event
  | atom()

High-level message categories supported by the public API.

t()

@type t() :: %ExWapp.Message{
  body: term(),
  id: String.t() | nil,
  metadata: map(),
  opts: keyword(),
  to: String.t(),
  type: message_type()
}

Runtime-neutral message value passed into transport adapters.

Functions

audio(to, source, opts \\ [])

@spec audio(String.t(), ExWapp.Media.source(), keyword()) :: t()

Builds an audio message from bytes, a filesystem path, or a pre-uploaded reference.

contact(to, display_name, vcard, opts \\ [])

@spec contact(String.t(), String.t(), String.t(), keyword()) :: t()

Builds a single WhatsApp contact card message.

vcard must contain the complete vCard payload (normally vCard 3.0).

document(to, source, opts \\ [])

@spec document(String.t(), ExWapp.Media.source(), keyword()) :: t()

Builds a document message from bytes, a filesystem path, or a pre-uploaded reference.

event(to, name, start_time, opts \\ [])

@spec event(String.t(), String.t(), integer() | DateTime.t(), keyword()) :: t()

Builds a WhatsApp calendar event message.

This message type exists in WhatsApp Web but is less stable than text, media, location, and contact messages. start_time may be a Unix timestamp in seconds or a DateTime.

image(to, source, opts \\ [])

@spec image(String.t(), ExWapp.Media.source(), keyword()) :: t()

Builds an image message from bytes, a filesystem path, or a pre-uploaded reference.

location(to, latitude, longitude, opts \\ [])

@spec location(String.t(), number(), number(), keyword()) :: t()

Builds a static GPS location message.

Latitude and longitude are encoded as protobuf doubles. Optional fields such as :name, :address, :url, :comment, and :accuracy are kept in opts until the session transport builds the wire payload.

read_receipt(to, message_ids, opts \\ [])

@spec read_receipt(String.t(), [String.t()], keyword()) :: t()

Builds a read receipt message for one or more message IDs.

text(to, body, opts \\ [])

@spec text(String.t(), iodata(), keyword()) :: t()

Builds a plain text message.

This is the simplest outbound message form and maps to WhatsApp's conversation or extendedTextMessage protobuf fields depending on options.

typing(to, composing \\ true, opts \\ [])

@spec typing(String.t(), boolean(), keyword()) :: t()

Builds a typing indicator message.

The boolean body is interpreted as true => composing and false => paused.