This commit is contained in:
parent
18a945aab9
commit
fb7349b69d
@ -10,4 +10,4 @@ RUN go build -o /app/phoneassistant
|
|||||||
|
|
||||||
EXPOSE 8080
|
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"]
|
||||||
|
7
main.go
7
main.go
@ -9,6 +9,7 @@ import (
|
|||||||
"git.simponic.xyz/simponic/phoneassistant/args"
|
"git.simponic.xyz/simponic/phoneassistant/args"
|
||||||
"git.simponic.xyz/simponic/phoneassistant/database"
|
"git.simponic.xyz/simponic/phoneassistant/database"
|
||||||
"git.simponic.xyz/simponic/phoneassistant/ntfy"
|
"git.simponic.xyz/simponic/phoneassistant/ntfy"
|
||||||
|
"git.simponic.xyz/simponic/phoneassistant/ntfy/assistant"
|
||||||
"git.simponic.xyz/simponic/phoneassistant/scheduler"
|
"git.simponic.xyz/simponic/phoneassistant/scheduler"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
@ -43,8 +44,10 @@ func main() {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for notification := range notifications {
|
for notification := range notifications {
|
||||||
message := notification.Message
|
err := assistant.Do(notification.Message)
|
||||||
log.Println("got message", message)
|
if err != nil {
|
||||||
|
log.Println("error when sending command: ", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
23
ntfy/assistant/assistant.go
Normal file
23
ntfy/assistant/assistant.go
Normal 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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user