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:
+33
-3
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user