From 6109b9ff733d6bfb9fff4d107036f0b6214662d4 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 5 Jan 2025 15:35:51 -0800 Subject: [PATCH] dynamically specify topic in text --- Dockerfile | 2 +- adapters/messaging/ntfy.go | 10 +++++++++- args/args.go | 5 +---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 68c157a..80f5e05 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,4 @@ RUN go build -o /app/phoneof EXPOSE 8080 -CMD ["/app/phoneof", "--server", "--migrate", "--port", "8080", "--template-path", "/app/templates", "--database-path", "/app/db/phoneof.db", "--static-path", "/app/static", "--scheduler", "--httpsms-endpoint", "https://httpsms.internal.simponic.xyz", "--ntfy-endpoint", "https://ntfy.simponic.hatecomputers.club", "--ntfy-topic", "sms"] +CMD ["/app/phoneof", "--server", "--migrate", "--port", "8080", "--template-path", "/app/templates", "--database-path", "/app/db/phoneof.db", "--static-path", "/app/static", "--scheduler", "--httpsms-endpoint", "https://httpsms.internal.simponic.xyz", "--ntfy-endpoint", "https://ntfy.simponic.hatecomputers.club"] diff --git a/adapters/messaging/ntfy.go b/adapters/messaging/ntfy.go index 837c01b..9c68f3a 100644 --- a/adapters/messaging/ntfy.go +++ b/adapters/messaging/ntfy.go @@ -17,7 +17,15 @@ func SendNtfy(topic string, ntfyEndpoint string) Continuation { 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)) + 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) diff --git a/args/args.go b/args/args.go index 6c112c6..ae18865 100644 --- a/args/args.go +++ b/args/args.go @@ -18,7 +18,6 @@ type Arguments struct { HttpSmsEndpoint string NtfyEndpoint string - NtfyTopic string Port int Server bool @@ -63,8 +62,7 @@ func GetArgs() (*Arguments, error) { httpSmsEndpoint := flag.String("httpsms-endpoint", "https://httpsms.com", "HTTPSMS endpoint") - ntfyTopic := flag.String("ntfy-topic", "sms", "NTFY endpoint") - ntfyEndpoint := flag.String("ntfy-endpoint", "https://ntfy.simponic.hatecomputers.club", "HTTPSMS endpoint") + ntfyEndpoint := flag.String("ntfy-endpoint", "https://ntfy.simponic.hatecomputers.club", "NTFY endpoint") scheduler := flag.Bool("scheduler", false, "Run scheduled jobs via cron") migrate := flag.Bool("migrate", false, "Run the migrations") @@ -83,7 +81,6 @@ func GetArgs() (*Arguments, error) { Migrate: *migrate, Scheduler: *scheduler, HttpSmsEndpoint: *httpSmsEndpoint, - NtfyTopic: *ntfyTopic, NtfyEndpoint: *ntfyEndpoint, } err := validateArgs(args)