summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2025-01-05 15:35:51 -0800
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2025-01-05 15:36:09 -0800
commit6109b9ff733d6bfb9fff4d107036f0b6214662d4 (patch)
tree77496306cdd15f894117975d2fa4c76bf4a52067
parent2984a715b830410b6d6ce2a8aaa1fc8a2388ee99 (diff)
downloadphoneof-6109b9ff733d6bfb9fff4d107036f0b6214662d4.tar.gz
phoneof-6109b9ff733d6bfb9fff4d107036f0b6214662d4.zip
dynamically specify topic in text
-rw-r--r--Dockerfile2
-rw-r--r--adapters/messaging/ntfy.go10
-rw-r--r--args/args.go5
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)