Class: Zavudev::Resources::Templates

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

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:



148
149
150
# File 'lib/zavudev/resources/templates.rb', line 148

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