WAservix Ruby on Rails integration
Connect WAservix to your Ruby on Rails app: send WhatsApp messages from your own WhatsApp number, check delivery and receive replies by webhook. Copy the examples, add your key and run.
Requirements
Ruby 3+ / Rails 7+ (standard library net/http).
Add your API key
Create a key under WAservix → Devices → API key (it starts with wpk_). Keep it on your server, in an environment variable or secret store. Never put it in a website, a mobile app or a public repository.
# set in your environment or credentials, never commit keys
WASERVIX_KEY=wpk_your_key
WASERVIX_WEBHOOK_SECRET=your_webhook_secret
Set up the client
Base URL https://tekservix.com/waservix/api. Send the key as Authorization: Bearer wpk_….
# app/services/waservix_client.rb
require 'net/http'
require 'json'
class WaservixClient
BASE = 'https://tekservix.com/waservix/api'
def request(verb, path, body = nil)
uri = URI(BASE + path)
req = verb == :post ? Net::HTTP::Post.new(uri) : Net::HTTP::Get.new(uri)
req['Authorization'] = "Bearer #{ENV.fetch('WASERVIX_KEY')}"
if body
req['Content-Type'] = 'application/json'
req.body = body.to_json
end
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 30) { |h| h.request(req) }
json = JSON.parse(res.body)
raise json['message'].to_s unless res.is_a?(Net::HTTPSuccess)
json['data']
end
# methods below go here
end
Send a WhatsApp message
Messages are queued and sent one at a time per number, so the answer comes back at once with "status": "in_progress" and a msgId.
def send_message
request(:post, '/send-message', {
to: '+250788123456',
text: 'Hello Aline, your order is ready'
})
end
Send a document or image
Use imageUrl, videoUrl, audioUrl or documentUrl with a public https link. Groups work too: put the group JID (…@g.us) in to.
def send_document
request(:post, '/send-message', {
to: '+250788123456',
text: 'Your invoice',
documentUrl: 'https://example.com/inv-1042.pdf',
fileName: 'Invoice-1042.pdf'
})
end
Check message status
status is queued, sent, delivered, read, played or failed. Webhooks tell you without polling.
def message_status
request(:get, '/messages/58213/info')
end
Receive WhatsApp messages by webhook
Set a webhook URL and events for the number under WAservix → Devices. Each request carries X-Webhook-Signature, which equals that device’s webhook secret. Compare it in constant time, answer 2xx quickly and process the message after answering (we retry 3 times).
# app/controllers/wapenda_webhooks_controller.rb
class WaservixWebhooksController < ActionController::API # API controllers skip CSRF
def create
return head :unauthorized unless ActiveSupport::SecurityUtils.secure_compare(ENV.fetch('WASERVIX_WEBHOOK_SECRET'), request.headers['X-Webhook-Signature'].to_s)
event = JSON.parse(request.raw_post)
if event['event'] == 'messages.received'
m = event.dig('data', 'messages')
Rails.logger.info("WhatsApp from #{m.dig('key', 'cleanedSenderPn')}: #{m['messageBody']}")
end
head :ok
end
end
# config/routes.rb
# post '/webhooks/wapenda', to: 'wapenda_webhooks#create'
Errors, limits and retries
Every answer has success; errors add a readable message. 401 means a wrong key, 402 no active plan for this number or phone, 409 the number or phone isn’t connected, 429 too many requests (300 a minute per key): wait for the Retry-After seconds and try again. Retry 5xx and network errors with a back-off, but don’t blindly retry a send that may have worked: check its status first, or you could send twice.
Full list of endpoints and fields: WAservix API reference.
Questions
Is this the official WhatsApp Business API?
No. WAservix links your own number as a companion device, like WhatsApp Web, so there is no Meta approval. Only message people who expect to hear from you: WhatsApp can ban numbers that spam.
Can I call the API from a mobile app or browser?
Don’t. Anyone could read the key from the app or page. Call the API from your server and let your app talk to your server.