dynamically specify topic in text
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Elizabeth Hunt 2025-01-05 15:35:51 -08:00
parent 2984a715b8
commit 6109b9ff73
Signed by: simponic
GPG Key ID: 2909B9A7FF6213EE
3 changed files with 11 additions and 6 deletions

View File

@ -10,4 +10,4 @@ RUN go build -o /app/phoneof
EXPOSE 8080 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"]

View File

@ -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) log.Printf("fren name for message %v is not ntfy so we wont send it there", message)
return success(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 url := ntfyEndpoint
payload := strings.NewReader(encodedMsg) payload := strings.NewReader(encodedMsg)

View File

@ -18,7 +18,6 @@ type Arguments struct {
HttpSmsEndpoint string HttpSmsEndpoint string
NtfyEndpoint string NtfyEndpoint string
NtfyTopic string
Port int Port int
Server bool Server bool
@ -63,8 +62,7 @@ func GetArgs() (*Arguments, error) {
httpSmsEndpoint := flag.String("httpsms-endpoint", "https://httpsms.com", "HTTPSMS endpoint") 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", "NTFY endpoint")
ntfyEndpoint := flag.String("ntfy-endpoint", "https://ntfy.simponic.hatecomputers.club", "HTTPSMS endpoint")
scheduler := flag.Bool("scheduler", false, "Run scheduled jobs via cron") scheduler := flag.Bool("scheduler", false, "Run scheduled jobs via cron")
migrate := flag.Bool("migrate", false, "Run the migrations") migrate := flag.Bool("migrate", false, "Run the migrations")
@ -83,7 +81,6 @@ func GetArgs() (*Arguments, error) {
Migrate: *migrate, Migrate: *migrate,
Scheduler: *scheduler, Scheduler: *scheduler,
HttpSmsEndpoint: *httpSmsEndpoint, HttpSmsEndpoint: *httpSmsEndpoint,
NtfyTopic: *ntfyTopic,
NtfyEndpoint: *ntfyEndpoint, NtfyEndpoint: *ntfyEndpoint,
} }
err := validateArgs(args) err := validateArgs(args)