Quick start
Link a WhatsApp account with the CLI, place a first call, then do the same from your own Go code.
You need Go (the version in go.mod), ffmpeg on your PATH, a WhatsApp account to call from, and a second number to call. The calling number risks a ban, so use one you can afford to lose.
Build the CLI
git clone https://github.com/zakiego/go-whatsapp-call && cd go-whatsapp-call
go build -o whatsapp-call ./cmd/whatsapp-callLink it as a device
./whatsapp-call linkIt writes qr.png and prints scan qr.png: WhatsApp > Linked devices > Link a device. Open WhatsApp on the phone that owns the calling number, go to Linked devices, tap Link a device and scan the image. The CLI prints linked as ... and keeps the session in whatsapp-call.db in the current folder.
Place a call
./whatsapp-call call 6281234567890 clip.mp3Put the number you're calling in place of 6281234567890, country code first. A leading + and spaces are dropped. ffmpeg decodes the clip to 16 kHz mono. The phone rings for up to 60 s. Once the callee answers, a soft loading sound plays for 3 s, then the clip, then a short closing chime, and the CLI hangs up.
calling 6281234567890 with 3.6s of audio
call 3EB0C0FFEE00000000000000000000AB: answered=true played=4.92s ended by usplayed counts the clip and the closing chime. Progress logs go to stderr.
Speak text instead of a file
With an ElevenLabs API key in a file, -text turns text into speech and calls with it. Flags go before the command:
./whatsapp-call -text "Hello, this is a test call" -elevenlabs-key-file ~/elevenlabs.key call 6281234567890The key is read from the file so it never shows up in your shell history or the process list. The CLI lists every flag.
From your own Go code
call.Play takes a connected whatsmeow client, the callee's JID and the clip as 16 kHz mono float samples. This program reuses the session the CLI linked and plays a clip you converted with ffmpeg first:
ffmpeg -i clip.mp3 -ac 1 -ar 16000 -f f32le clip.f32package main
import (
"context"
"database/sql"
"encoding/binary"
"fmt"
"log"
"math"
"os"
"time"
"go.mau.fi/whatsmeow"
"go.mau.fi/whatsmeow/store/sqlstore"
"go.mau.fi/whatsmeow/types"
"go.mau.fi/whatsmeow/types/events"
waLog "go.mau.fi/whatsmeow/util/log"
_ "modernc.org/sqlite"
"github.com/zakiego/go-whatsapp-call/call"
)
func main() {
ctx := context.Background()
// 16 kHz mono float32, made with:
// ffmpeg -i clip.mp3 -ac 1 -ar 16000 -f f32le clip.f32
raw, err := os.ReadFile("clip.f32")
if err != nil {
log.Fatal(err)
}
pcm := make([]float32, len(raw)/4)
for i := range pcm {
pcm[i] = math.Float32frombits(binary.LittleEndian.Uint32(raw[i*4:]))
}
// The session the CLI's link command made.
db, err := sql.Open("sqlite", "file:whatsapp-call.db?_pragma=foreign_keys(1)&_pragma=busy_timeout(5000)")
if err != nil {
log.Fatal(err)
}
container := sqlstore.NewWithDB(db, "sqlite", waLog.Noop)
if err := container.Upgrade(ctx); err != nil {
log.Fatal(err)
}
device, err := container.GetFirstDevice(ctx)
if err != nil {
log.Fatal(err)
}
client := whatsmeow.NewClient(device, waLog.Noop)
connected := make(chan struct{}, 1)
client.AddEventHandler(func(evt any) {
if _, ok := evt.(*events.Connected); ok {
select {
case connected <- struct{}{}:
default:
}
}
})
if err := client.Connect(); err != nil {
log.Fatal(err)
}
defer client.Disconnect()
<-connected
jid := types.NewJID("6281234567890", types.DefaultUserServer)
res, err := call.Play(ctx, client, jid, pcm, call.Options{LeadIn: 2 * time.Second})
if err != nil {
log.Fatal(err)
}
fmt.Printf("answered=%v played=%s ended by %s\n", res.Answered, res.Played, res.EndedBy)
}Without a LeadInSound, the callee hears 2 s of silence after answering, then the clip. The Go API page covers every option and what Result holds.