Go-WhatsApp-Web-Multidevice: Efficient WhatsApp Integration for Software Engineers


Go-WhatsApp-Web-Multidevice: Efficient WhatsApp Integration for Software Engineers

aldinokemal/go-whatsapp-web-multidevice

2025-07-19

go-whatsapp-web-multidevice (GOWA) is essentially a WhatsApp REST API client built with Golang. In simpler terms, it allows your applications to programmatically interact with WhatsApp. Think of it as a bridge that lets your code send and receive WhatsApp messages, manage contacts, and even build chatbots, all without needing to manually use the WhatsApp Web interface.

Automation
This is the big one! You can automate a wide range of tasks that would normally require manual interaction with WhatsApp.

Chatbots & Customer Support
Build intelligent chatbots to answer frequently asked questions, provide 24/7 customer support, or route inquiries to the right human agent.

Notifications & Alerts
Send automated notifications for events like order confirmations, appointment reminders, system alerts, or new lead notifications directly to WhatsApp.

Data Integration
Integrate WhatsApp communication into your existing systems (CRM, ERP, monitoring tools). For example, automatically log WhatsApp conversations in your CRM.

Marketing & Engagement
Send personalized messages to user segments (though be mindful of WhatsApp's policies and spam!).

Internal Communication Tools
Create custom internal tools for team communication or updates.

Performance
Being built with Golang, it's designed for efficient memory use and high concurrency, which is crucial for applications that might handle a large volume of messages.

Multi-Device Support
The "multidevice" aspect is key! This means it leverages WhatsApp's official multi-device feature, making it more robust and less prone to disconnections compared to older methods that relied on single-session WhatsApp Web.

Before diving into code, you'll need to set up your environment.

Go installed
Make sure you have Go (Golang) installed on your system. You can download it from the official Go website.

Basic Go knowledge
Familiarity with Go syntax and module management will be helpful.

WhatsApp Account
You'll need a WhatsApp account that you want to connect to.

Since go-whatsapp-web-multidevice is a Go module, you'll typically include it in your Go project.

Create a new Go module (if you don't have one)

mkdir my-whatsapp-bot
cd my-whatsapp-bot
go mod init my-whatsapp-bot

Download the module

go get github.com/aldinokemal/go-whatsapp-web-multidevice

This command will download the module and add it to your go.mod file.

The general flow for using GOWA will look something like this

Initialize the client
Connect to the WhatsApp servers.

Scan QR Code
When you connect for the first time, you'll need to scan a QR code with your phone's WhatsApp app to link the session (just like WhatsApp Web).

Handle Events
Set up handlers to listen for incoming messages, connection status changes, and other events.

Send Messages
Use the client to send messages.

Let's look at some basic examples to get you started.

This example shows how to initialize the client and keep it running, waiting for the QR code scan.

package main

import (
	"fmt"
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/aldinokemal/go-whatsapp-web-multidevice/client"
	"github.com/aldinokemal/go-whatsapp-web-multidevice/session"
	"github.com/aldinokemal/go-whatsapp-web-multidevice/types" // Import the types package for QR code data
)

func main() {
	// Initialize a new session store. This will store your session data.
	// You might want to use a more persistent store in production (e.g., database, file).
	sess := session.NewMemorySession() 

	// Create a new WhatsApp client
	cli := client.NewClient(sess)

	// Set up an event handler for QR code.
	cli.OnQRCode = func(qrCode types.QrCode) {
		fmt.Println("Scan this QR code with your WhatsApp app:")
		fmt.Println(qrCode.Base64) // This will print the base64 encoded QR code string
		// You'll typically display this QR code to the user, perhaps by converting it to an image.
		// For a simple console app, you can use a QR code generator tool to scan this string.
	}

	// Set up an event handler for successful connection.
	cli.OnConnected = func() {
		fmt.Println(" Successfully connected to WhatsApp!")
	}

	// Set up an event handler for disconnection.
	cli.OnDisconnected = func() {
		fmt.Println(" Disconnected from WhatsApp.")
	}

	// Connect to WhatsApp
	fmt.Println("Connecting to WhatsApp...")
	err := cli.Connect()
	if err != nil {
		log.Fatalf("Failed to connect: %v", err)
	}

	// Keep the application running until a signal is received (e.g., Ctrl+C)
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
	<-c // Wait for an interrupt signal

	fmt.Println("Shutting down...")
	err = cli.Disconnect() // Disconnect gracefully
	if err != nil {
		log.Printf("Error disconnecting: %v", err)
	}
	fmt.Println("Disconnected. Goodbye!")
}

To run this code

Save it as main.go in your my-whatsapp-bot directory.

Run go run main.go.

You'll see a base64 string printed. You'll need to use a base64 to QR code generator (many online tools exist) to convert this string into an actual QR code, then scan it with your WhatsApp mobile app (WhatsApp Settings -> Linked Devices -> Link a Device).

Once connected, you can send messages. This example assumes you have a connected session.

package main

import (
	"fmt"
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/aldinokemal/go-whatsapp-web-multidevice/client"
	"github.com/aldinokemal/go-whatsapp-web-multidevice/session"
	"github.com/aldinokemal/go-whatsapp-web-multidevice/types"
)

func main() {
	sess := session.NewMemorySession() 
	cli := client.NewClient(sess)

	cli.OnQRCode = func(qrCode types.QrCode) {
		fmt.Println("Scan this QR code with your WhatsApp app:")
		fmt.Println(qrCode.Base64)
	}

	cli.OnConnected = func() {
		fmt.Println(" Successfully connected to WhatsApp!")

		// --- SENDING A MESSAGE EXAMPLE ---
		// Replace "[email protected]" with the actual JID of the recipient.
		// For a personal contact, it's typically <phone_number>@s.whatsapp.net.
		// For a group, it's <group_id>@g.us.
		recipientJID := "[email protected]" // <--- IMPORTANT: Change this!
		message := "Hello from my Go WhatsApp bot! "

		fmt.Printf("Sending message to %s...\n", recipientJID)
		_, err := cli.SendMessage(recipientJID, message)
		if err != nil {
			log.Printf("Error sending message: %v", err)
		} else {
			fmt.Println("Message sent successfully!")
		}
		// --- END SENDING EXAMPLE ---
	}

	cli.OnDisconnected = func() {
		fmt.Println(" Disconnected from WhatsApp.")
	}

	fmt.Println("Connecting to WhatsApp...")
	err := cli.Connect()
	if err != nil {
		log.Fatalf("Failed to connect: %v", err)
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
	<-c

	fmt.Println("Shutting down...")
	err = cli.Disconnect()
	if err != nil {
		log.Printf("Error disconnecting: %v", err)
	}
	fmt.Println("Disconnected. Goodbye!")
}

Important
Replace "[email protected]" with the actual WhatsApp JID (Jabber ID) of the recipient. For individual chats, this is typically the phone number followed by @s.whatsapp.net. For example, [email protected].

To build a chatbot, you'll need to listen for incoming messages.

package main

import (
	"fmt"
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/aldinokemal/go-whatsapp-web-multidevice/client"
	"github.com/aldinokemal/go-whatsapp-web-multidevice/session"
	"github.com/aldinokemal/go-whatsapp-web-multidevice/types"
)

func main() {
	sess := session.NewMemorySession() 
	cli := client.NewClient(sess)

	cli.OnQRCode = func(qrCode types.QrCode) {
		fmt.Println("Scan this QR code with your WhatsApp app:")
		fmt.Println(qrCode.Base64)
	}

	cli.OnConnected = func() {
		fmt.Println(" Successfully connected to WhatsApp! Listening for messages...")
	}

	cli.OnDisconnected = func() {
		fmt.Println(" Disconnected from WhatsApp.")
	}

	// --- RECEIVING MESSAGES EXAMPLE ---
	cli.OnMessage = func(message *types.Message) {
		fmt.Printf(" Received message from %s: %s\n", message.Info.Sender, message.Message.GetConversation())

		// Simple echo bot logic
		if message.Message.GetConversation() == "ping" {
			senderJID := message.Info.Sender
			response := "pong!"
			fmt.Printf("Responding to %s with: %s\n", senderJID, response)
			_, err := cli.SendMessage(senderJID, response)
			if err != nil {
				log.Printf("Error sending response: %v", err)
			}
		}
	}
	// --- END RECEIVING EXAMPLE ---

	fmt.Println("Connecting to WhatsApp...")
	err := cli.Connect()
	if err != nil {
		log.Fatalf("Failed to connect: %v", err)
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
	<-c

	fmt.Println("Shutting down...")
	err = cli.Disconnect()
	if err != nil {
		log.Printf("Error disconnecting: %v", err)
	}
	fmt.Println("Disconnected. Goodbye!")
}

This example introduces the OnMessage handler. Whenever a message is received, this function will be called. Inside, you can access the sender's information (message.Info.Sender) and the message content (message.Message.GetConversation()). A simple "ping-pong" bot is implemented as an example.

Persistent Session Storage
In a real-world application, you wouldn't use session.NewMemorySession(). You'd want to save the session data to a file or database so you don't have to scan the QR code every time your application restarts. The library likely has examples or interfaces for this.

Error Handling
The examples are basic. In production, you'd need more robust error handling and retry mechanisms.

WhatsApp Policies
Be aware of WhatsApp's policies regarding automated messaging. Sending spam or violating their terms of service can lead to your number being banned.

Message Types
WhatsApp supports various message types (images, videos, documents, stickers, etc.). Explore the library's capabilities to send and receive these.

Webhook Support
The project description mentions "Webhooks." This is a fantastic feature for integrating with other services. Instead of constantly polling for new messages, WhatsApp can "push" updates to your application via a webhook URL. This is much more efficient.

API vs. Library
This is a Go library that acts as a client. If you're building a service that needs to be consumed by other programming languages, you'd typically wrap this Go application in a REST API (using Go's net/http or a framework like Gin/Echo) and expose endpoints for sending messages or retrieving message history. This is where the "WhatsApp REST API" aspect of GOWA comes in handy.


aldinokemal/go-whatsapp-web-multidevice




Taming Discord: Resource-Efficient Communication with the discordo TUI Client

discordo is a lightweight, secure, and feature-rich terminal user interface (TUI) client for Discord, built using Go.From a software engineer's standpoint


An Introduction to Charmbracelet/Bubble Tea

Here's a breakdown of its benefits for software engineers, how to get started, and a simple code example.From a software engineer's perspective


Infisical: Secure Secret Management for Developers

Imagine you're building an application. Your code needs to talk to databases, external APIs, and various services. Each of these interactions often requires sensitive credentials like API keys


From Manual to Automated: Leveraging autobrr/qui for Multi-Instance Torrent Orchestration

autobrr/qui is exactly that kind of tool. If you’re managing multiple torrent instances or trying to maintain a healthy seeding ratio across different trackers


Mastering Media Streams: An Engineer's Look at bluenviron/mediamtx

In a nutshell, bluenviron/mediamtx is a versatile media server and media proxy built with Go (Golang). Think of it as a central hub for all your video and audio streams


Moby Project: Your Gateway to Custom Containerization

Here's how Moby can be incredibly useful from a software engineer's perspective, along with how to get started and some conceptual code examples


Mastering Redis with the Go-Redis Library

As a software engineer, you'll often encounter situations where you need a fast, reliable, and scalable way to handle data


How to Use tulir/whatsmeow for Custom WhatsApp Alerts in Go

tulir/whatsmeow is a Go (Golang) library that implements the communication protocol for WhatsApp's multi-device feature


High-Performance RPC: An Engineer's Look at grpc-go

At its core, grpc-go is a library that allows you to define and call remote procedures (RPCs) as if they were local function calls


Simplifying Command-Line Interfaces with spf13/cobra for Software Engineers

spf13/cobra (often simply called Cobra) is a library for Go that provides a simple and effective framework for creating powerful modern CLI applications