Anu.Template (Anu v0.2.1)

Copy Markdown View Source

Helpers for building template message components.

Template messages require pre-approved templates registered in the WhatsApp Business Manager. These helpers build the component parameters that fill in the template placeholders.

Examples

Anu.Message.new("+5511999999999")
|> Anu.Message.template("order_update", "en_US", [
  Anu.Template.body_param("John"),
  Anu.Template.body_param("#12345")
])

Summary

Functions

Creates a text parameter for the template body.

Creates a button parameter for a template button.

Creates a document parameter for the template header.

Creates an image parameter for the template header.

Types

param()

@type param() :: map()

Functions

body_param(value)

@spec body_param(String.t()) :: param()

Creates a text parameter for the template body.

Examples

iex> Anu.Template.body_param("John")
%{type: "text", text: "John"}

button_param(binary, value)

@spec button_param(String.t(), String.t()) :: param()

Creates a button parameter for a template button.

Types

  • "url" - URL suffix appended to the button URL
  • "quick_reply" - payload sent back when user taps the button

Examples

iex> Anu.Template.button_param("url", "/track/12345")
%{type: "url", url: "/track/12345"}

iex> Anu.Template.button_param("quick_reply", "confirm_yes")
%{type: "quick_reply", payload: "confirm_yes"}

header_document(url, filename)

@spec header_document(String.t(), String.t()) :: param()

Creates a document parameter for the template header.

Examples

iex> Anu.Template.header_document("https://example.com/doc.pdf", "invoice.pdf")
%{type: "document", document: %{link: "https://example.com/doc.pdf", filename: "invoice.pdf"}}

header_image(url)

@spec header_image(String.t()) :: param()

Creates an image parameter for the template header.

Examples

iex> Anu.Template.header_image("https://example.com/img.png")
%{type: "image", image: %{link: "https://example.com/img.png"}}