示例#1
0
func incomingVoicemail(tc *twilio.Client, m mailgun.Mailgun, req *http.Request, log *log.Logger) {
	log.Printf("%#v", req.Form)
	transReq, err := tc.NewRequest("GET", req.FormValue("TranscriptionUrl")+".json", nil)
	if err != nil {
		log.Println("Transcription req build error:", err)
		return
	}
	var trans transcription
	_, err = tc.Do(transReq, &trans)
	if err != nil {
		log.Println("Transcription req error:", err)
		return
	}

	var buf bytes.Buffer
	err = voicemailTemplate.Execute(&buf, &voicemailData{
		From:      req.FormValue("From"),
		Duration:  trans.Duration,
		Recording: req.FormValue("RecordingUrl"),
		Text:      trans.Text,
	})
	if err != nil {
		log.Println("Email template error:", err)
		return
	}

	msg := mailgun.NewMessage("voicemail@"+emailDomain, "New voicemail from "+req.FormValue("From"), buf.String(), emailTo)
	msg.SetDKIM(true)
	_, _, err = m.Send(msg)
	if err != nil {
		log.Println("Voicemail send error:", err)
		return
	}
}
示例#2
0
func incomingSMS(m mailgun.Mailgun, req *http.Request, log *log.Logger) string {
	log.Println(req.Form)
	msg := mailgun.NewMessage(
		req.FormValue("From")+"@"+emailDomain,
		"SMS from "+req.FormValue("From"),
		req.FormValue("Body"),
		emailTo,
	)
	msg.SetDKIM(true)
	_, _, err := m.Send(msg)
	if err != nil {
		log.Println("Email send error:", err)
	} else {
		log.Println("Email sent to", emailTo)
	}
	return twilioResponse("")
}