add unlock command
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Elizabeth Hunt 2025-01-13 21:10:50 -08:00
parent 18a945aab9
commit fb7349b69d
Signed by: simponic
GPG Key ID: 2909B9A7FF6213EE
3 changed files with 29 additions and 3 deletions

View File

@ -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"]

View File

@ -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)
}
}
}()
}

View File

@ -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)
}