-
Notifications
You must be signed in to change notification settings - Fork 13
/
sms.go
121 lines (106 loc) · 3.34 KB
/
sms.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package registry
import (
"errors"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/clock"
"github.com/coretrix/hitrix/service/component/config"
"github.com/coretrix/hitrix/service/component/sms"
"github.com/sarulabs/di"
)
func ServiceProviderSMS(entity sms.LogEntity) *service.DefinitionGlobal {
return &service.DefinitionGlobal{
Name: service.SMSService,
Build: func(ctn di.Container) (interface{}, error) {
clockService := ctn.Get(service.ClockService).(clock.IClock)
configService := ctn.Get("config").(config.IConfig)
// register twilio
sid, ok := configService.String("sms.twilio.sid")
if !ok {
return nil, errors.New("missing sms.twilio.sid")
}
token, ok := configService.String("sms.twilio.token")
if !ok {
return nil, errors.New("missing sms.twilio.token")
}
fromNumberTwilio, ok := configService.String("sms.twilio.from_number")
if !ok {
return nil, errors.New("missing sms.twilio.from_number")
}
authyURL, ok := configService.String("sms.twilio.authy_url")
if !ok {
return nil, errors.New("missing sms.twilio.authy_url")
}
authyAPIKey, ok := configService.String("sms.twilio.authy_api_key")
if !ok {
return nil, errors.New("missing sms.twilio.authy_api_key")
}
verifyURL, _ := configService.String("sms.twilio.verify_url")
verifySID, _ := configService.String("sms.twilio.verify_sid")
twilioGateway := &sms.TwilioGateway{
SID: sid,
Token: token,
FromNumber: fromNumberTwilio,
AuthyURL: authyURL,
AuthyAPIKey: authyAPIKey,
VerifyURL: verifyURL,
VerifySID: verifySID,
}
//register sinch
appID, ok := configService.String("sms.sinch.app_id")
if !ok {
return nil, errors.New("missing sms.sinch.app_id")
}
appSecret, ok := configService.String("sms.sinch.app_secret")
if !ok {
return nil, errors.New("missing sms.sinch.app_secret")
}
msgURL, ok := configService.String("sms.sinch.msg_url")
if !ok {
return nil, errors.New("missing sms.sinch.msg_url")
}
fromNumberSinch, ok := configService.String("sms.sinch.from_number")
if !ok {
return nil, errors.New("missing sms.sinch.from_number")
}
callURL, ok := configService.String("sms.sinch.call_url")
if !ok {
return nil, errors.New("missing sms.sinch.call_url")
}
callerNumber, ok := configService.String("sms.sinch.caller_number")
if !ok {
return nil, errors.New("missing sms.sinch.caller_number")
}
sinchGateway := &sms.SinchGateway{
Clock: clockService,
AppID: appID,
AppSecret: appSecret,
MsgURL: msgURL,
FromNumber: fromNumberSinch,
CallURL: callURL,
CallerNumber: callerNumber,
}
// register kavenegar
apiKey, ok := configService.String("sms.kavenegar.api_key")
if !ok {
return nil, errors.New("missing sms.kavenegar.api_key")
}
sender, ok := configService.String("sms.kavenegar.sender")
if !ok {
return nil, errors.New("missing sms.kavenegar.sender")
}
kavenegarGateway := &sms.KavenegarGateway{
APIKey: apiKey,
Sender: sender,
}
return &sms.Sender{
Logger: entity,
Clock: clockService,
GatewayFactory: map[string]sms.Gateway{
sms.Twilio: twilioGateway,
sms.Sinch: sinchGateway,
sms.Kavenegar: kavenegarGateway,
},
}, nil
},
}
}