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
Functions
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 parameters: a list of values (positional) or a keyword list / map of
parameter_name => value (named).
@spec button_copy_code(non_neg_integer(), String.t()) :: map()
Coupon code for the copy code button at index.
@spec button_flow(non_neg_integer(), map()) :: map()
Action for the flow button at index, such as
%{flow_token: "...", flow_action_data: %{...}}.
@spec button_quick_reply(non_neg_integer(), String.t()) :: map()
Payload returned when the quick reply button at index is tapped.
@spec button_url(non_neg_integer(), value()) :: map()
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.