From 73c4c38a02be67f2be64f82068bffd3c666c2918 Mon Sep 17 00:00:00 2001 From: Tuhin Nair Date: Tue, 8 Dec 2020 05:46:36 +0530 Subject: [PATCH] Change webhook url to host --- cmd/web/main.go | 16 ++++++++-------- cmd/web/twilio.go | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/web/main.go b/cmd/web/main.go index 1ef5636..b15a44f 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -11,11 +11,11 @@ import ( ) type config struct { - port string - twilioSID string - twilioAuthToken string - twilioWebhook string - dbURL string + port string + twilioSID string + twilioAuthToken string + twilioWebhookHost string + dbURL string } func loadConfig() *config { @@ -23,10 +23,10 @@ func loadConfig() *config { port = ":" + port twilioSID := os.Getenv("TWILIO_SID") twilioAuthToken := os.Getenv("TWILIO_AUTH_TOKEN") - twilioWebhook := os.Getenv("TWILIO_WEBHOOK") + twilioWebhookHost := os.Getenv("TWILIO_WEBHOOK_HOST") dbURL := os.Getenv("DATABASE_URL") - return &config{port, twilioSID, twilioAuthToken, twilioWebhook, dbURL} + return &config{port, twilioSID, twilioAuthToken, twilioWebhookHost, dbURL} } func main() { @@ -42,7 +42,7 @@ func main() { bot := &Bot{dataview} twilioClient := twilio.NewClient(config.twilioSID, config.twilioAuthToken, nil) - twilioValidator := &twilioValidator{config.twilioWebhook, config.twilioAuthToken} + twilioValidator := &twilioValidator{config.twilioWebhookHost, config.twilioAuthToken} twilioBot := TwilioBot{twilioClient, twilioValidator, bot} mux := http.NewServeMux() diff --git a/cmd/web/twilio.go b/cmd/web/twilio.go index e232427..890d6d7 100644 --- a/cmd/web/twilio.go +++ b/cmd/web/twilio.go @@ -55,21 +55,21 @@ func (tb *TwilioBot) handleWhatsapp(w http.ResponseWriter, r *http.Request) { err := tb.validator.validateRequest(r) if err != nil { - log.Println("Twilio not authenticated") + log.Printf("Twilio not authenticated: %v", err) http.Error(w, http.StatusText(401), 401) return } twilioRequestData, err := tb.parseRequest(r) if err != nil { - log.Println("Malformed request") + log.Printf("Malformed request: %v", err) http.Error(w, http.StatusText(400), 400) return } err = tb.respond(twilioRequestData) if err != nil { - log.Println("Unable to respond") + log.Printf("Unable to respond: %v", err) http.Error(w, http.StatusText(500), 500) } else { w.WriteHeader(200)