func (tc *Config) SendMessage(to, message string) error {
	if to == "" {
		return errors.New("no phone number specified")
	}
	if message == "" {
		return errors.New("no message specified")
	}
	if len(message) > tc.MaxMsgLen {
		return fmt.Errorf("message exceeeds %d bytes", tc.MaxMsgLen)
	}

	ep := fmt.Sprintf("https://api.twilio.com/%s/Accounts/%s/Messages.json", apiVersion, tc.AccountSid)

	v := url.Values{}
	v.Set("To", to)
	v.Set("From", tc.From)
	v.Set("Body", message)
	vReader := *strings.NewReader(v.Encode())

	client := &http.Client{
		Timeout: tc.Timeout,
	}
	req, err := http.NewRequest("POST", ep, &vReader)
	if err != nil {
		return err
	}
	req.Header.Add("Accept", "application/json")
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	req.SetBasicAuth(tc.AccountSid, tc.authToken)

	var resp *http.Response

	for backOff := time.Second * 0; backOff <= maxBackoff; backOff *= 2 {
		time.Sleep(backOff)
		resp, err = client.Do(req)
		if err != nil {
			return err
		}
		defer resp.Body.Close()
		if resp.StatusCode != 429 { // Too many requests.
			break
		}
	}

	// Although the response is documented here https://www.twilio.com/docs/usage/twilios-response
	// we don't actually care about any of the fields. We return nil in the case of a successful
	// response, and we return the HTTP status message (e.g., "400 BAD REQUEST") otherwise.
	if resp.StatusCode >= 200 && resp.StatusCode < 300 {
		return nil // Success.
	}
	return errors.New(resp.Status) // Failure.
}
// SendMessage sends a message to the specified mobile phone number. It returns nil on success and an error otherwise.
SendMessage sends a message to the specified mobile phone number. It returns nil on success and an error otherwise.
// SendMessage sends a message to the specified mobile phone number . It returns nil on success and an error otherwise .
func (tc *Config) SendMessage(to, message string) error {
	if to == "" {
		return errors.New("no phone number specified")
	}
	if message == "" {
		return errors.New("no message specified")
	}
	if len(message) > tc.MaxMsgLen {
		return fmt.Errorf("message exceeeds %d bytes", tc.MaxMsgLen)
	}
	ep := fmt.Sprintf("https://api.twilio.com/%s/Accounts/%s/Messages.json", apiVersion, tc.AccountSid)
	v := url.Values{}
	v.Set("To", to)
	v.Set("From", tc.From)
	v.Set("Body", message)
	vReader := *strings.NewReader(v.Encode())
	client := &http.Client{
		Timeout: tc.Timeout,
	}
	req, err := http.NewRequest("POST", ep, &vReader)
	if err != nil {
		return err
	}
	req.Header.Add("Accept", "application/json")
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	req.SetBasicAuth(tc.AccountSid, tc.authToken)
	var resp *http.Response
	for backOff := time.Second * 0; backOff <= maxBackoff; backOff *= 2 {
		time.Sleep(backOff)
		resp, err = client.Do(req)
		if err != nil {
			return err
		}
		defer resp.Body.Close()
		if resp.StatusCode != 429 { 
			break
		}
	}
	if resp.StatusCode >= 200 && resp.StatusCode < 300 {
		return nil 
	}
	return errors.New(resp.Status) 
}
func ( tc * Config ) SendMessage ( to , message string ) error { if to == " " { return errors . New ( " " ) } if message == " " { return errors . New ( " " ) } if len ( message ) > tc . MaxMsgLen { return fmt . Errorf ( " " , tc . MaxMsgLen ) } ep := fmt . Sprintf ( " " , apiVersion , tc . AccountSid ) v := url . Values { } v . Set ( " " , to ) v . Set ( " " , tc . From ) v . Set ( " " , message ) vReader := * strings . NewReader ( v . Encode ( ) ) client := & http . Client { Timeout : tc . Timeout , } req , err := http . NewRequest ( " " , ep , & vReader ) if err != nil { return err } req . Header . Add ( " " , " " ) req . Header . Add ( " " , " " ) req . SetBasicAuth ( tc . AccountSid , tc . authToken ) var resp * http . Response for backOff := time . Second * 0 ; backOff <= maxBackoff ; backOff *= 2 { time . Sleep ( backOff ) resp , err = client . Do ( req ) if err != nil { return err } defer resp . Body . Close ( ) if resp . StatusCode != 429 { break } } if resp . StatusCode >= 200 && resp . StatusCode < 300 { return nil } return errors . New ( resp . Status ) }
SendMessage sends a message to the specified mobile phone number.
SendMessage sends a message to the specified mobile phone number .
// Too many requests. // Although the response is documented here https://www.twilio.com/docs/usage/twilios-response // we don't actually care about any of the fields. We return nil in the case of a successful // response, and we return the HTTP status message (e.g., "400 BAD REQUEST") otherwise. // Success. // Failure.