Noizu.WhatsApp.Messages (Noizu.WhatsApp v0.1.0)

Copy Markdown View Source

Cloud API messaging: text, templates, media, read receipts, reactions.

Every function accepts an explicit Noizu.WhatsApp.Client first or omits it (a default client is built from the environment). Recipients are normalized to digits-only E.164; failures return {:error, %Noizu.WhatsApp.Error{}} with the phone masked.

Graph code 131047 errors carry kind: :window_closed — the 24-hour customer-service window has lapsed; use send_template/4 (an approved template) to re-open it.

Summary

Functions

Marks an inbound message as read.

Reacts to an inbound message (:emoji may be an empty string to remove).

Sends media by link or by media id (as uploaded via Media.upload/2).

Sends an approved template — the only way to start a conversation outside the 24h window. lang is a template language code (e.g. "en_US"); components is the Cloud API components list (header/body/button params).

Functions

mark_read(message_id)

@spec mark_read(String.t()) :: Noizu.WhatsApp.Request.result()

mark_read(client, message_id, opts \\ [])

Marks an inbound message as read.

react(to, message_id, emoji)

react(client, to, message_id, emoji, opts \\ [])

Reacts to an inbound message (:emoji may be an empty string to remove).

send_media(client_or_to, to_or_type, type_or_link, link_or_opts \\ [], opts_or_nil \\ nil)

@spec send_media(
  Noizu.WhatsApp.Client.t() | term(),
  term(),
  :image | :document | :audio | :video | :sticker,
  term(),
  keyword()
) :: Noizu.WhatsApp.Request.result()

Sends media by link or by media id (as uploaded via Media.upload/2).

type is :image | :document | :audio | :video | :sticker; link_or_id is a URL (link: true implied) or an uploaded media id (binary/string id used as id:). Options: :caption (image/document/video), :filename (document).

send_template(client_or_to, to_or_name, name_or_lang, lang_or_components \\ [], components_or_nil \\ nil)

@spec send_template(
  Noizu.WhatsApp.Client.t() | term(),
  term(),
  String.t(),
  String.t(),
  list()
) ::
  Noizu.WhatsApp.Request.result()

Sends an approved template — the only way to start a conversation outside the 24h window. lang is a template language code (e.g. "en_US"); components is the Cloud API components list (header/body/button params).

send_text(client_or_to, to_or_body, body_or_opts \\ [], opts_or_nil \\ nil)

Sends a free-form text message.

Options: :preview_url (true renders a link preview), :reply_to (message id threaded under context).