-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsms.go
More file actions
66 lines (60 loc) · 1.5 KB
/
sms.go
File metadata and controls
66 lines (60 loc) · 1.5 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
60
61
62
63
64
65
66
package termux
import (
"bytes"
"encoding/json"
)
// SMSBoxType enumberates available sms box types
type SMSBoxType int
const (
// All sms box type
All SMSBoxType = 0
// Inbox sms box type
Inbox SMSBoxType = 1
// Sent sms box type
Sent SMSBoxType = 2
// Draft sms box type
Draft SMSBoxType = 3
// Outbox sms box type
Outbox SMSBoxType = 4
)
// SMS represents a piece of received SMS
type SMS struct {
ThreadID int `json:"threadid"`
Type string `json:"type"`
Read bool `json:"read"`
Sender string `json:"sender"`
Number string `json:"number"`
Received string `json:"received"`
Body string `json:"body"`
}
// SMSList acquires a list of the received SMS in the given SMS box with a given limit and offset
func SMSList(limit int, offset int, box SMSBoxType) ([]SMS, error) {
buf := bytes.NewBuffer([]byte{})
if err := exec(nil, buf, "SmsInbox", map[string]interface{}{
"type": box,
"limit": limit,
"offset": offset,
}, ""); err != nil {
return nil, err
}
res := buf.Bytes()
if err := checkErr(res); err != nil {
return nil, err
}
l := make([]SMS, 0)
if err := json.Unmarshal(res, l); err != nil {
return nil, err
}
return l, nil
}
// SMSSend sends a text message to the given recipient numbers
func SMSSend(numbers []string, text string) error {
in := bytes.NewBufferString(text)
buf := bytes.NewBuffer([]byte{})
if err := exec(in, buf, "SmsSend", map[string]interface{}{
"recipients": numbers,
}, ""); err != nil {
return err
}
return checkErr(buf.Bytes())
}