-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
59 lines (51 loc) · 1.19 KB
/
main.go
File metadata and controls
59 lines (51 loc) · 1.19 KB
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
package main
import (
"fmt"
"os"
"strings"
"github.com/chzyer/readline"
"github.com/go-gsm/ucp"
)
func main() {
opt := &ucp.Options{
Addr: fmt.Sprintf("%s:%s", os.Getenv("SMSC_HOST"), os.Getenv("SMSC_PORT")),
User: os.Getenv("SMSC_USER"),
Password: os.Getenv("SMSC_PASSWORD"),
AccessCode: os.Getenv("SMSC_ACCESSCODE"),
}
client := ucp.New(opt)
if err := client.Connect(); err != nil {
fmt.Println("Cant connect")
os.Exit(1)
}
defer client.Close()
reader, _ := readline.New(">>> ")
defer reader.Close()
for {
fmt.Print(">>> ")
lines, _ := reader.Readline()
fields := strings.Fields(lines)
if len(fields) == 1 {
// exit CLI
if fields[0] == "exit" {
return
}
// display help message
if fields[0] == "help" {
fmt.Println("\n\tSend a 'message' to 'receiver' with a 'sender' mask\n\t>>> sender receiver message\n\n\tExit the cli\n\t>>> exit\n")
}
}
// sender receiver message...
if len(fields) >= 3 {
sender := fields[0]
receiver := fields[1]
message := strings.Join(fields[2:], " ")
ids, err := client.Send(sender, receiver, message)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("%v\n", ids)
}
}
}
}