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:



200
201
202
# File 'lib/sentdm/resources/templates.rb', line 200

def initialize(client:)
  @client = client
end

Instance Method Details

#create(category: nil, creation_source: nil, definition: nil, language: nil, sandbox: nil, submit_for_review: nil, idempotency_key: nil, x_profile_id: 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: Complete definition of a message template including header, body, fo

  • language (String, nil)

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

  • sandbox (Boolean)

    Body param: Sandbox flag - when true, the operation is simulated without side ef

  • submit_for_review (Boolean)

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

  • idempotency_key (String)

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

  • x_profile_id (String)

    Header param: Profile UUID to scope the request to a child profile. Only organiz

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

Returns:

See Also:



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

def create(params = {})
  parsed, options = Sentdm::TemplateCreateParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key", x_profile_id: "x-profile-id"}
  @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, sandbox: nil, x_profile_id: 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)

    Path param: Template ID from route parameter

  • delete_from_meta (Boolean, nil)

    Body param: Whether to also delete the template from WhatsApp/Meta (optional, de

  • sandbox (Boolean)

    Body param: Sandbox flag - when true, the operation is simulated without side ef

  • x_profile_id (String)

    Header param: Profile UUID to scope the request to a child profile. Only organiz

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

Returns:

  • (nil)

See Also:



184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/sentdm/resources/templates.rb', line 184

def delete(id, params = {})
  parsed, options = Sentdm::TemplateDeleteParams.dump_request(params)
  header_params = {x_profile_id: "x-profile-id"}
  @client.request(
    method: :delete,
    path: ["v3/templates/%1$s", id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: NilClass,
    options: options
  )
end

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

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

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

Parameters:

  • page (Integer)

    Query param: Page number (1-indexed)

  • page_size (Integer)

    Query param: Number of items per page

  • category (String, nil)

    Query param: Optional category filter: MARKETING, UTILITY, AUTHENTICATION

  • is_welcome_playground (Boolean, nil)

    Query param: Optional filter by welcome playground flag

  • search (String, nil)

    Query param: Optional search term for filtering templates

  • status (String, nil)

    Query param: Optional status filter: APPROVED, PENDING, REJECTED

  • x_profile_id (String)

    Header param: Profile UUID to scope the request to a child profile. Only organiz

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

Returns:

See Also:



149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/sentdm/resources/templates.rb', line 149

def list(params)
  query_params = [:page, :page_size, :category, :is_welcome_playground, :search, :status]
  parsed, options = Sentdm::TemplateListParams.dump_request(params)
  query = Sentdm::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :get,
    path: "v3/templates",
    query: query,
    headers: parsed.except(*query_params).transform_keys(x_profile_id: "x-profile-id"),
    model: Sentdm::Models::TemplateListResponse,
    options: options
  )
end

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

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

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

  • x_profile_id (String)

    Profile UUID to scope the request to a child profile. Only organization API keys

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

Returns:

See Also:



67
68
69
70
71
72
73
74
75
76
# File 'lib/sentdm/resources/templates.rb', line 67

def retrieve(id, params = {})
  parsed, options = Sentdm::TemplateRetrieveParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["v3/templates/%1$s", id],
    headers: parsed.transform_keys(x_profile_id: "x-profile-id"),
    model: Sentdm::APIResponseTemplate,
    options: options
  )
end

#update(id, category: nil, definition: nil, language: nil, name: nil, sandbox: nil, submit_for_review: nil, idempotency_key: nil, x_profile_id: 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: Complete definition of a message template including header, body, fo

  • language (String, nil)

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

  • name (String, nil)

    Body param: Template display name

  • sandbox (Boolean)

    Body param: Sandbox flag - when true, the operation is simulated without side ef

  • submit_for_review (Boolean)

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

  • idempotency_key (String)

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

  • x_profile_id (String)

    Header param: Profile UUID to scope the request to a child profile. Only organiz

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

Returns:

See Also:



109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/sentdm/resources/templates.rb', line 109

def update(id, params = {})
  parsed, options = Sentdm::TemplateUpdateParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key", x_profile_id: "x-profile-id"}
  @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