Exemplo n.º 1
0
func (c *SmsClient) SendSms(smsClient twilio.Client, frm, to, msg string) (*twilio.Message, error) {

	if message, err := twilio.NewMessage(smsClient, frm, to, twilio.Body(msg)); err != nil {
		log.Println(err)
		return message, nil
	} else {
		return message, nil
	}
}
Exemplo n.º 2
0
func (tn *TwilioNotification) Clear(check stalker.Check) {
	for _, v := range tn.Recipients {
		message, err := twilio.NewMessage(tn.tc, tn.FromNumber, v, twilio.Body(fmt.Sprintf("%s on %s is up", check.Check, check.Hostname)))
		if err != nil {
			log.Errorf("Error sending notification to %s via twilio: %s\n", v, err.Error())
		} else {
			log.Infof("Sent twilio notification: %+v\n", message)
		}
	}
}
func handleMessage(q *sqs.Queue, m *sqs.Message, h Handler, client twilio.Client, sender string) error {
	var err error
	err = h.HandleMessage(m)
	fmt.Println("Sending the following message : ", m.Body)
	receiver := m.MessageAttribute[1].Value.StringValue // collect the mobile number
	fmt.Println("To : ", receiver)
	fmt.Println("\n")
	message, err2 := twilio.NewMessage(client, sender, receiver, twilio.Body(m.Body))

	// verification
	if err2 != nil {
		fmt.Println(err2)
	} else {
		fmt.Println(message.Status)
	}
	if err != nil {
		return err
	}
	// delete
	_, err = q.DeleteMessage(m)
	return err
}
Exemplo n.º 4
0
func (t *Twilio) Notify(body string) error {
	resp, err := twilio.NewMessage(t.client, t.from, t.to, twilio.Body(body))
	logging.Log.Debugf("Twilio Response: %#v", resp)
	return err
}
Exemplo n.º 5
0
func (smsSender *twilioSenderSms) SendEvents(events notifier.EventsData, contact notifier.ContactData, trigger notifier.TriggerData, throttled bool) error {
	var message bytes.Buffer

	state := events.GetSubjectState()
	tags := trigger.GetTags()

	message.WriteString(fmt.Sprintf("%s %s %s (%d)\n\n", state, trigger.Name, tags, len(events)))

	for _, event := range events {
		value := strconv.FormatFloat(event.Value, 'f', -1, 64)
		message.WriteString(fmt.Sprintf("%s: %s = %s (%s to %s)\n", time.Unix(event.Timestamp, 0).Format("15:04"), event.Metric, value, event.OldState, event.State))
	}

	if len(events) > 5 {
		message.WriteString(fmt.Sprintf("\n...and %d more events.", len(events)-5))
	}

	if throttled {
		message.WriteString("\nPlease, fix your system or tune this trigger to generate less events.")
	}

	smsSender.log.Debug("Calling twilio sms api to phone %s and message body %s", contact.Value, message.String())
	twilioMessage, err := twilio.NewMessage(smsSender.client, smsSender.APIFromPhone, contact.Value, twilio.Body(message.String()))

	if err != nil {
		return fmt.Errorf("Failed to send message to contact %s: %s", contact.Value, err)
	}

	smsSender.log.Debug(fmt.Sprintf("message send to twilio with status: %s", twilioMessage.Status))

	return nil
}