Exemple #1
0
// KnockKnock sends a private message to a user.
func (h *HipChat) KnockKnock(d *doorbot.Door, p *doorbot.Person) error {

	log.WithFields(log.Fields{
		"account_id": h.Account.ID,
		"person_id":  p.ID,
		"door_id":    d.ID,
	}).Info("Notificator::HipChat->Notify request")

	c := hipchat.NewClient(h.Token)

	dbb := rendering.DoorbotBar()

	renderingData := map[string]string{
		"name": p.Name,
		"door": d.Name,
	}

	messageRequest := &hipchat.MessageRequest{
		Message: dbb.Render("Hi {{name}},\nThere is someone waiting at the {{door}}.\n\n - Doorbot", renderingData),
		Notify:  true,
	}

	response, err := c.User.Message(p.Email, messageRequest)
	if response.StatusCode != 200 {
		return err
	}

	return nil
}
Exemple #2
0
func (t *Twilio) KnockKnock(d *doorbot.Door, p *doorbot.Person) error {
	log.WithFields(log.Fields{
		"account_id":          t.Account.ID,
		"person_id":           p.ID,
		"person_phone_number": p.PhoneNumber,
		"door_id":             d.ID,
	}).Info("Notificator::Twilio->KnockKnock request")

	from := t.PhoneNumber
	to := p.PhoneNumber

	renderingData := map[string]string{
		"name": p.Name,
		"door": d.Name,
	}

	dbb := rendering.DoorbotBar()

	template := *t.Account.NotificationsSMSMessageTemplate
	if len(template) == 0 {
		template = "Hi {{name}}, there is someone waiting for your at the {{door}}."
	}

	message := dbb.Render(template, renderingData)

	twilio := gotwilio.NewTwilioClient(t.AccountSID, t.Token)
	// was response
	_, exception, err := twilio.SendSMS(from, to, message, "", "")
	if exception != nil {
		log.WithFields(log.Fields{
			"twilio_message": exception.Message,
			"twilio_code":    exception.Code,
			"account_id":     t.Account.ID,
			"person_id":      p.ID,
			"door_id":        d.ID,
			"sms_to":         to,
			"sms_from":       from,
		}).Error("Notificator::Twilio->KnockKnock twilio exception")

		return err
	}

	return nil
}
Exemple #3
0
// KnockKnock sends a private message to a user.
func (p *Postmark) KnockKnock(d *doorbot.Door, person *doorbot.Person) error {
	log.WithFields(log.Fields{
		"account_id": p.Account.ID,
		"person_id":  person.ID,
		"door_id":    d.ID,
	}).Info("Notificator::Postmark->KnockKnock request")

	dbb := rendering.DoorbotBar()

	renderingData := map[string]string{
		"name": person.Name,
		"door": d.Name,
	}

	//TODO HTML message template.
	message := &postmark.Message{
		From:     "*****@*****.**",
		To:       person.Email,
		Subject:  dbb.Render("Doorbot - There is someone waiting at the {{door}}.", renderingData),
		TextBody: dbb.Render("Hi {{name}},\nThere is someone waiting at the {{door}}.\n\n - Doorbot", renderingData),
	}

	pm := postmark.NewPostmark(p.Token)

	_, err := pm.Send(message)

	if err != nil {
		log.WithFields(log.Fields{
			"error":      err,
			"account_id": p.Account.ID,
			"person_id":  person.ID,
			"door_id":    d.ID,
		}).Error("Notificator::Postmark->KnockKnock error")
		return err
	}

	return nil
}