Ejemplo n.º 1
0
func (app *AnsweringMachine) checkMessagesHandlerInternal(tropoHandler *tropo.CommunicationHandler, session *tropo.Session, w http.ResponseWriter, req *http.Request) {
	glog.V(3).Infof("checkMessagesHandlerInternal")

	// check if new messages
	messages := app.db.FetchNewMessages()
	nbOfNewMessages := len(messages)
	if nbOfNewMessages == 0 {
		msg := fmt.Sprintf(app.messages.CheckNoMessage, app.env.CheckerFirstName)
		tropoHandler.Say(msg, app.messages.DefaultVoice)
		return
	}

	compo := tropoHandler.NewComposer()
	msg := fmt.Sprintf(app.messages.CheckNewMessages, app.env.CheckerFirstName, nbOfNewMessages)
	compo.AddCommand(&tropo.SayCommand{Message: msg, Voice: app.messages.DefaultVoice})

	// TODO: Say when the message was recorded

	// play first message
	firstMessage := messages[0]
	audioFile := firstMessage.CallID + ".wav"
	audioURI := app.env.AudioServerEndpoint + "/" + audioFile
	compo.AddCommand(&tropo.SayCommand{Message: audioURI})

	// TODO: play next messages
	//     - register event with messageID

	//     - Mark latest message as read (place code below in the commands callback)
	app.db.MarkMessageAsRead(firstMessage)

	tropoHandler.ExecuteComposer(compo)
}
Ejemplo n.º 2
0
func (app *AnsweringMachine) welcomeHandlerInternal(tropoHandler *tropo.CommunicationHandler, session *tropo.Session, w http.ResponseWriter, req *http.Request) {
	glog.V(3).Infof("welcomeHandlerInternal")

	// if no database to record message, say alternate welcome message
	if app.db == nil {
		tropoHandler.Say(app.messages.WelcomeAltMessage, app.messages.DefaultVoice)
		return
	}

	// store the new message entry
	voiceMessage := app.db.CreateVoiceMessage(session.CallID, "+"+session.From.ID)
	if err := app.db.Store(voiceMessage); err != nil {
		// say alternate welcome message
		tropoHandler.Say(app.messages.WelcomeAltMessage, app.messages.DefaultVoice)
		return
	}

	// please leave a message, start recording
	compo := tropoHandler.NewComposer()
	compo.AddCommand(&tropo.SayCommand{Message: app.messages.WelcomeMessage, Voice: app.messages.DefaultVoice})

	choices := tropo.RecordChoices{Terminator: "#"}
	transcript := tropo.RecordTranscription{ID: session.CallID, URL: app.env.TranscriptsReceiver}
	recorderURL := app.env.RecorderEndpoint + "/" + session.CallID + ".wav"
	compo.AddCommand(&tropo.RecordCommand{
		Bargein:       true,
		Attempts:      3,
		Beep:          true,
		Choices:       &choices,
		MaxSilence:    3,
		Timeout:       10,
		MaxTime:       60,
		Name:          "recording",
		URL:           recorderURL,
		Username:      app.env.RecorderUsername,
		Password:      app.env.RecorderPassword,
		AsyncUpload:   true,
		Transcription: &transcript})
	compo.AddCommand(&tropo.OnCommand{Event: "continue", Next: app.routes.RecordingSuccessRoute, Required: true})
	compo.AddCommand(&tropo.OnCommand{Event: "incomplete", Next: app.routes.RecordingIncompleteRoute, Required: true})
	compo.AddCommand(&tropo.OnCommand{Event: "error", Next: app.routes.RecordingFailedRoute, Required: true})

	tropoHandler.ExecuteComposer(compo)
}