Unicom360.WhatsApp.Session (Unicom360 v0.1.0)

Copy Markdown View Source

Builders for WhatsApp session messages, sent with Unicom360.WhatsApp.send_session/3 inside the 24-hour customer service window.

alias Unicom360.WhatsApp.Session

Session.text("260971234567", "Your order is ready.", reply_to: inbound_wamid)
Session.image("260971234567", "https://example.com/receipt.png", caption: "Your receipt")
Session.buttons("260971234567", "Collect today or deliver?", [
  {"collect", "Collect"},
  {"deliver", "Deliver"}
])

Every builder takes the keyword options :from (your WhatsApp number), :user_reference_id (makes the send safe to retry), :callback_url and, all but reaction/4, :reply_to. :reply_to and a reaction's message_id take either a message_id a send returned or the wamid. id of an inbound message, exactly as a message.received webhook delivers it.

The SDK checks no lengths or limits; the gateway answers an invalid message with an :invalid_request_error.

Summary

Functions

An interactive message with up to three reply buttons, each a Unicom360.WhatsApp.ReplyButton, an {id, title} tuple or a map. Options: :header, :footer and the common ones.

Contact cards, each a map in Meta's contact shape (%{"name" => %{"formatted_name" => ...}, "phones" => [...]}), sent as given.

A document, with an optional :caption and :filename.

An image, with an optional :caption.

An interactive list: button is the text of the button that opens it, sections a list of Unicom360.WhatsApp.ListSection (or maps). Options: :header, :footer and the common ones.

A location pin. Options: :name, :address and the common ones.

A reaction to a message. An empty emoji ("") removes your reaction. Options: :from, :user_reference_id and :callback_url (a reaction takes no :reply_to).

A text message. Options: the common ones.

A video, with an optional :caption.

Functions

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

An audio file.

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

An interactive message with up to three reply buttons, each a Unicom360.WhatsApp.ReplyButton, an {id, title} tuple or a map. Options: :header, :footer and the common ones.

contacts(to, contacts, opts \\ [])

@spec contacts(String.t(), [map()], keyword()) ::
  Unicom360.WhatsApp.SessionMessage.t()

Contact cards, each a map in Meta's contact shape (%{"name" => %{"formatted_name" => ...}, "phones" => [...]}), sent as given.

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

A document, with an optional :caption and :filename.

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

An image, with an optional :caption.

list(to, body, button, sections, opts \\ [])

An interactive list: button is the text of the button that opens it, sections a list of Unicom360.WhatsApp.ListSection (or maps). Options: :header, :footer and the common ones.

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

A location pin. Options: :name, :address and the common ones.

reaction(to, message_id, emoji, opts \\ [])

A reaction to a message. An empty emoji ("") removes your reaction. Options: :from, :user_reference_id and :callback_url (a reaction takes no :reply_to).

sticker(to, url, opts \\ [])

A sticker.

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

A text message. Options: the common ones.

video(to, url, opts \\ [])

A video, with an optional :caption.