This repository has been archived on 2023-07-05. You can view files and clone it, but cannot push or open issues or pull requests.
clessy/broker/webhook.go

30 lines
558 B
Go
Raw Normal View History

2016-02-08 16:52:13 +00:00
package main
import (
2016-02-09 10:04:27 +00:00
"encoding/json"
"log"
2016-02-08 16:52:13 +00:00
"net/http"
2016-02-09 10:04:27 +00:00
2016-02-09 14:55:37 +00:00
"github.com/hamcha/clessy/tg"
2016-02-08 16:52:13 +00:00
)
func webhook(rw http.ResponseWriter, req *http.Request) {
2016-02-09 10:04:27 +00:00
defer req.Body.Close()
// Re-encode request to ensure conformity
var update tg.APIUpdate
err := json.NewDecoder(req.Body).Decode(&update)
2016-02-09 10:01:05 +00:00
if err != nil {
2016-02-09 10:04:27 +00:00
log.Println("[webhook] Received incorrect request: " + err.Error())
return
}
data, err := json.Marshal(update)
if err != nil {
log.Println("[webhook] Cannot re-encode json (??) : " + err.Error())
2016-02-09 10:01:05 +00:00
return
}
2016-02-08 16:52:13 +00:00
2016-02-09 10:01:05 +00:00
broadcast(string(data))
2016-02-08 16:52:13 +00:00
}