Class: Zavudev::Resources::Templates

Inherits:
Object
  • Object
show all
Defined in:
lib/zavudev/resources/templates.rb,
sig/zavudev/resources/templates.rbs

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:



193
194
195
# File 'lib/zavudev/resources/templates.rb', line 193

def initialize(client:)
  @client = client
end

Instance Method Details

#create(body:, language:, name:, add_security_recommendation: nil, buttons: nil, code_expiration_minutes: nil, footer: nil, header_content: nil, header_type: nil, instagram_body: nil, sms_body: nil, telegram_body: nil, variables: nil, whatsapp_category: nil, request_options: {}) ⇒ Zavudev::Models::Template

Create a WhatsApp message template. Note: Templates must be approved by Meta before use.

Parameters:

  • body (String) —

    Default template body. Used when no channel-specific body is set.

  • language (String)
  • name (String)
  • add_security_recommendation (Boolean) —

    Add 'Do not share this code' disclaimer. Only for AUTHENTICATION templates.

  • buttons (Array<Zavudev::Models::TemplateCreateParams::Button>) —

    Template buttons (max 3).

  • code_expiration_minutes (Integer) —

    Code expiration time in minutes. Only for AUTHENTICATION templates.

  • footer (String) —

    Footer text for the template.

  • header_content (String) —

    Header content (text string or media URL).

  • header_type (Symbol, Zavudev::Models::TemplateCreateParams::HeaderType) —

    Type of header for the template.

  • instagram_body (String) —

    Channel-specific body for Instagram. Falls back to body if not set.

  • sms_body (String) —

    Channel-specific body for SMS. Falls back to body if not set.

  • telegram_body (String) —

    Channel-specific body for Telegram. Falls back to body if not set.

  • variables (Array<String>)
  • whatsapp_category (Symbol, Zavudev::Models::WhatsappCategory) —

    WhatsApp template category.

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

Returns:

See Also:



44
45
46
47
48
49
50
51
52
53
# File 'lib/zavudev/resources/templates.rb', line 44

def create(params)
  parsed, options = Zavudev::TemplateCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "v1/templates",
    body: parsed,
    model: Zavudev::Template,
    options: options
  )
end

#delete(template_id, request_options: {}) ⇒ nil

Delete template

Parameters:

Returns:

  • (nil)

See Also:



108
109
110
111
112
113
114
115
# File 'lib/zavudev/resources/templates.rb', line 108

def delete(template_id, params = {})
  @client.request(
    method: :delete,
    path: ["v1/templates/%1$s", template_id],
    model: NilClass,
    options: params[:request_options]
  )
end

#list(cursor: nil, limit: nil, request_options: {}) ⇒ Zavudev::Internal::Cursor<Zavudev::Models::Template>

List WhatsApp message templates for this project.

Parameters:

Returns:

See Also:



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/zavudev/resources/templates.rb', line 85

def list(params = {})
  parsed, options = Zavudev::TemplateListParams.dump_request(params)
  query = Zavudev::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "v1/templates",
    query: query,
    page: Zavudev::Internal::Cursor,
    model: Zavudev::Template,
    options: options
  )
end

#retrieve(template_id, request_options: {}) ⇒ Zavudev::Models::Template

Get template

Parameters:

Returns:

See Also:



65
66
67
68
69
70
71
72
# File 'lib/zavudev/resources/templates.rb', line 65

def retrieve(template_id, params = {})
  @client.request(
    method: :get,
    path: ["v1/templates/%1$s", template_id],
    model: Zavudev::Template,
    options: params[:request_options]
  )
end

#submit(template_id, sender_id:, category: nil, request_options: {}) ⇒ Zavudev::Models::Template

Submit a WhatsApp template to Meta for approval. The template must be in draft status and associated with a sender that has a WhatsApp Business Account configured.

Parameters:

  • template_id (String)
  • sender_id (String) —

    The sender ID with the WhatsApp Business Account to submit the template to.

  • category (Symbol, Zavudev::Models::WhatsappCategory) —

    Template category. If not provided, uses the category set on the template.

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

Returns:

See Also:



134
135
136
137
138
139
140
141
142
143
# File 'lib/zavudev/resources/templates.rb', line 134

def submit(template_id, params)
  parsed, options = Zavudev::TemplateSubmitParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["v1/templates/%1$s/submit", template_id],
    body: parsed,
    model: Zavudev::Template,
    options: options
  )
end

#sync(sender_id: nil, request_options: {}) ⇒ Zavudev::Models::TemplateSyncResponse

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

Reconcile this project's templates against WhatsApp. Two things happen per connected WhatsApp Business Account: templates that exist on Meta but not in Zavu are imported (or linked to an existing template with the same name), and the approval status of the templates Zavu already knows about is refreshed from Meta.

This is what to call when a template was created outside Zavu — in Meta Business Manager, or by another tool — or when a template.status_changed webhook was missed and a template is stuck in pending. Status changes normally arrive by webhook; this endpoint is the recovery path and the only path for a template Zavu never created.

Templates that Meta reports as rejected or disabled are not imported; they are counted in skipped. Existing local templates are matched first by Meta template ID, then by name.

By default every sender in the project with a WhatsApp Business Account is synced. Pass senderId to sync only that sender's account. The call is synchronous — it waits for Meta and returns what changed — so it can take a few seconds per account. A failure on one account does not fail the request: it is reported in errors and the remaining accounts are still synced.

Parameters:

  • sender_id (String) —

    Sync only the WhatsApp Business Account attached to this sender. If omitted, eve

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

Returns:

See Also:



179
180
181
182
183
184
185
186
187
188
# File 'lib/zavudev/resources/templates.rb', line 179

def sync(params = {})
  parsed, options = Zavudev::TemplateSyncParams.dump_request(params)
  @client.request(
    method: :post,
    path: "v1/templates/sync",
    body: parsed,
    model: Zavudev::Models::TemplateSyncResponse,
    options: options
  )
end