diff --git a/Makefile b/Makefile index ab87c5d..c67efd9 100644 --- a/Makefile +++ b/Makefile @@ -2,3 +2,6 @@ all: clessy-broker clessy-broker: go build -o clessy-broker ./broker + +clean: + rm -f clessy-broker diff --git a/broker/main.go b/broker/main.go index 994957f..f518d33 100644 --- a/broker/main.go +++ b/broker/main.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "flag" + "log" "net/http" "os" ) @@ -39,14 +40,17 @@ func main() { // Setup webhook handler go func() { + log.Println("Starting webserver..") http.HandleFunc(config.Token, webhook) err := http.ListenAndServe(config.BindServer, nil) assert(err) }() // Register webhook @ Telegram + log.Println("Registering webhook..") api.setWebhook(config.BaseURL + config.WebhookURL) // Create server for clients + log.Println("Starting clients server..") startClientsServer(config.BindClients) } diff --git a/broker/telegram.go b/broker/telegram.go index d1beb5b..36aefe4 100644 --- a/broker/telegram.go +++ b/broker/telegram.go @@ -1,7 +1,7 @@ package main import ( - "io/ioutil" + "encoding/json" "log" "net/http" "net/url" @@ -23,9 +23,11 @@ func (t Telegram) setWebhook(webhook string) { resp, err := http.PostForm(t.apiURL("setWebhook"), url.Values{"url": {webhook}}) if !checkerr("setWebhook", err) { defer resp.Body.Close() - data, err := ioutil.ReadAll(resp.Body) + var result tg.APIResponse + err = json.NewDecoder(resp.Body).Decode(&result) if err != nil { - log.Printf("setWebhook result: %s\n", string(data)) + log.Println("Could not read reply: " + err.Error()) + return } } } diff --git a/tg/api.go b/tg/api.go index 0d3f573..3432404 100644 --- a/tg/api.go +++ b/tg/api.go @@ -118,3 +118,9 @@ type APIUpdate struct { UpdateID int `json:"update_id"` Message APIMessage `json:"message"` } + +type APIResponse struct { + Ok bool `json:"ok"` + ErrCode *int `json:"error_code,omitempty"` + Description *string `json:"description,omitempty"` +}