Example #1
0
// HandleCreateMessage
func HandleCreateMessage(e *config.Env, w http.ResponseWriter, r *http.Request) (int, error) {
	r.ParseForm()

	jobrunner.Now(CreateMessageAndPushToDevice{TwilioResponse: r.Form, Env: e})

	return http.StatusOK, nil
}
Example #2
0
// HandleVisitSurveysCreate -
func HandleVisitSurveysCreate(e *config.Env, w http.ResponseWriter, r *http.Request) (int, error) {
	v := visit.Visit{ID: mux.Vars(r)["id"]}

	sCode, err := v.Get(e)

	if err != nil {
		return sCode, err
	}

	// Push survey only once.
	if !v.Survey {
		statusCode, err := visit.AddSurveyByVisitID(e, v.ID)

		if err != nil {
			return statusCode, err
		}

		// Send precanned message to user...
		m := message.Message{
			VisitID:    v.ID,
			Text:       "Thanks for taking the time to visit us today! I just wanted to follow-up personally and see how your visit went. Thanks! -Samantha",
			IsBusiness: true,
		}

		jobrunner.Now(jobs.PushToTwilio{Env: e, Message: m})
	}

	return http.StatusOK, nil

}
Example #3
0
// HandleVisitMessagesCreate (GET)
//   params: id (id)
func HandleVisitMessagesCreate(e *config.Env, w http.ResponseWriter, r *http.Request) (int, error) {
	vID := mux.Vars(r)["id"]

	decoder := json.NewDecoder(r.Body)
	var m message.Message
	err := decoder.Decode(&m)

	if err != nil {
		return http.StatusBadRequest, err
	}

	m.VisitID = vID

	sCode, err := m.Create(e)

	if err != nil {
		return sCode, err
	}

	ms := make([]message.Message, 1)

	ms[0] = m

	writeJSONMessages(w, &ms)

	jobrunner.Now(jobs.PushToTwilio{Env: e, Message: m})

	return http.StatusOK, nil
}
Example #4
0
func (m CreateMessageAndPushToDevice) Run() {
	v := visit.Visit{PhoneNumber: m.TwilioResponse.Get("From")}

	_, err := v.GetByPhoneNumber(m.Env)

	if err != nil {
		logError(m.Env, err)
	}

	// Handle survey right off the bat.
	if v.Survey {
		// Send precanned message to user...
		msg := message.Message{
			VisitID:    v.ID,
			Text:       "Thanks for getting back to me, I really appreciate it :) -Samantha",
			IsBusiness: true,
		}

		_, err = msg.Create(m.Env)

		if err != nil {
			logError(m.Env, err)
		}

		jobrunner.Now(jobs.PushToTwilio{Env: m.Env, Message: msg})
	} else {
		msg := message.Message{
			Text:       m.TwilioResponse.Get("Body"),
			IsBusiness: false,
			VisitID:    v.ID,
		}

		_, err = msg.Create(m.Env)

		if err != nil {
			logError(m.Env, err)
		}

		msgs := make([]message.Message, 1)

		msgs[0] = msg

		pushToDevice(msgs)
	}
}