Class: Sendly::WhatsAppTemplatesResource
- Inherits:
-
Object
- Object
- Sendly::WhatsAppTemplatesResource
- Defined in:
- lib/sendly/whatsapp_resource.rb
Overview
Manage Meta-reviewed message templates.
Instance Method Summary collapse
-
#create(sender:, name:, language:, category:, body:, header: nil, footer: nil, buttons: nil, examples: nil) ⇒ WhatsAppTemplate
Create a template and submit it to Meta for review.
-
#delete(id) ⇒ WhatsAppTemplateDeletion
Delete a template.
-
#initialize(client) ⇒ WhatsAppTemplatesResource
constructor
A new instance of WhatsAppTemplatesResource.
-
#list ⇒ Hash
List your WhatsApp templates.
-
#update(id, body: nil, header: nil, footer: nil, buttons: nil, examples: nil) ⇒ WhatsAppTemplate
Edit an APPROVED or REJECTED template and resubmit it for review.
Constructor Details
#initialize(client) ⇒ WhatsAppTemplatesResource
Returns a new instance of WhatsAppTemplatesResource.
437 438 439 |
# File 'lib/sendly/whatsapp_resource.rb', line 437 def initialize(client) @client = client end |
Instance Method Details
#create(sender:, name:, language:, category:, body:, header: nil, footer: nil, buttons: nil, examples: nil) ⇒ WhatsAppTemplate
Create a template and submit it to Meta for review.
Review usually takes 24-48h; the template is usable once its status
is "APPROVED". Requires a live API key.
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/sendly/whatsapp_resource.rb', line 491 def create(sender:, name:, language:, category:, body:, header: nil, footer: nil, buttons: nil, examples: nil) raise ValidationError, "sender is required" if sender.nil? || sender.to_s.empty? raise ValidationError, "name is required" if name.nil? || name.to_s.empty? raise ValidationError, "language is required" if language.nil? || language.to_s.empty? raise ValidationError, "category is required" if category.nil? || category.to_s.empty? raise ValidationError, "body is required" if body.nil? || body.to_s.empty? payload = { sender: sender, name: name, language: language, category: category, body: body } payload[:header] = header unless header.nil? payload[:footer] = unless .nil? payload[:buttons] = if payload[:examples] = examples if examples response = @client.post("/whatsapp/templates", payload) WhatsAppTemplate.new(response) end |
#delete(id) ⇒ WhatsAppTemplateDeletion
Delete a template.
Meta locks a deleted template's name for ~30 days — re-creating it
fails with template_name_locked until the lock lifts. To fix a
rejected template, prefer #update. Requires a live API key.
563 564 565 566 567 568 569 |
# File 'lib/sendly/whatsapp_resource.rb', line 563 def delete(id) raise ValidationError, "id is required" if id.nil? || id.to_s.empty? encoded_id = URI.encode_www_form_component(id) response = @client.delete("/whatsapp/templates/#{encoded_id}") WhatsAppTemplateDeletion.new(response) end |
#list ⇒ Hash
List your WhatsApp templates.
449 450 451 452 453 |
# File 'lib/sendly/whatsapp_resource.rb', line 449 def list response = @client.get("/whatsapp/templates") templates = (response["templates"] || []).map { |t| WhatsAppTemplate.new(t) } { templates: templates } end |
#update(id, body: nil, header: nil, footer: nil, buttons: nil, examples: nil) ⇒ WhatsAppTemplate
Edit an APPROVED or REJECTED template and resubmit it for review.
This is the recovery path for rejections: template names are locked for ~30 days after deletion, so editing a rejected template (rather than deleting and re-creating it) is the way to fix it. The updated template goes back to "PENDING" review. Requires a live API key.
536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/sendly/whatsapp_resource.rb', line 536 def update(id, body: nil, header: nil, footer: nil, buttons: nil, examples: nil) raise ValidationError, "id is required" if id.nil? || id.to_s.empty? payload = {} payload[:body] = body unless body.nil? payload[:header] = header unless header.nil? payload[:footer] = unless .nil? payload[:buttons] = unless .nil? payload[:examples] = examples unless examples.nil? encoded_id = URI.encode_www_form_component(id) response = @client.patch("/whatsapp/templates/#{encoded_id}", payload) WhatsAppTemplate.new(response) end |