Class: Zavudev::Resources::Templates
- Inherits:
-
Object
- Object
- Zavudev::Resources::Templates
- Defined in:
- lib/zavudev/resources/templates.rb,
sig/zavudev/resources/templates.rbs
Instance Method Summary collapse
-
#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.
-
#delete(template_id, request_options: {}) ⇒ nil
Delete template.
-
#initialize(client:) ⇒ Templates
constructor
private
A new instance of Templates.
-
#list(cursor: nil, limit: nil, request_options: {}) ⇒ Zavudev::Internal::Cursor<Zavudev::Models::Template>
List WhatsApp message templates for this project.
-
#retrieve(template_id, request_options: {}) ⇒ Zavudev::Models::Template
Get template.
-
#submit(template_id, sender_id:, category: nil, request_options: {}) ⇒ Zavudev::Models::Template
Submit a WhatsApp template to Meta for approval.
-
#sync(sender_id: nil, request_options: {}) ⇒ Zavudev::Models::TemplateSyncResponse
Some parameter documentations has been truncated, see Models::TemplateSyncParams for more details.
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.
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.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/zavudev/resources/templates.rb', line 44 def create(params) parsed, = Zavudev::TemplateCreateParams.dump_request(params) @client.request( method: :post, path: "v1/templates", body: parsed, model: Zavudev::Template, options: ) end |
#delete(template_id, request_options: {}) ⇒ nil
Delete template
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.
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/zavudev/resources/templates.rb', line 85 def list(params = {}) parsed, = 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: ) end |
#retrieve(template_id, request_options: {}) ⇒ Zavudev::Models::Template
Get template
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.
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/zavudev/resources/templates.rb', line 134 def submit(template_id, params) parsed, = Zavudev::TemplateSubmitParams.dump_request(params) @client.request( method: :post, path: ["v1/templates/%1$s/submit", template_id], body: parsed, model: Zavudev::Template, 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.
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/zavudev/resources/templates.rb', line 179 def sync(params = {}) parsed, = Zavudev::TemplateSyncParams.dump_request(params) @client.request( method: :post, path: "v1/templates/sync", body: parsed, model: Zavudev::Models::TemplateSyncResponse, options: ) end |