KapsoEx.WhatsApp.TemplateComponents (kapso_ex v0.1.0)

Copy Markdown View Source

Builders for the components list sent with a template message.

Parameter values may be strings (sent as text parameters) or full parameter maps, such as %{type: "currency", currency: %{...}}.

Examples

alias KapsoEx.WhatsApp.TemplateComponents, as: C

# Positional parameters ({{1}}, {{2}})
C.body(["Ana", "#1234"])

# Named parameters ({{first_name}})
C.body(first_name: "Ana", order_number: "#1234")

Messages.send_template(client, phone_number_id, "56961567267", "seasonal_promotion", "en_US",
  components: [
    C.header_media(:image, "https://example.com/sale.jpg"),
    C.body(sale_name: "Summer Sale"),
    C.button_url(0, "summer2024"),
    C.button_quick_reply(1, "unsubscribe")
  ]
)

Summary

Functions

Components for an authentication (OTP) template: the code in the body and in the copy code / one-tap button.

Body parameters: a list of values (positional) or a keyword list / map of parameter_name => value (named).

Coupon code for the copy code button at index.

Action for the flow button at index, such as %{flow_token: "...", flow_action_data: %{...}}.

Payload returned when the quick reply button at index is tapped.

Dynamic suffix for the URL button at index.

Location header with :latitude, :longitude, :name and :address.

Media header. type is :image, :video or :document; media is a URL, an uploaded media ID or a map such as %{id: ..., filename: ...}.

Text header with one parameter, optionally named.

Types

value()

@type value() :: String.t() | map()

Functions

authentication(code)

@spec authentication(String.t()) :: [map()]

Components for an authentication (OTP) template: the code in the body and in the copy code / one-tap button.

Messages.send_template(client, phone_number_id, "56961567267", "login_code", "es",
  components: TemplateComponents.authentication("482913"))

body(params)

@spec body([value()] | keyword() | map()) :: map()

Body parameters: a list of values (positional) or a keyword list / map of parameter_name => value (named).

button_copy_code(index, code)

@spec button_copy_code(non_neg_integer(), String.t()) :: map()

Coupon code for the copy code button at index.

button_flow(index, action)

@spec button_flow(non_neg_integer(), map()) :: map()

Action for the flow button at index, such as %{flow_token: "...", flow_action_data: %{...}}.

button_quick_reply(index, payload)

@spec button_quick_reply(non_neg_integer(), String.t()) :: map()

Payload returned when the quick reply button at index is tapped.

button_url(index, value)

@spec button_url(non_neg_integer(), value()) :: map()

Dynamic suffix for the URL button at index.

header_location(location)

@spec header_location(map() | keyword()) :: map()

Location header with :latitude, :longitude, :name and :address.

header_media(type, media)

@spec header_media(:image | :video | :document, String.t() | map()) :: map()

Media header. type is :image, :video or :document; media is a URL, an uploaded media ID or a map such as %{id: ..., filename: ...}.

header_text(value)

@spec header_text(value()) :: map()

Text header with one parameter, optionally named.

header_text(name, value)

@spec header_text(atom() | String.t(), value()) :: map()