Skip to content

Commit

Permalink
feat: send msg with sublabel
Browse files Browse the repository at this point in the history
  • Loading branch information
OldTyT committed Nov 9, 2024
1 parent 41b7cdc commit 28d2d9e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ docker compose up -d
| Variable | Default value | Description |
| ----------- | ----------- | ----------- |
| `TELEGRAM_BOT_TOKEN` | `""`| Token for telegram bot. |
| `FRIGATE_URL` | `http://localhost:5000` | Internal link in frigate. |
| `FRIGATE_URL` | `https://localhost:8971` | Internal link in frigate. |
| `FRIGATE_EVENT_LIMIT` | `20`| Limit the number of events returned. |
| `DEBUG` | `False` | Debug mode. |
| `TELEGRAM_CHAT_ID` | `0` | Telegram chat id. |
| `SLEEP_TIME`| `5` | Sleep time after cycle, in second. |
| `FRIGATE_EXTERNAL_URL` | `http://localhost:5000` | External link in frigate(need for generate link in message). |
| `FRIGATE_EXTERNAL_URL` | `https://localhost:8971` | External link in frigate(need for generate link in message). |
| `TZ` | `""` | Timezone |
| `REDIS_ADDR` | `localhost:6379` | IP and port redis |
| `REDIS_PASSWORD` | `""` | Redis password |
Expand All @@ -48,3 +48,4 @@ docker compose up -d
| `SEND_TEXT_EVENT` | `False` | Send text event without media |
| `FRIGATE_EXCLUDE_CAMERA` | `None` | List exclude frigate camera, separate `,` |
| `FRIGATE_INCLUDE_CAMERA` | `All` | List Include frigate camera, separate `,` |
| `INSECURE_SKIP_VERIFY`| `False` | Ignore certificate on frigate |
6 changes: 4 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Config struct {
WatchDogSleepTime int
EventBeforeSeconds int
SendTextEvent bool
InsecureSkipVerify bool
FrigateIncludeCamera []string
FrigateExcludeCamera []string
}
Expand All @@ -30,20 +31,21 @@ type Config struct {
func New() *Config {
return &Config{
TelegramBotToken: getEnv("TELEGRAM_BOT_TOKEN", ""),
FrigateURL: getEnv("FRIGATE_URL", "http://localhost:5000"),
FrigateURL: getEnv("FRIGATE_URL", "https://localhost:8971"),
FrigateEventLimit: getEnvAsInt("FRIGATE_EVENT_LIMIT", 20),
Debug: getEnvAsBool("DEBUG", false),
TelegramChatID: getEnvAsInt64("TELEGRAM_CHAT_ID", 0),
SleepTime: getEnvAsInt("SLEEP_TIME", 5),
WatchDogSleepTime: getEnvAsInt("WATCH_DOG_SLEEP_TIME", 3),
FrigateExternalURL: getEnv("FRIGATE_EXTERNAL_URL", "http://localhost:5000"),
FrigateExternalURL: getEnv("FRIGATE_EXTERNAL_URL", "https://localhost:8971"),
RedisAddr: getEnv("REDIS_ADDR", "localhost:6379"),
RedisPassword: getEnv("REDIS_PASSWORD", ""),
RedisDB: getEnvAsInt("REDIS_DB", 0),
RedisProtocol: getEnvAsInt("REDIS_PROTOCOL", 3),
RedisTTL: getEnvAsInt("REDIS_TTL", 1209600), // 7 days
EventBeforeSeconds: getEnvAsInt("EVENT_BEFORE_SECONDS", 300),
SendTextEvent: getEnvAsBool("SEND_TEXT_EVENT", false),
InsecureSkipVerify: getEnvAsBool("INSECURE_SKIP_VERIFY", false),
FrigateExcludeCamera: getEnvAsSlice("FRIGATE_EXCLUDE_CAMERA", []string{"None"}, ","),
FrigateIncludeCamera: getEnvAsSlice("FRIGATE_INCLUDE_CAMERA", []string{"All"}, ","),
}
Expand Down
17 changes: 14 additions & 3 deletions internal/frigate/frigate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package frigate

import (
"crypto/tls"
"encoding/base64"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -142,18 +143,23 @@ func GetEvents(FrigateURL string, bot *tgbotapi.BotAPI, SetBefore bool) EventsSt
FrigateURL = FrigateURL + "&before=" + strconv.FormatInt(timestamp, 10)
}

tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: conf.InsecureSkipVerify},
}
client := &http.Client{Transport: tr}

log.Debug.Println("Geting events from Frigate via URL: " + FrigateURL)

// Request to Frigate
resp, err := http.Get(FrigateURL)
resp, err := client.Get(FrigateURL)
if err != nil {
ErrorSend("Error get events from Frigate, error: "+err.Error(), bot, "ALL")
}
defer resp.Body.Close()

// Check response status code
if resp.StatusCode != 200 {
ErrorSend("Response status != 200, when getting events from Frigate.\nExit.", bot, "ALL")
ErrorSend("Response status "+strconv.Itoa(resp.StatusCode)+" != 200, when getting events from Frigate.\nExit.", bot, "ALL")
}

// Read data from response
Expand Down Expand Up @@ -193,8 +199,13 @@ func SaveClip(EventID string, bot *tgbotapi.BotAPI) string {
}
defer f.Close()

tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: conf.InsecureSkipVerify},
}
client := &http.Client{Transport: tr}

// Download clip file
resp, err := http.Get(ClipURL)
resp, err := client.Get(ClipURL)
if err != nil {
ErrorSend("Error clip download: "+err.Error(), bot, EventID)
}
Expand Down

0 comments on commit 28d2d9e

Please sign in to comment.