Пример #1
0
func LoadEnvConfiguration(filename string) *EnvConfiguration {

	conf := configure.New()
	glog.V(0).Infof("Loading configuration from 1. shell variables")
	conf.Use(configure.NewEnvironment())
	if filename != "" {
		glog.V(0).Infof("Loading configuration from 2. json file: %s", filename)
		if file, err := os.Open(filename); err != nil {
			// TODO What if we wanted to pass all configuration via env variables, not possible as of today
			glog.Fatalf("Could not open Environment configuration file: %s", filename)
		} else {
			file.Close()
			conf.Use(configure.NewJSONFromFile(filename))
		}
	}

	// environment specifics
	checkerPhoneNumber := conf.String("GOLAM_CHECKER_NUMBER", "", "the checker phone number to automate new messages check")
	checkerName := conf.String("GOLAM_CHECKER_NAME", "", "to enhance the welcome message of the new messages checker")
	recorderEndpoint := conf.String("GOLAM_RECORDER_ENDPOINT", "", "to receive the recordings")
	recorderUsername := conf.String("GOLAM_RECORDER_USERNAME", "", "credentials to the recorder endpoint")
	recorderPassword := conf.String("GOLAM_RECORDER_PASSWORD", "", "credentials to the recorder endpoint")
	audioEndpoint := conf.String("GOLAM_AUDIO_ENDPOINT", "", "audio files server")
	transcriptsEmail := conf.String("GOLAM_TRANSCRIPTS_EMAIL", "", "to receive transcripts via email")
	dbFilename := conf.String("GOLAM_DATABASE_PATH", "messages.db", "path to the messages database")
	dbResetAtStartup := conf.Bool("GOLAM_DATABASE_RESET", true, "flag to empty messages at startup")

	conf.Parse()

	var env EnvConfiguration
	env.RecorderEndpoint = *recorderEndpoint
	env.RecorderUsername = *recorderUsername
	env.RecorderPassword = *recorderPassword
	env.AudioServerEndpoint = *audioEndpoint
	env.TranscriptsReceiver = "mailto:" + *transcriptsEmail
	env.CheckerPhoneNumber = *checkerPhoneNumber
	env.CheckerFirstName = *checkerName
	env.DBfilename = *dbFilename
	env.DBresetAtStartup = *dbResetAtStartup

	return &env
}
// Load default messages from file
// The file is in json format and contains one or more of the entries:
// - GOLAM_VOICE
// - GOLAM_WELCOME
// - GOLAM_WELCOME_ALT
// - GOLAM_CHECK_NO_MESSAGE
// - GOLAM_CHECK_NEW_MESSAGES
// - GOLAM_RECORDING_OK
// - GOLAM_RECORDING_FAILED
// If an entry is not present, a default english message is added
func LoadMessagesConfiguration(filename string) *I18nMessages {

	conf := configure.New()
	glog.V(0).Infof("Loading env preferences from 1. env variables")
	conf.Use(configure.NewEnvironment())
	if filename != "" {
		glog.V(0).Infof("Loading messages from: %s", filename)
		if file, err := os.Open(filename); err != nil {
			glog.Warningf("Could not open Messages definition, switching to default values", filename)
		} else {
			file.Close()
			conf.Use(configure.NewJSONFromFile(filename))
		}
	}

	// messages
	defaultVoice := conf.String("GOLAM_VOICE", "Vanessa", "defaults to English")
	welcome := conf.String("GOLAM_WELCOME", "Welcome, please leave a message after the beep", "to enhance the welcome message of the new messages checker")
	welcomeAlt := conf.String("GOLAM_WELCOME_ALT", "Sorry we do not take any message currently, please call again later", "alternative message if storage service could not be started")
	checkNoMessage := conf.String("GOLAM_CHECK_NO_MESSAGE", "Hello %s, no new messages. Have a good day !", "")
	checkNewMessage := conf.String("GOLAM_CHECK_NEW_MESSAGES", "Hello %s, you have %d new messages", "")
	recordingOK := conf.String("GOLAM_RECORDING_OK", "Your message is recorded. Have a great day !", "")
	recordingFailed := conf.String("GOLAM_RECORDING_FAILED", "Sorry, we could not record your message. Please try again later", "")

	conf.Parse()

	var messages I18nMessages
	messages.DefaultVoice = tropo.GetVoice(*defaultVoice)
	messages.WelcomeMessage = *welcome
	messages.WelcomeAltMessage = *welcomeAlt
	messages.CheckNewMessages = *checkNewMessage
	messages.CheckNoMessage = *checkNoMessage
	messages.RecordingOKMessage = *recordingOK
	messages.RecordingFailedMessage = *recordingFailed

	return &messages
}
Пример #3
0
func init() {
	conf.Use(configure.NewFlag())
	conf.Use(configure.NewJSONFromFile("config.json"))
}