mirror of
https://github.com/idanoo/go-mastodon-matrix-webhooks.git
synced 2024-11-22 08:25:17 +00:00
Post webhook
This commit is contained in:
parent
87a24c8058
commit
cba0345278
43
main.go
43
main.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@ -95,28 +96,28 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
func sendWebhook(msgText string) error {
|
func sendWebhook(msgText string) error {
|
||||||
log.Println(msgText)
|
log.Println(msgText)
|
||||||
|
|
||||||
// data := MatrixWebhook{
|
data := MatrixWebhook{
|
||||||
// Key: MATRIX_WEBHOOK_API_KEY,
|
Key: MATRIX_WEBHOOK_API_KEY,
|
||||||
// }
|
}
|
||||||
// data.Body = msgText
|
data.Body = msgText
|
||||||
// b, err := json.Marshal(data)
|
b, err := json.Marshal(data)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
// req, err := http.NewRequest("POST", MATRIX_WEBHOOK_URL+"/"+MATRIX_CHANNEL, bytes.NewBuffer(b))
|
req, err := http.NewRequest("POST", MATRIX_WEBHOOK_URL+"/"+MATRIX_CHANNEL, bytes.NewBuffer(b))
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
|
|
||||||
// req.Header.Set("X-Custom-Header", "myvalue")
|
req.Header.Set("X-Custom-Header", "myvalue")
|
||||||
// req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
// client := &http.Client{}
|
client := &http.Client{}
|
||||||
// resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// panic(err)
|
panic(err)
|
||||||
// }
|
}
|
||||||
// defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -139,5 +140,5 @@ func ipLookup(ip string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return "(" + results.Country_long + ")"
|
return " (" + results.Country_long + ")"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user