Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Complete MVP implementation of the Cast GHL Conversation Provider bridge: - Go module setup with chi router and mongo-driver dependencies - Config loading with env var validation and defaults - MongoDB token store with upsert, get, update, delete operations - Cast.ph SMS client with 429 retry logic and typed errors - Phone number normalization (E.164 ↔ Philippine local format) - GHL OAuth 2.0 install/callback/refresh flow - GHL webhook handler with ECDSA signature verification (async dispatch) - GHL API client for message status updates and inbound message stubs - Multi-stage Dockerfile, docker-compose with MongoDB, Woodpecker CI pipeline - Unit tests for phone normalization, Cast client, GHL webhook, and OAuth handlers Co-Authored-By: SideKx <sidekx.ai@sds.dev>
65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
type Config struct {
|
|
Port string
|
|
BaseURL string
|
|
GHLClientID string
|
|
GHLClientSecret string
|
|
GHLWebhookPublicKey string
|
|
GHLConversationProviderID string
|
|
CastAPIKey string
|
|
CastAPIURL string
|
|
CastSenderID string
|
|
MongoURI string
|
|
InboundAPIKey string
|
|
}
|
|
|
|
func Load() (*Config, error) {
|
|
c := &Config{
|
|
Port: getEnvDefault("PORT", "3002"),
|
|
BaseURL: os.Getenv("BASE_URL"),
|
|
GHLClientID: os.Getenv("GHL_CLIENT_ID"),
|
|
GHLClientSecret: os.Getenv("GHL_CLIENT_SECRET"),
|
|
GHLWebhookPublicKey: os.Getenv("GHL_WEBHOOK_PUBLIC_KEY"),
|
|
GHLConversationProviderID: os.Getenv("GHL_CONVERSATION_PROVIDER_ID"),
|
|
CastAPIKey: os.Getenv("CAST_API_KEY"),
|
|
CastAPIURL: getEnvDefault("CAST_API_URL", "https://api.cast.ph"),
|
|
CastSenderID: os.Getenv("CAST_SENDER_ID"),
|
|
MongoURI: os.Getenv("MONGO_URI"),
|
|
InboundAPIKey: os.Getenv("INBOUND_API_KEY"),
|
|
}
|
|
|
|
var missing []string
|
|
required := map[string]string{
|
|
"BASE_URL": c.BaseURL,
|
|
"GHL_CLIENT_ID": c.GHLClientID,
|
|
"GHL_CLIENT_SECRET": c.GHLClientSecret,
|
|
"GHL_WEBHOOK_PUBLIC_KEY": c.GHLWebhookPublicKey,
|
|
"GHL_CONVERSATION_PROVIDER_ID": c.GHLConversationProviderID,
|
|
"CAST_API_KEY": c.CastAPIKey,
|
|
"MONGO_URI": c.MongoURI,
|
|
}
|
|
for key, val := range required {
|
|
if val == "" {
|
|
missing = append(missing, key)
|
|
}
|
|
}
|
|
if len(missing) > 0 {
|
|
return nil, fmt.Errorf("missing required environment variables: %s", strings.Join(missing, ", "))
|
|
}
|
|
return c, nil
|
|
}
|
|
|
|
func getEnvDefault(key, def string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return def
|
|
}
|