TemplatesResource
Defined in: src/resources/templates.ts:75
Message-template management API exposed as client.templates.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TemplatesResource(
request,getDefaultBusinessAccountId):TemplatesResource
Defined in: src/resources/templates.ts:79
Parameters
Section titled “Parameters”request
Section titled “request”RequestFn
getDefaultBusinessAccountId
Section titled “getDefaultBusinessAccountId”BusinessAccountIdAccessor
Returns
Section titled “Returns”TemplatesResource
Methods
Section titled “Methods”create()
Section titled “create()”create(
payload,businessAccountId?):Promise<CreateTemplateResponse>
Defined in: src/resources/templates.ts:144
Creates a message template. Client-side validation of the documented hard limits runs before the request, so an invalid payload never hits the API.
Parameters
Section titled “Parameters”payload
Section titled “payload”businessAccountId?
Section titled “businessAccountId?”string
Returns
Section titled “Returns”Promise<CreateTemplateResponse>
Examples
Section titled “Examples”Positional body with a footer
await client.templates.create({ name: 'order_confirmation', language: 'en_US', category: 'UTILITY', components: [ { type: 'BODY', text: 'Hi {{1}}, your order {{2}} is confirmed.', example: { body_text: [['Sam', '12345']] } }, { type: 'FOOTER', text: 'Reply STOP to opt out.' }, ],});Named-parameter body with a media header and buttons
await client.templates.create({ name: 'appointment_reminder', language: 'en_US', category: 'UTILITY', parameterFormat: 'NAMED', components: [ { type: 'HEADER', format: 'IMAGE', example: { header_handle: ['4::handle'] } }, { type: 'BODY', text: 'Hi {{name}}, your appointment is on {{date}}.', example: { body_text_named_params: [{ param_name: 'name', example: 'Sam' }, { param_name: 'date', example: 'Monday' }] }, }, { type: 'BUTTONS', buttons: [{ type: 'QUICK_REPLY', text: 'Confirm' }, { type: 'QUICK_REPLY', text: 'Cancel' }] }, ],});delete()
Section titled “delete()”delete(
options):Promise<SuccessResponse>
Defined in: src/resources/templates.ts:213
Deletes a template by name. By default all versions are deleted; pass
templateId (mapped to hsm_id) to delete a single version. name is
always required.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Promise<SuccessResponse>
edit()
Section titled “edit()”edit(
templateId,payload,businessAccountId?):Promise<SuccessResponse>
Defined in: src/resources/templates.ts:177
Edits an existing template by its id. Only category, components, and
messageSendTtlSeconds are editable; name and language are immutable.
Editing an APPROVED template resets it to PENDING for re-review.
businessAccountId is accepted for signature parity with the other
methods but is unused: the edit endpoint is addressed globally by template
id and does not include a WABA segment.
Parameters
Section titled “Parameters”templateId
Section titled “templateId”string
payload
Section titled “payload”businessAccountId?
Section titled “businessAccountId?”string
Returns
Section titled “Returns”Promise<SuccessResponse>
get(
templateId,fields?):Promise<MessageTemplate>
Defined in: src/resources/templates.ts:100
Reads a single template by its id. Pass fields to request specific Graph
fields; when omitted no field selection is sent.
Parameters
Section titled “Parameters”templateId
Section titled “templateId”string
fields?
Section titled “fields?”string[]
Returns
Section titled “Returns”Promise<MessageTemplate>
list()
Section titled “list()”list(
options?):Promise<TemplateList>
Defined in: src/resources/templates.ts:88
Lists the message templates on a business account. All options are
optional; fields is comma-joined and every value is URL-encoded.
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”Promise<TemplateList>
Independent open-source project. Not affiliated with, endorsed by or sponsored by Meta or WhatsApp. Released under the MIT licence. Source on GitHub.