forked from Marquis42/ari
/
textMessage.go
39 lines (31 loc) · 1.04 KB
/
textMessage.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
package native
import "net/url"
// TextMessage provides the ARI TextMessage accessors for the native client
type TextMessage struct {
client *Client
}
// Send sends a text message to an endpoint
func (t *TextMessage) Send(from, tech, resource, body string, vars map[string]string) error {
// Construct querystring values
v := url.Values{}
v.Set("from", from)
v.Set("body", body)
// vars must not be nil, or Ari will reject the request
if vars == nil {
vars = map[string]string{}
}
return t.client.put("/endpoints/"+tech+"/"+resource+"/sendMessage?"+v.Encode(), nil, &vars)
}
// SendByURI sends a text message to an endpoint by free-form URI (rather than tech/resource)
func (t *TextMessage) SendByURI(from, to, body string, vars map[string]string) error {
// Construct querystring values
v := url.Values{}
v.Set("from", from)
v.Set("to", to)
v.Set("body", body)
// vars must not be nil, or Ari will reject the request
if vars == nil {
vars = map[string]string{}
}
return t.client.put("/endpoints/sendMessage?"+v.Encode(), nil, &vars)
}