Class: Sendly::WhatsAppSendersResource
- Inherits:
-
Object
- Object
- Sendly::WhatsAppSendersResource
- Defined in:
- lib/sendly/whatsapp_resource.rb
Overview
List the numbers connected (or connecting) to WhatsApp, and manage their business profiles.
Instance Method Summary collapse
-
#get_profile(phone_number) ⇒ WhatsAppSenderProfile
Get a sender's WhatsApp business profile.
-
#initialize(client) ⇒ WhatsAppSendersResource
constructor
A new instance of WhatsAppSendersResource.
-
#list ⇒ Hash
List your WhatsApp senders, newest first.
-
#update_profile(phone_number, display_name: nil, about: nil, description: nil, category: nil, email: nil, website: nil, address: nil) ⇒ WhatsAppSenderProfile
Update a sender's WhatsApp business profile.
Constructor Details
#initialize(client) ⇒ WhatsAppSendersResource
Returns a new instance of WhatsAppSendersResource.
345 346 347 |
# File 'lib/sendly/whatsapp_resource.rb', line 345 def initialize(client) @client = client end |
Instance Method Details
#get_profile(phone_number) ⇒ WhatsAppSenderProfile
Get a sender's WhatsApp business profile.
The business profile is what recipients see when they open the
sender's details in WhatsApp: display name, photo, category, about
line, description, and contact details. The sender must be "active"
(connected to WhatsApp).
381 382 383 384 385 386 387 |
# File 'lib/sendly/whatsapp_resource.rb', line 381 def get_profile(phone_number) raise ValidationError, "phone_number is required" if phone_number.nil? || phone_number.to_s.empty? encoded_number = URI.encode_www_form_component(phone_number) response = @client.get("/whatsapp/senders/#{encoded_number}/profile") WhatsAppSenderProfile.new(response) end |
#list ⇒ Hash
List your WhatsApp senders, newest first. An empty list means no number is connected yet — start one with Sendly::WhatsAppSignupResource#create.
359 360 361 362 363 |
# File 'lib/sendly/whatsapp_resource.rb', line 359 def list response = @client.get("/whatsapp/senders") senders = (response["senders"] || []).map { |s| WhatsAppSender.new(s) } { senders: senders } end |
#update_profile(phone_number, display_name: nil, about: nil, description: nil, category: nil, email: nil, website: nil, address: nil) ⇒ WhatsAppSenderProfile
Update a sender's WhatsApp business profile.
Pass only the fields to change; omitted fields keep their current
value. about is limited to 139 characters and description to 512.
display_name changes are reviewed by Meta before they take effect.
The profile photo cannot be set through this method. Requires a live
API key.
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'lib/sendly/whatsapp_resource.rb', line 415 def update_profile(phone_number, display_name: nil, about: nil, description: nil, category: nil, email: nil, website: nil, address: nil) raise ValidationError, "phone_number is required" if phone_number.nil? || phone_number.to_s.empty? body = {} body[:displayName] = display_name unless display_name.nil? body[:about] = about unless about.nil? body[:description] = description unless description.nil? body[:category] = category unless category.nil? body[:email] = email unless email.nil? body[:website] = website unless website.nil? body[:address] = address unless address.nil? raise ValidationError, "Provide at least one profile field to update" if body.empty? encoded_number = URI.encode_www_form_component(phone_number) response = @client.patch("/whatsapp/senders/#{encoded_number}/profile", body) WhatsAppSenderProfile.new(response) end |