-
Notifications
You must be signed in to change notification settings - Fork 13
/
kavenegar_gateway.go
64 lines (50 loc) · 1.37 KB
/
kavenegar_gateway.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
package sms
import (
"fmt"
"github.com/kavenegar/kavenegar-go"
)
type KavenegarGateway struct {
APIKey string
Sender string
}
func (g *KavenegarGateway) SendOTPSMS(otp *OTP) (string, error) {
return g.SendSMSMessage(&Message{
Text: otp.OTP,
Number: otp.Number,
})
}
func (g *KavenegarGateway) SendOTPCallout(otp *OTP) (string, error) {
return g.SendCalloutMessage(&Message{
Text: otp.OTP,
Number: otp.Number,
})
}
func (g *KavenegarGateway) SendSMSMessage(message *Message) (string, error) {
api := kavenegar.New(g.APIKey)
res, err := api.Message.Send(g.Sender, []string{message.Number}, message.Text, nil)
if err != nil {
return err.Error(), err
}
if len(res) < 1 {
e := fmt.Errorf("there was a problem sending sms")
return e.Error(), e
}
return res[0].StatusText, nil
}
func (g *KavenegarGateway) SendCalloutMessage(message *Message) (string, error) {
api := kavenegar.New(g.APIKey)
tts, err := api.Call.MakeTTS(message.Number, message.Text, &kavenegar.CallParam{})
if err != nil {
return err.Error(), err
}
return tts.StatusText, nil
}
func (g *KavenegarGateway) SendVerificationSMS(otp *OTP) (string, error) {
panic("not implemented.")
}
func (g *KavenegarGateway) SendVerificationCallout(otp *OTP) (string, error) {
panic("not implemented.")
}
func (g *KavenegarGateway) VerifyCode(opt *OTP) (string, error) {
panic("not implemented.")
}