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.
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
|
|
|
|
}
|
|
|
|
|
2016-02-19 11:20:13 +00:00
|
|
|
data, err := json.Marshal(tg.BrokerUpdate{
|
|
|
|
Type: tg.BMessage,
|
|
|
|
Message: &(update.Message),
|
|
|
|
Callback: nil,
|
|
|
|
})
|
2016-02-09 10:04:27 +00:00
|
|
|
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
|
|
|
}
|