Files
aura-crm/production/backend/internal/smsgw/smsgw.go
T

39 lines
1.1 KiB
Go

// Package smsgw sends SMS through a pluggable RU aggregator — SMS.ru is the
// only implementation today, but callers depend on the Provider interface,
// not smsru directly, so swapping aggregators later is a new file, not a
// rewrite of every call site.
package smsgw
import (
"context"
"fmt"
"net/http"
"time"
)
// Provider sends a single SMS and returns the aggregator's own message ID
// (stored in client_notifications.provider_message_id for support lookups).
type Provider interface {
Send(ctx context.Context, phoneE164, text string) (messageID string, err error)
}
const sendTimeout = 10 * time.Second
// New builds a Provider for the given name ("smsru" today). test=true asks
// the aggregator to validate the request without actually sending or
// billing — used when settings.sms_enabled is on but the deployment is
// still in dev/staging.
func New(name, apiID, from string, test bool) (Provider, error) {
switch name {
case "", "smsru":
return &smsru{
apiID: apiID,
from: from,
test: test,
client: &http.Client{Timeout: sendTimeout},
}, nil
default:
return nil, fmt.Errorf("unknown SMS provider %q", name)
}
}