Class: Sendly::WhatsAppSignupResource

Inherits:
Object
  • Object
show all
Defined in:
lib/sendly/whatsapp_resource.rb

Overview

Connect numbers to WhatsApp. Starting a signup returns a connect_url a human must complete in a browser.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ WhatsAppSignupResource

Returns a new instance of WhatsAppSignupResource.



294
295
296
# File 'lib/sendly/whatsapp_resource.rb', line 294

def initialize(client)
  @client = client
end

Instance Method Details

#create(phone_number:) ⇒ WhatsAppSignupSession

Start connecting a number to WhatsApp.

Charges a one-time $19 setup fee (no monthly fee) and returns a connect_url. Completing the connection requires a human: hand the URL to your user — they open it in a browser and log in with Facebook to link their WhatsApp Business Account. Then poll #get until the status is "active".

Calling again for a number with an in-flight signup returns the existing signup (same connect_url) without charging again. Requires a live API key.

Examples:

 = client.whatsapp..create(phone_number: "+15559876543")
puts "Open #{.connect_url} and log in with Facebook"

Parameters:

  • phone_number (String)

    The number to connect, in E.164 format. Must be an active number in your workspace.

Returns:

Raises:



317
318
319
320
321
322
# File 'lib/sendly/whatsapp_resource.rb', line 317

def create(phone_number:)
  raise ValidationError, "phone_number is required" if phone_number.nil? || phone_number.to_s.empty?

  response = @client.post("/whatsapp/signup", { phoneNumber: phone_number })
  WhatsAppSignupSession.new(response)
end

#get(id) ⇒ WhatsAppSignup

Get the status of a WhatsApp signup.

Examples:

 = client.whatsapp..get("was_xxx")
puts .failure_reasons if .failed?

Parameters:

  • id (String)

    The signup's id

Returns:

Raises:



333
334
335
336
337
338
339
# File 'lib/sendly/whatsapp_resource.rb', line 333

def get(id)
  raise ValidationError, "id is required" if id.nil? || id.to_s.empty?

  encoded_id = URI.encode_www_form_component(id)
  response = @client.get("/whatsapp/signup/#{encoded_id}")
  WhatsAppSignup.new(response)
end