Skip to main content

Installation

# Gemfile
gem "whatsrb_cloud"
bundle install

Setup

require "whatsrb_cloud"

WhatsrbCloud.configure do |c|
  c.api_key = ENV["WHATSRB_API_KEY"]
end

client = WhatsrbCloud::Client.new
Or pass the key directly:
client = WhatsrbCloud::Client.new(api_key: "wrb_live_xxx")

Quick example

# List your business accounts
accounts = client.business_accounts.list
account  = accounts.data.first

# Send a text message
account.send_text(to: "+33612345678", text: "Hello!")

# Send a template
account.send_template(
  to: "+33612345678",
  template_name: "order_confirmation",
  template_language: "en_US"
)

Resources

Error handling

All SDK methods raise typed exceptions:
begin
  account.send_text(to: "+33612345678", text: "Hello!")
rescue WhatsrbCloud::AuthenticationError => e
  # Invalid API key
rescue WhatsrbCloud::NotFoundError => e
  # Account not found
rescue WhatsrbCloud::RateLimitError => e
  puts "Retry after #{e.retry_after}s"
rescue WhatsrbCloud::ValidationError => e
  # Invalid parameters
rescue WhatsrbCloud::ServerError => e
  # 5xx from the API
rescue WhatsrbCloud::Error => e
  # Base class for all SDK errors
end
ExceptionHTTP status
AuthenticationError401
ForbiddenError403
NotFoundError404
ConflictError409
ValidationError422
RateLimitError429
ServerError5xx