Will continue @ home

This commit is contained in:
Hamcha 2016-02-08 17:05:46 +00:00
parent bc28a0faa0
commit f3186708ef
4 changed files with 18 additions and 3 deletions

View file

@ -2,3 +2,6 @@ all: clessy-broker
clessy-broker:
go build -o clessy-broker ./broker
clean:
rm -f clessy-broker

View file

@ -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)
}

View file

@ -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
}
}
}

View file

@ -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"`
}