package messaging import ( "fmt" "log" "net/http" "strings" "git.simponic.xyz/simponic/phoneof/utils" ) func SendNtfy(ntfyEndpoint string) Continuation { return func(message Message) ContinuationChain { return func(success Continuation, failure Continuation) ContinuationChain { log.Println(message) if message.FrenName != "ntfy" { log.Printf("fren name for message %v is not ntfy so we wont send it there", message) return success(message) } content := strings.SplitN(message.Message, " ", 2) if len(content) < 2 { log.Printf("no topic %s", content) return failure(message) } topic := content[0] msg := content[1] encodedMsg := fmt.Sprintf(`{"message": "%s", "topic": "%s"}`, utils.Quote(msg), utils.Quote(topic)) url := ntfyEndpoint payload := strings.NewReader(encodedMsg) req, _ := http.NewRequest("PUT", url, payload) req.Header.Add("Content-Type", "application/json") res, err := http.DefaultClient.Do(req) if err != nil || res.StatusCode/100 != 2 { log.Printf("got err sending message send req %s %v %s", encodedMsg, res, err) return failure(message) } return success(message) } } }