Whatsapp Business support

This commit is contained in:
2025-12-29 06:23:16 +02:00
parent 09a12560d3
commit ae169f81e4
14 changed files with 2269 additions and 800 deletions

View File

@@ -28,10 +28,22 @@ type ServerConfig struct {
// WhatsAppConfig holds configuration for a WhatsApp account
type WhatsAppConfig struct {
ID string `json:"id"`
PhoneNumber string `json:"phone_number"`
SessionPath string `json:"session_path"`
ShowQR bool `json:"show_qr,omitempty"`
ID string `json:"id"`
Type string `json:"type"` // "whatsmeow" or "business-api"
PhoneNumber string `json:"phone_number"`
SessionPath string `json:"session_path,omitempty"`
ShowQR bool `json:"show_qr,omitempty"`
BusinessAPI *BusinessAPIConfig `json:"business_api,omitempty"`
}
// BusinessAPIConfig holds configuration for WhatsApp Business API
type BusinessAPIConfig struct {
PhoneNumberID string `json:"phone_number_id"`
AccessToken string `json:"access_token"`
BusinessAccountID string `json:"business_account_id,omitempty"`
APIVersion string `json:"api_version,omitempty"` // Default: v21.0
WebhookPath string `json:"webhook_path,omitempty"`
VerifyToken string `json:"verify_token,omitempty"`
}
// Hook represents a registered webhook
@@ -114,6 +126,19 @@ func Load(path string) (*Config, error) {
cfg.Database.SQLitePath = "./data/events.db"
}
// Default WhatsApp account type to whatsmeow for backwards compatibility
for i := range cfg.WhatsApp {
if cfg.WhatsApp[i].Type == "" {
cfg.WhatsApp[i].Type = "whatsmeow"
}
// Set default API version for Business API
if cfg.WhatsApp[i].Type == "business-api" && cfg.WhatsApp[i].BusinessAPI != nil {
if cfg.WhatsApp[i].BusinessAPI.APIVersion == "" {
cfg.WhatsApp[i].BusinessAPI.APIVersion = "v21.0"
}
}
}
return &cfg, nil
}