package main import ( "bytes" "encoding/json" "fmt" "html/template" "log" "net/http" ) type SendToTelegramSync struct { SyncFilterImpl sender Sender logger *log.Logger tpl *template.Template } func (sendToTg *SendToTelegramSync) Call(msg GenericMessage) { err := sendToTg.sender.Send(msg, sendToTg.tpl) if err != nil { // TODO: handle it better panic(err) } sendToTg.CallNext(msg) } type SendToMatterbridgeSync struct { SyncFilterImpl s SatelNameGetter config AppConfig logger *log.Logger tpl *template.Template } func (mbridge *SendToMatterbridgeSync) Call(msg GenericMessage) { for _, matterbridgeConfig := range mbridge.config.Matterbridge { body, err := json.Marshal(MatterbridgeMessage{ Text: msg.Format(mbridge.tpl, mbridge.s, mbridge.logger), Username: matterbridgeConfig.Username, Gateway: matterbridgeConfig.Gateway, }) if err != nil { mbridge.logger.Fatal("Could not marshal a JSON message: ", err) } req, err := http.NewRequest(http.MethodPost, matterbridgeConfig.URI, bytes.NewBuffer(body)) req.Header["Authorization"] = []string{fmt.Sprint("Bearer ", matterbridgeConfig.Token)} client := http.Client{ Timeout: httpTimeout, } res, err := client.Do(req) if err != nil { mbridge.logger.Print("Could not POST ", matterbridgeConfig.URI, ": ", err) return } mbridge.logger.Print("Notified via Matterbridge with result ", res.StatusCode) } mbridge.CallNext(msg) }