github.com/CyCoreSystems/ari@v4.8.4+incompatible/client/native/textMessage.go (about)

     1  package native
     2  
     3  import "net/url"
     4  
     5  // TextMessage provides the ARI TextMessage accessors for the native client
     6  type TextMessage struct {
     7  	client *Client
     8  }
     9  
    10  // Send sends a text message to an endpoint
    11  func (t *TextMessage) Send(from, tech, resource, body string, vars map[string]string) error {
    12  	// Construct querystring values
    13  	v := url.Values{}
    14  	v.Set("from", from)
    15  	v.Set("body", body)
    16  
    17  	// vars must not be nil, or Ari will reject the request
    18  	if vars == nil {
    19  		vars = map[string]string{}
    20  	}
    21  
    22  	err := t.client.post("/endpoints/"+tech+"/"+resource+"/sendMessage?"+v.Encode(), nil, &vars)
    23  	return err
    24  }
    25  
    26  // SendByURI sends a text message to an endpoint by free-form URI (rather than tech/resource)
    27  func (t *TextMessage) SendByURI(from, to, body string, vars map[string]string) error {
    28  	// Construct querystring values
    29  	v := url.Values{}
    30  	v.Set("from", from)
    31  	v.Set("to", to)
    32  	v.Set("body", body)
    33  
    34  	// vars must not be nil, or Ari will reject the request
    35  	if vars == nil {
    36  		vars = map[string]string{}
    37  	}
    38  
    39  	err := t.client.post("/endpoints/sendMessage?"+v.Encode(), nil, &vars)
    40  	return err
    41  }