-
Notifications
You must be signed in to change notification settings - Fork 46
/
main.go
44 lines (35 loc) · 1.15 KB
/
main.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
// SMS cannot be sent to landline destination number. The Twilio REST API will throw a 400 response with error code 21614, the message will not appear in the logs and the account will not be charged.
package main
import (
"io"
"log"
"os"
flags "github.com/jessevdk/go-flags"
"github.com/sfreiberg/gotwilio"
)
var opts struct {
SID string `short:"s" long:"sid" default:"" description:"accountSid"`
AUTH string `short:"a" long:"auth" default:"" description:"authToken"`
}
func main() {
if len(os.Args) == 1 {
println(`Please ./twilioTest -h`)
} else {
// разбор флагов
flags.Parse(&opts)
// создание файла log для записи ошибок
fLog, err := os.OpenFile(`./.log`, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0640)
if err != nil {
log.Fatalln(err)
}
defer fLog.Close()
// запись ошибок и инфы в файл и вывод
log.SetOutput(io.MultiWriter(fLog, os.Stdout))
twilio := gotwilio.NewTwilioClient(opts.SID, opts.AUTH)
from := "+12013807451"
to := "+79818500301"
message := "Welcome to gotwilio!"
twilio.SendSMS(from, to, message, "", "")
log.Println("Готово")
}
}