Class: Sentdm::Resources::Templates

Inherits:
Object
  • Object
show all
Defined in:
lib/sentdm/resources/templates.rb

Overview

Manage message templates with variable substitution

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Templates

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Templates.

Parameters:



177
178
179
# File 'lib/sentdm/resources/templates.rb', line 177

def initialize(client:)
  @client = client
end

Instance Method Details

#create(category: nil, creation_source: nil, definition: nil, language: nil, submit_for_review: nil, test_mode: nil, idempotency_key: nil, request_options: {}) ⇒ Sentdm::Models::APIResponseTemplate

Some parameter documentations has been truncated, see Models::TemplateCreateParams for more details.

Creates a new message template with header, body, footer, and buttons. The template can be submitted for review immediately or saved as draft for later submission.

Parameters:

  • category (String, nil)

    Body param: Template category: MARKETING, UTILITY, AUTHENTICATION (optional, aut

  • creation_source (String, nil)

    Body param: Source of template creation (default: from-api)

  • definition (Sentdm::Models::TemplateDefinition)

    Body param: Template definition including header, body, footer, and buttons

  • language (String, nil)

    Body param: Template language code (e.g., en_US) (optional, auto-detected if not

  • submit_for_review (Boolean)

    Body param: Whether to submit the template for review after creation (default: f

  • test_mode (Boolean)

    Body param: Test mode flag - when true, the operation is simulated without side

  • idempotency_key (String)

    Header param: Unique key to ensure idempotent request processing. Must be 1-255

  • request_options (Sentdm::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sentdm/resources/templates.rb', line 35

def create(params = {})
  parsed, options = Sentdm::TemplateCreateParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key"}
  @client.request(
    method: :post,
    path: "v3/templates",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Sentdm::APIResponseTemplate,
    options: options
  )
end

#delete(id, delete_from_meta: nil, test_mode: nil, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::TemplateDeleteParams for more details.

Deletes a template by ID. Optionally, you can also delete the template from WhatsApp/Meta by setting delete_from_meta=true.

Parameters:

  • id (String)

    Template ID from route parameter

  • delete_from_meta (Boolean, nil)

    Whether to also delete the template from WhatsApp/Meta (optional, defaults to fa

  • test_mode (Boolean)

    Test mode flag - when true, the operation is simulated without side effects

  • request_options (Sentdm::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



162
163
164
165
166
167
168
169
170
171
172
# File 'lib/sentdm/resources/templates.rb', line 162

def delete(id, params = {})
  parsed, options = Sentdm::TemplateDeleteParams.dump_request(params)
  @client.request(
    method: :delete,
    path: ["v3/templates/%1$s", id],
    headers: {"content-type" => "*/*"},
    body: parsed,
    model: NilClass,
    options: options
  )
end

#list(page:, page_size:, category: nil, search: nil, status: nil, request_options: {}) ⇒ Sentdm::Models::TemplateListResponse

Retrieves a paginated list of message templates for the authenticated customer. Supports filtering by status, category, and search term.

Parameters:

  • page (Integer)

    Page number (1-indexed)

  • page_size (Integer)
  • category (String, nil)

    Optional category filter: MARKETING, UTILITY, AUTHENTICATION

  • search (String, nil)

    Optional search term for filtering templates

  • status (String, nil)

    Optional status filter: APPROVED, PENDING, REJECTED

  • request_options (Sentdm::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/sentdm/resources/templates.rb', line 131

def list(params)
  parsed, options = Sentdm::TemplateListParams.dump_request(params)
  query = Sentdm::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "v3/templates",
    query: query.transform_keys(page_size: "pageSize"),
    model: Sentdm::Models::TemplateListResponse,
    options: options
  )
end

#retrieve(id, request_options: {}) ⇒ Sentdm::Models::APIResponseTemplate

Retrieves a specific template by its ID. Returns template details including name, category, language, status, and definition.

Parameters:

  • id (String)

    Template ID from route parameter

  • request_options (Sentdm::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



60
61
62
63
64
65
66
67
# File 'lib/sentdm/resources/templates.rb', line 60

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["v3/templates/%1$s", id],
    model: Sentdm::APIResponseTemplate,
    options: params[:request_options]
  )
end

#update(id, category: nil, definition: nil, language: nil, name: nil, submit_for_review: nil, test_mode: nil, idempotency_key: nil, request_options: {}) ⇒ Sentdm::Models::APIResponseTemplate

Some parameter documentations has been truncated, see Models::TemplateUpdateParams for more details.

Updates an existing template’s name, category, language, definition, or submits it for review.

Parameters:

  • id (String)

    Path param: Template ID from route parameter

  • category (String, nil)

    Body param: Template category: MARKETING, UTILITY, AUTHENTICATION

  • definition (Sentdm::Models::TemplateDefinition, nil)

    Body param: Template definition including header, body, footer, and buttons

  • language (String, nil)

    Body param: Template language code (e.g., en_US)

  • name (String, nil)

    Body param: Template display name

  • submit_for_review (Boolean)

    Body param: Whether to submit the template for review after updating (default: f

  • test_mode (Boolean)

    Body param: Test mode flag - when true, the operation is simulated without side

  • idempotency_key (String)

    Header param: Unique key to ensure idempotent request processing. Must be 1-255

  • request_options (Sentdm::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/sentdm/resources/templates.rb', line 98

def update(id, params = {})
  parsed, options = Sentdm::TemplateUpdateParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key"}
  @client.request(
    method: :put,
    path: ["v3/templates/%1$s", id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Sentdm::APIResponseTemplate,
    options: options
  )
end