Skip to content

Commit

Permalink
Change webhook url to host
Browse files Browse the repository at this point in the history
  • Loading branch information
TuhinNair committed Dec 8, 2020
1 parent fac4566 commit 73c4c38
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions cmd/web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ 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 {
port := os.Getenv("PORT")
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() {
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions cmd/web/twilio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 73c4c38

Please sign in to comment.