-
Notifications
You must be signed in to change notification settings - Fork 2
/
twilio.go
48 lines (38 loc) · 1018 Bytes
/
twilio.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package twilio
import (
"errors"
"github.com/kadisoka/iam/pkg/iamserver/pnv10n"
)
const ServiceName = "twilio"
func init() {
pnv10n.RegisterModule(
ServiceName,
pnv10n.Module{
ConfigSkeleton: func() interface{} { cfg := ConfigSkeleton(); return &cfg },
NewSMSDeliveryService: NewSMSDeliveryService,
})
}
type SMSDeliveryService struct {
config *Config
endpointURL string
}
var _ pnv10n.SMSDeliveryService = &SMSDeliveryService{}
const apiBaseURL = "https://api.twilio.com/2010-04-01/Accounts"
func NewSMSDeliveryService(config interface{}) pnv10n.SMSDeliveryService {
if config == nil {
panic(errors.New("configuration required"))
}
conf, ok := config.(*Config)
if !ok {
panic(errors.New("configuration of invalid type"))
}
if conf.AccountSID == "" {
panic("Twilio Account SID not found")
}
if conf.AuthToken == "" {
panic("Unable to find twilio auth token")
}
return &SMSDeliveryService{
config: conf,
endpointURL: apiBaseURL + "/%s/Messages.json"}
}