feat(api): add phone number registration endpoint and update related logic
Some checks failed
CI / Test (1.23) (push) Failing after -21m47s
CI / Test (1.22) (push) Failing after -21m38s
CI / Lint (push) Failing after -21m58s
CI / Build (push) Failing after -22m23s

This commit is contained in:
2026-02-21 00:04:16 +02:00
parent 8732b332a1
commit 4a716bb82d
10 changed files with 275 additions and 43 deletions

View File

@@ -51,7 +51,10 @@ func (m *Manager) Connect(ctx context.Context, cfg config.WhatsAppConfig) error
// Factory pattern based on type
switch cfg.Type {
case "business-api":
client, err = businessapi.NewClient(cfg, m.eventBus, m.mediaConfig)
onWABAResolved := func(accountID, wabaID string) {
m.updateWABAInConfig(accountID, wabaID)
}
client, err = businessapi.NewClient(cfg, m.eventBus, m.mediaConfig, onWABAResolved)
case "whatsmeow", "":
// Create callback for phone number updates
onPhoneUpdate := func(accountID, phoneNumber string) {
@@ -187,6 +190,32 @@ func (m *Manager) GetClient(id string) (Client, bool) {
return client, exists
}
// updateWABAInConfig stores the resolved WABA ID back into the in-memory config and syncs to DB/file
func (m *Manager) updateWABAInConfig(accountID, wabaID string) {
m.mu.Lock()
defer m.mu.Unlock()
for i := range m.config.WhatsApp {
if m.config.WhatsApp[i].ID == accountID {
if m.config.WhatsApp[i].BusinessAPI == nil {
return
}
if m.config.WhatsApp[i].BusinessAPI.WABAId == wabaID {
return // already up to date
}
m.config.WhatsApp[i].BusinessAPI.WABAId = wabaID
logging.Info("Updated WABA ID in config", "account_id", accountID, "waba_id", wabaID)
if m.onConfigUpdate != nil {
if err := m.onConfigUpdate(m.config); err != nil {
logging.Error("Failed to save config after WABA ID update", "account_id", accountID, "error", err)
}
}
break
}
}
}
// updatePhoneNumberInConfig updates the phone number for an account in config and saves it
func (m *Manager) updatePhoneNumberInConfig(accountID, phoneNumber string) {
m.mu.Lock()