Getting Started
Requirements
- Ruby >= 3.1
- Node.js >= 18
Installation
Add to your Gemfile:
gem 'whatsapp-ruby'
bundle install
Node dependencies are installed automatically on first connection.
Quick start
require 'whatsapp'
client = Whatsapp.client
# Display QR code on first connection
client.on_qr do |qr_data|
puts qr_data
# Or use the rqrcode gem:
# puts RQRCode::QRCode.new(qr_data).as_ansi
end
client.on_connected { puts "Connected!" }
# Only real-time messages (no history sync)
client.on_message do |msg|
puts "#{msg.from}: #{msg.text}"
end
client.connect
# Send a message
client.send_message(to: "+33612345678", text: "Hello from Ruby!")
# Keep the process alive
sleep
Sending messages
| Method | Description |
|---|---|
send_message(to:, text:) | Text message |
send_message(to:, media: { type: 'image', file: '...' }) | Image |
send_message(to:, media: { type: 'document', file: '...' }) | Document |
send_message(to:, media: { type: 'video', file: '...' }) | Video |
send_message(to:, media: { type: 'audio', file: '...' }) | Audio |
send_message(to:, media: { type: 'sticker', file: '...' }) | Sticker |
send_message(to:, location: { latitude:, longitude: }) | Location |
send_message(to:, contact: { name:, phone: }) | Contact card |
send_message(to:, react: { emoji:, message_id: }) | Reaction |
send_message(to:, text:, quoted_message_id:) | Quoted reply |
send_message(to:, poll: { question:, options:, selectable_count: }) | Poll |
Next steps
- Configuration — all config options
- Rails Integration — model macro, generators, multi-session
- Events & Messages — events, message object, errors
- Architecture — how it works under the hood