-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsns_manager.go
43 lines (36 loc) · 939 Bytes
/
sns_manager.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
package sms
import (
"context"
"os"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/sns"
"github.com/adwitiyaio/arka/cloud"
"github.com/adwitiyaio/arka/logger"
)
type snsManager struct {
clm cloud.Manager
client *sns.Client
}
func (snsm *snsManager) initialize() {
config := snsm.clm.GetConfig()
snsm.client = sns.NewFromConfig(config)
}
func (snsm snsManager) SendSms(options Options) (interface{}, error) {
var res []*sns.PublishOutput
for _, recipient := range options.Recipients {
input := &sns.PublishInput{
Message: aws.String(options.Message),
PhoneNumber: aws.String(recipient),
}
if os.Getenv("CI") == "true" {
return nil, nil
}
out, err := snsm.client.Publish(context.TODO(), input)
if err != nil {
logger.Log.Error().Err(err).Msgf("failed to send SMS for the mobile number, %s", recipient)
continue
}
res = append(res, out)
}
return res, nil
}