Exemple #1
0
// Send Message with options. It's support required and optional parameters.
//
// One of these parameters is required:
//
//	Body     : The text of the message you want to send
//	MediaUrl : The URL of the media you wish to send out with the message. Currently support: gif, png, and jpeg.
//
// Optional parameters:
//
//	StatusCallback : A URL that Twilio will POST to when your message is processed.
//	ApplicationSid : Twilio will POST `MessageSid` as well as other statuses to the URL in the `MessageStatusCallback` property of this application
func (s *MessageService) Send(from, to string, params MessageParams) (*Message, *Response, error) {
	err := params.Validates()
	if err != nil {
		return nil, nil, err
	}

	v := un.StructToMap(&params)
	v.Set("From", from)
	v.Set("To", to)

	return s.Create(v)
}
Exemple #2
0
func StructToMap(it interface{}) url.Values {
	un.BoolFlag = []string{"0", "1"}

	val := un.StructToMap(it)

	// parameterize key names
	for k, v := range val {
		n := inflect.Dasherize(k)

		if k != n {
			val.Del(k)
			val[n] = v
		}
	}

	return val
}
Exemple #3
0
func (s *MessageService) List(params MessageListParams) ([]Message, *Response, error) {
	u := s.client.EndPoint("Messages")
	v := un.StructToMap(&params)

	req, _ := s.client.NewRequest("GET", u.String(), strings.NewReader(v.Encode()))

	// Helper struct for handling the listing
	type list struct {
		Pagination
		Messages []Message `json:"messages"`
	}

	l := new(list)
	resp, err := s.client.Do(req, l)
	if err != nil {
		return nil, resp, err
	}

	resp.Pagination = l.Pagination

	return l.Messages, resp, err
}