summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth@simponic.xyz>2025-01-13 21:10:50 -0800
committerElizabeth Hunt <elizabeth@simponic.xyz>2025-01-13 21:10:50 -0800
commitfb7349b69d77557aceb189efbc26497d7470d641 (patch)
treeb7778a2f739772b9499bf934ee7403f0e276e791
parent18a945aab9b3129b82076f633fab1d13ba28148e (diff)
downloadphoneassistant-fb7349b69d77557aceb189efbc26497d7470d641.tar.gz
phoneassistant-fb7349b69d77557aceb189efbc26497d7470d641.zip
add unlock command
-rw-r--r--Dockerfile2
-rw-r--r--main.go7
-rw-r--r--ntfy/assistant/assistant.go23
3 files changed, 29 insertions, 3 deletions
diff --git a/Dockerfile b/Dockerfile
index f82bdb6..696d2fe 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -10,4 +10,4 @@ RUN go build -o /app/phoneassistant
EXPOSE 8080
-CMD ["/app/phoneassistant", "--server", "--migrate", "--port", "8080", "--template-path", "/app/templates", "--database-path", "/app/db/phoneassistant.db", "--static-path", "/app/static", "--scheduler", "--ntfy-topics", "whois", "--ntfy-endpoint", "https://ntfy.simponic.hatecomputers.club"]
+CMD ["/app/phoneassistant", "--server", "--migrate", "--port", "8080", "--template-path", "/app/templates", "--database-path", "/app/db/phoneassistant.db", "--static-path", "/app/static", "--scheduler", "--ntfy-topics", "passt", "--ntfy-endpoint", "https://ntfy.simponic.hatecomputers.club"]
diff --git a/main.go b/main.go
index b721f90..b7aea35 100644
--- a/main.go
+++ b/main.go
@@ -9,6 +9,7 @@ import (
"git.simponic.xyz/simponic/phoneassistant/args"
"git.simponic.xyz/simponic/phoneassistant/database"
"git.simponic.xyz/simponic/phoneassistant/ntfy"
+ "git.simponic.xyz/simponic/phoneassistant/ntfy/assistant"
"git.simponic.xyz/simponic/phoneassistant/scheduler"
"github.com/joho/godotenv"
)
@@ -43,8 +44,10 @@ func main() {
go func() {
for notification := range notifications {
- message := notification.Message
- log.Println("got message", message)
+ err := assistant.Do(notification.Message)
+ if err != nil {
+ log.Println("error when sending command: ", err)
+ }
}
}()
}
diff --git a/ntfy/assistant/assistant.go b/ntfy/assistant/assistant.go
new file mode 100644
index 0000000..3f15647
--- /dev/null
+++ b/ntfy/assistant/assistant.go
@@ -0,0 +1,23 @@
+package assistant
+
+import (
+ "fmt"
+ "net/http"
+ "os"
+)
+
+func UnlockDoor(webhook string) error {
+ req, _ := http.NewRequest("GET", webhook)
+ res, err := http.DefaultClient.Do(req)
+ if err != nil || res.StatusCode/100 != 2 {
+ return fmt.Errorf("got err sending message send req %s %v %s", message, res, err)
+ }
+ return nil
+}
+
+func Do(command string) error {
+ if command == "unlock" {
+ return UnlockDoor(os.Getenv("UNLOCK_DOOR_WEBHOOK"))
+ }
+ return fmt.Errorf("unknown command %s", command)
+}