tsk-8: Schedule message (#15)

Closes #8

Reviewed-on: #15
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-11-29 19:28:05 +00:00
committed by phoenix
parent 9af11dc961
commit 04da7785c8
9 changed files with 367 additions and 6 deletions
+33 -3
View File
@@ -5,6 +5,7 @@ import (
"os"
"path"
"git.kundeng.us/phoenix/textsender-models/tx0/config"
"github.com/joho/godotenv"
)
@@ -15,6 +16,7 @@ type App struct {
AuthUrl string
ServiceUsername string
ServicePassphrase string
TwilioConfig *config.TwiloConfig
}
func Load() (*App, error) {
@@ -44,8 +46,36 @@ func Load() (*App, error) {
} else if len(servicePassphrase) == 0 {
return nil, fmt.Errorf("Service passphrase not provided")
} else {
return &App{
ApiUrl: apiUrl, AuthUrl: authUrl, ServiceUsername: serviceUsername, ServicePassphrase: servicePassphrase,
}, nil
if cfg, err := loadTwilioConfig(); err != nil {
return nil, err
} else {
return &App{
ApiUrl: apiUrl, AuthUrl: authUrl, ServiceUsername: serviceUsername, ServicePassphrase: servicePassphrase, TwilioConfig: cfg,
}, nil
}
}
}
func loadTwilioConfig() (*config.TwiloConfig, error) {
authSid := os.Getenv("TWILIO_AUTH_SID")
serviceSid := os.Getenv("TWILIO_SERVICE_SID")
authToken := os.Getenv("TWILIO_AUTH_TOKEN")
phoneNumber := os.Getenv("TWILIO_PHONE_NUMBER")
if len(authSid) == 0 {
return nil, fmt.Errorf("Twilio config auth sid not provided")
} else if len(serviceSid) == 0 {
return nil, fmt.Errorf("Twilio config service sid not provided")
} else if len(authToken) == 0 {
return nil, fmt.Errorf("Twilio config token not provided")
} else if len(phoneNumber) == 0 {
return nil, fmt.Errorf("Twilio config phone number not provided")
} else {
cfg := config.TwiloConfig{}
cfg.AccountSID = authSid
cfg.AuthToken = authToken
cfg.ServiceSID = serviceSid
cfg.Number = phoneNumber
return &cfg, nil
}
}