-
Notifications
You must be signed in to change notification settings - Fork 0
/
sms.go
40 lines (33 loc) · 856 Bytes
/
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
package sms
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sns"
"log"
)
type TwilioInfo struct {
sid string
authToken string
from string
}
func SendMessage(message, phoneNumber string) error {
return sendThroughSNS(message, phoneNumber)
}
func sendThroughSNS(message, phoneNumber string) error {
sess, err := session.NewSession()
if err != nil {
log.Println("could not start aws session")
return fmt.Errorf("error when startin aws session: %w", err)
}
snsSvc := sns.New(sess)
params := &sns.PublishInput{
Message: aws.String(message),
PhoneNumber: aws.String(phoneNumber),
}
_, err = snsSvc.Publish(params)
if err != nil {
return fmt.Errorf("could not send SMS to friend '%s' with number '%s': %w", err)
}
return nil
}