2018-04-03 09:51:06 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2018-04-03 09:54:00 +00:00
|
|
|
"github.com/hamcha/tg"
|
2018-04-03 09:51:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func webhook(rw http.ResponseWriter, req *http.Request) {
|
|
|
|
defer req.Body.Close()
|
|
|
|
|
|
|
|
// Re-encode request to ensure conformity
|
|
|
|
var update tg.APIUpdate
|
|
|
|
err := json.NewDecoder(req.Body).Decode(&update)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("[webhook] Received incorrect request: " + err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.Marshal(tg.BrokerUpdate{
|
|
|
|
Type: tg.BMessage,
|
|
|
|
Message: &(update.Message),
|
|
|
|
Callback: nil,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Println("[webhook] Cannot re-encode json (??) : " + err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
broadcast(string(data))
|
|
|
|
}
|