RUBY QUICKSTART
Send your first WhatsApp message in under 5 minutes. You need a WA Bridges API key - get one from the dashboard.
1. INSTALL
SHELL
gem install sinatra
ENV
export WA_API_KEY="sk_..."
2. PROVISION A BRIDGE
One bridge = one WhatsApp number. customer_ref is your internal identifier (user ID, slug, etc.).
RUBY
require 'net/http'
require 'json'
API_KEY = ENV['WA_API_KEY']
BASE = 'https://wabridges.com/api'
def wa_post(path, body)
uri = URI("#{BASE}#{path}")
req = Net::HTTP::Post.new(uri)
req['Authorization'] = "Bearer #{API_KEY}"
req['Content-Type'] = 'application/json'
req.body = body.to_json
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }
JSON.parse(res.body)
end
bridge = wa_post('/instances', {
customer_ref: 'user-123',
webhook_url: 'https://yourbackend.com/hook'
})
pp bridge
RESPONSE
{"id": 42, "customer_ref": "user-123", "state": "running"}
3. PAIR A PHONE
Request a pairing code. Open WhatsApp on the phone, go to Linked Devices → Link a device → Link with phone number, then enter the code.
RUBY
result = wa_post('/instances/user-123/proxy/pair', { phone: '15550001234' })
puts "Enter this code on the phone: #{result['code']}"
RESPONSE
{"code": "ABCD-EFGH"}
Once paired, the bridge fires a connected webhook event. Poll /proxy/status or wait for the event.
4. SEND A MESSAGE
RUBY
msg = wa_post('/instances/user-123/proxy/send/text', {
chat: '15559876543',
body: 'Hello from the API!'
})
puts msg['message_id']
RESPONSE
{"message_id": "ACE41E...", "timestamp": 1777180605}
5. RECEIVE EVENTS
Inbound messages and events are delivered via POST to your webhook_url. Return 200 immediately.
RUBY
require 'sinatra'
require 'json'
post '/hook' do
payload = JSON.parse(request.body.read)
status 200
if payload['event'] == 'message' && !payload['from_me']
puts "#{payload['name']}: #{payload['body']}"
# reply with wa_post(...)
end
''
end
See the webhook guide for all event types and fields.