whatsapp-api-js - v5.2.0
    Preparing search index...

    Class Template

    Template API object

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    Methods

    Constructors

    • Create a Template object for the API

      Parameters

      • name: string

        Name of the template

      • language: string | Language

        The code of the language or locale to use. Accepts both language and language_locale formats (e.g., en and en_US).

      • ...components: TemplateComponent[]

        Components objects containing the parameters of the message. For text-based templates, the only supported component is BodyComponent.

      Returns Template

      import {
      Template,
      HeaderComponent,
      HeaderParameter,
      BodyComponent,
      BodyParameter,
      Currency,
      DateTime
      } from "whatsapp-api-js/messages";

      const template_variables_message = new Template(
      "template_name",
      "en",
      new HeaderComponent(
      new HeaderParameter("Hello"),
      new HeaderParameter(new Currency(1.5 * 1000, "USD", "U$1.5")),
      new HeaderParameter(new DateTime("01/01/2023"))
      ),
      new BodyComponent(
      new BodyParameter("Hello"),
      new BodyParameter(new Currency(1.5 * 1000, "USD", "U$1.5")),
      new BodyParameter(new DateTime("01/01/2023"))
      )
      );

      If the template isn't text-based (only one BodyComponent is given) and one of the parameters is a string and it's over 1024 characters.

    Properties

    components?: TemplateComponent[]

    The components of the template

    language: Language

    The language of the template

    name: string

    The name of the template

    Methods

    • OTP Template generator

      Parameters

      • name: string

        Name of the template

      • language: string | Language

        The code of the language or locale to use. Accepts both language and language_locale formats (e.g., en and en_US).

      • code: string

        The one time password to be sent

      Returns Template

      A Template object for the API

      import { Template } from "whatsapp-api-js/messages";

      const template_otp_message = Template.OTP("template_name", "en", "123456");