forked from an/flokati
make token a parameter
This commit is contained in:
parent
23f324ccad
commit
df0303ebcf
|
@ -7,14 +7,14 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.dnix.de/an/xlog"
|
"git.dnix.de/an/xlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
webhookPort = flag.String("webhook_port", "8080", "Webhook listener port")
|
webhookPort = flag.String("webhook_port", "8080", "Webhook listener port")
|
||||||
webhookChan = flag.String("webhook_chan", "", "Channel to post into")
|
webhookChan = flag.String("webhook_chan", "", "Channel to post into")
|
||||||
|
webhookToken = flag.String("webhook_token", "", "Token")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -24,24 +24,10 @@ func init() {
|
||||||
|
|
||||||
func webhookRun() {
|
func webhookRun() {
|
||||||
xlog.Info("webhook listener started")
|
xlog.Info("webhook listener started")
|
||||||
http.HandleFunc("/webhook", webhookHandleHTTP)
|
http.HandleFunc("/webhook/"+*webhookToken, webhookHandleHTTP)
|
||||||
xlog.Fatal("%v", http.ListenAndServe(":"+*webhookPort, nil))
|
xlog.Fatal("%v", http.ListenAndServe(":"+*webhookPort, nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func webhookHandleMessage(m *Message) {
|
|
||||||
tok := strings.Split(m.Text, " ")
|
|
||||||
if len(tok) < 1 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
switch tok[0] {
|
|
||||||
case "!webhook-add":
|
|
||||||
if len(tok) > 1 {
|
|
||||||
http.HandleFunc("/webhook/"+tok[1], webhookHandleHTTP)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func webhookHandleHTTP(w http.ResponseWriter, r *http.Request) {
|
func webhookHandleHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
data := make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
err := json.NewDecoder(r.Body).Decode(&data)
|
err := json.NewDecoder(r.Body).Decode(&data)
|
||||||
|
|
Loading…
Reference in New Issue