summaryrefslogtreecommitdiff
path: root/adapters/messaging/ntfy.go
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/messaging/ntfy.go')
-rw-r--r--adapters/messaging/ntfy.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/adapters/messaging/ntfy.go b/adapters/messaging/ntfy.go
new file mode 100644
index 0000000..837c01b
--- /dev/null
+++ b/adapters/messaging/ntfy.go
@@ -0,0 +1,35 @@
+package messaging
+
+import (
+ "fmt"
+ "log"
+ "net/http"
+ "strings"
+
+ "git.simponic.xyz/simponic/phoneof/utils"
+)
+
+func SendNtfy(topic string, 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)
+ }
+ encodedMsg := fmt.Sprintf(`{"message": "%s", "topic": "%s"}`, utils.Quote(message.Message), 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)
+ }
+ }
+}