예제 #1
0
파일: main.go 프로젝트: segfault88/enigma
func main() {
	log.Info("Enigma main")

	accountSid := os.Getenv("TwilioSid")
	authToken := os.Getenv("TwilioToken")

	_ = twirest.NewClient(accountSid, authToken)

	goji.Get("/hello/:name", hello)
	goji.Get("/twiml", basicTwiml)
	goji.Serve()
}
예제 #2
0
func init() {
	twilioSID := os.Getenv("TWILIO_ACCOUNT_SID")
	twilioToken := os.Getenv("TWILIO_AUTH_TOKEN")
	if twilioSID == "" || twilioToken == "" {
		log.Fatal("TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN environment variables must be set.")
	}

	twilioNumber = os.Getenv("TWILIO_NUMBER")
	if twilioNumber == "" {
		log.Fatal("TWILIO_NUMBER environment variable must be set.")
	}
	twilioClient = twirest.NewClient(twilioSID, twilioToken)
}
예제 #3
0
func init_server() {

	bind_address := server_config.Network.BindAddress + ":" + server_config.Network.BindPort

	api_handler := NewApiHandler(&server_config)

	read_timeout, err := time.ParseDuration(server_config.Network.ReadTimeout)
	if err != nil {
		read_timeout = 10 * time.Second
		log.Println("Invalid network timeout", server_config.Network.ReadTimeout)
	}

	write_timeout, err := time.ParseDuration(server_config.Network.WriteTimeout)
	if err != nil {
		write_timeout = 10 * time.Second
		log.Println("Invalid network timeout", server_config.Network.WriteTimeout)
	}

	http_server = http.Server{
		Addr:           bind_address,
		Handler:        api_handler,
		ReadTimeout:    read_timeout,
		WriteTimeout:   write_timeout,
		MaxHeaderBytes: 1 << 20,
	}

	session_manager := NewSessionManager(&server_config)
	twilio_client := twirest.NewClient(server_config.Twilio.SID, server_config.Twilio.Token)
	twilio_messagequeue := make(chan *SMS, 100)
	go workTwilioQueue(twilio_client, twilio_messagequeue)
	api_handler.AddServlet("/version", NewVersionServlet())
	api_handler.AddServlet("/kitchen", NewKitchenServlet(&server_config, session_manager))
	api_handler.AddServlet("/kitchenuser", NewKitchenUserServlet(&server_config, session_manager, twilio_messagequeue))
	api_handler.AddServlet("/mealrequest", NewMealRequestServlet(&server_config, session_manager, twilio_messagequeue))
	api_handler.AddServlet("/host", NewHostServlet(&server_config, session_manager, twilio_messagequeue))
	api_handler.AddServlet("/meal", NewMealServlet(&server_config, session_manager))
	api_handler.AddServlet("/review", NewReviewServlet(&server_config, session_manager, twilio_messagequeue))

	// Start listening to HTTP requests
	if err := http_server.ListenAndServe(); err != nil {
		log.Fatalln("Fatal Error: ListenAndServe: ", err.Error())
	}

	log.Println("Listening on " + bind_address)
}
예제 #4
0
파일: main.go 프로젝트: revmischa/summoner
func TwiREST() *twirest.TwilioClient {
	accountSid := os.Getenv("ACCT_SID")
	authToken := os.Getenv("AUTH_TOKEN")
	client := twirest.NewClient(accountSid, authToken)
	return client
}