Skip to content
Snippets Groups Projects
Verified Commit 93be414e authored by Réthelyi Bálint's avatar Réthelyi Bálint :no_mouth:
Browse files

send message

parent 2ce88b8e
Branches
No related tags found
No related merge requests found
package server package server
import ( import (
"bytes"
"fmt" "fmt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"gitlab.com/MikeTTh/env" "gitlab.com/MikeTTh/env"
...@@ -93,9 +94,45 @@ func sendFile(file multipart.File, fileheader *multipart.FileHeader) { ...@@ -93,9 +94,45 @@ func sendFile(file multipart.File, fileheader *multipart.FileHeader) {
} }
func msgHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
return
}
cook, e := r.Cookie(cookie)
if e != nil {
http.Error(w, "elbasztad", http.StatusTeapot)
return
}
if cook.Value != env.GetOrDosomething("MAGIC_COOKIE", func() string {
panic("i have no magic cookie")
}) {
http.Error(w, "elbasztad", http.StatusTeapot)
return
}
buf := new(bytes.Buffer)
_, e = buf.ReadFrom(r.Body)
if e != nil {
http.Error(w, "valami nem ok", http.StatusTeapot)
return
}
str := buf.String()
msg := tgbotapi.NewMessage(chanId, str)
_, e = DefaultBot.Send(msg)
if e != nil {
fmt.Println(e)
}
}
func Serv() { func Serv() {
mux := http.NewServeMux() mux := http.NewServeMux()
mux.HandleFunc("/in/", inputHandler) mux.HandleFunc("/in/", inputHandler)
mux.HandleFunc("/msg/", msgHandler)
e := http.ListenAndServe(env.String("LISTEN", ":8080"), mux) e := http.ListenAndServe(env.String("LISTEN", ":8080"), mux)
if e != nil { if e != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment