A comprehensive Go library for the WhatsApp Business Cloud API. Send messages, handle webhooks, manage templates, and build interactive Flows with a clean, type-safe interface.
- 📱 Complete API Coverage - Messages, webhooks, business management, Flows
- 🔒 Security Built-in - Webhook signature verification, secure token handling
- 🏗️ Framework Agnostic - Works with Gin, Echo, standard HTTP, and more
- 📝 Type Safe - Full type definitions with comprehensive error handling
- 🧪 Testable - Interface-based design for easy mocking
go get github.com/wongpinter/go-whatsapppackage main
import (
"context"
"log"
"github.com/wongpinter/go-whatsapp/cloudapi"
)
func main() {
client := cloudapi.NewClient("PHONE_NUMBER_ID", "ACCESS_TOKEN")
resp, err := client.SendText(context.Background(), "+1234567890", "Hello from Go!")
if err != nil {
log.Fatal(err)
}
log.Printf("Message sent: %s", resp.GetMessageID())
}package main
import (
"context"
"net/http"
"github.com/wongpinter/go-whatsapp/webhook"
)
type Handler struct{}
func (h *Handler) OnTextMessage(ctx context.Context, msg *webhook.Message, metadata *webhook.Metadata) error {
log.Printf("Received: %s from %s", msg.Text.Body, msg.From)
return nil
}
func main() {
handler := webhook.NewHandler("VERIFY_TOKEN", "APP_SECRET", nil)
handler.SetMessageHandler(&Handler{})
http.HandleFunc("/webhook", handler.ServeHTTP)
log.Fatal(http.ListenAndServe(":8080", nil))
}package main
import (
"github.com/wongpinter/go-whatsapp/flows"
)
func main() {
flow := flows.NewFlowBuilder().
SetVersion("3.0").
AddScreen("contact_form").
SetTitle("Contact Information").
AddTextInput("name", "Full Name").SetRequired(true).Done().
AddEmailInput("email", "Email").SetRequired(true).Done().
SetTerminal(true).
Done().
Build()
flowJSON, _ := flow.ToJSON()
log.Printf("Flow created: %s", flowJSON)
}| Package | Purpose | Documentation |
|---|---|---|
cloudapi |
Send messages (text, media, templates) | API Reference |
webhook |
Handle incoming events and messages | Webhook Guide |
flows |
Build and manage WhatsApp Flows | Flows Guide |
bm |
Business Management and templates | BM Guide |
# Required
WHATSAPP_ACCESS_TOKEN=your_access_token
WHATSAPP_PHONE_NUMBER_ID=your_phone_number_id
# For webhooks
WHATSAPP_VERIFY_TOKEN=your_verify_token
WHATSAPP_APP_SECRET=your_app_secretclient := cloudapi.NewClient(phoneNumberID, accessToken,
cloudapi.WithLogger(logger),
cloudapi.WithRateLimiting(80.0),
cloudapi.WithRetryConfig(3, time.Second),
)- Complete Guide - Comprehensive documentation with examples
- API Reference - Detailed API documentation
- Getting Started - Quick navigation and setup guide
- Examples - Working code examples
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- WhatsApp Business API - Official API documentation
- Issues - Report bugs or request features
- Discussions - Community discussions
Made with ❤️ for the Go community