View Source WhatsappElixir.Templates (whatsapp_elixir v0.1.2)
Module for managing WhatsApp message templates including creation, deletion, editing, and listing.
Link to this section Summary
Functions
Creates a new message template.
Deletes a message template by ID, name, or both.
Edits an existing message template.
Lists message templates.
Retrieve template namespace
Link to this section Functions
Creates a new message template.
Parameters
template_data: A map containing the following keys::name(string, required): Template name (maximum 512 characters).:category(string, required): Template category (AUTHENTICATION,MARKETING,UTILITY).:allow_category_change(boolean, optional): Set totrueto allow automatic category assignment.:language(string, required): Template language and locale code (e.g., "en_US").:components(list, required): Array of template components.:library_template_name(string, optional): Exact name of the Utility Template Library template.:library_template_button_inputs(list, optional): Array of objects for website and/or phone number used in the template.
Example
iex> template_data = %{
...> name: "order_confirmation",
...> category: "UTILITY",
...> allow_category_change: true,
...> language: "en_US",
...> components: components
...> }
iex> WhatsappElixir.Templates.create_template(template_data)
{:ok, %{"id" => "123456", "status" => "PENDING", "category" => "UTILITY"}}Validation
- Raises
ArgumentErrorif required fields (name,category,language,components) are missing.
Link to this function
delete_template(template_id \\ nil, name \\ nil, custom_configs \\ [])
View SourceDeletes a message template by ID, name, or both.
Parameters
template_id: The ID of the template to delete (optional).name: The name of the template to delete (optional).
Example
iex> WhatsappElixir.Templates.delete_template("123456", "order_confirmation")
{:ok, %{"success" => true}}
iex> WhatsappElixir.Templates.delete_template(nil, "order_confirmation")
{:ok, %{"success" => true}}
iex> WhatsappElixir.Templates.delete_template("123456", nil)
{:ok, %{"success" => true}}
Edits an existing message template.
Parameters
template_id: The ID of the template to edit.params: A map containing the properties to be edited:category: New category for the template (optional).components: New components for the template (optional).
Example
iex> params = %{"category" => "MARKETING", "components" => new_components}
iex> WhatsappElixir.Templates.edit_template("123456", params, custom_configs)
{:ok, %{"success" => true}}
Lists message templates.
Parameters
fields: Comma-separated list of fields to include in the response (optional).limit: Maximum number of templates to return (optional).
Example
iex> WhatsappElixir.Templates.list_templates("name,status", 10)
{:ok, %{"data" => [%{"name" => "template1", "status" => "APPROVED"}]}}
Retrieve template namespace
Example
iex(7)> WhatsappElixir.Templates.retrieve_template_namespace(custom_configs) {:ok, %{
"id" => "375688788962938",
"message_template_namespace" => "87c5159f_1423_4819_8fe3_11e731b2d492"}}