Class: Sendly::WhatsAppSendersResource

Inherits:
Object
  • Object
show all
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

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).

Examples:

profile = client.whatsapp.senders.get_profile("+15559876543")
puts profile.display_name
puts profile.about

Parameters:

  • phone_number (String)

    Your WhatsApp-connected sending number, in E.164 format

Returns:

Raises:



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

#listHash

List your WhatsApp senders, newest first. An empty list means no number is connected yet — start one with Sendly::WhatsAppSignupResource#create.

Examples:

client.whatsapp.senders.list[:senders].each do |s|
  puts "#{s.phone_number} (#{s.display_name || 'no name yet'}) — #{s.status}"
end

Returns:

  • (Hash)

    { senders: Array<WhatsAppSender> }



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.

Examples:

client.whatsapp.senders.update_profile("+15559876543",
  about: "Fresh roasted coffee, delivered.",
  website: "https://acme.example"
)

Parameters:

  • phone_number (String)

    Your WhatsApp-connected sending number, in E.164 format

  • display_name (String, nil) (defaults to: nil)

    The business name recipients see

  • about (String, nil) (defaults to: nil)

    Short profile line (max 139 characters)

  • description (String, nil) (defaults to: nil)

    Longer business description (max 512 characters)

  • category (String, nil) (defaults to: nil)

    Business category shown on the profile

  • email (String, nil) (defaults to: nil)

    Contact email shown on the profile

  • website (String, nil) (defaults to: nil)

    Website shown on the profile

  • address (String, nil) (defaults to: nil)

    Business address shown on the profile

Returns:

Raises:



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