Skip to content

Commit

Permalink
add TELEGRAM_ALWAYS env configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mol committed Aug 16, 2024
1 parent c407ec2 commit 79da22a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
45 changes: 24 additions & 21 deletions pkg/catoso/catoso.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ import (
)

type Catoso struct {
Config *config.Config
Telegram *telegram.Telegram
ChatId int64
Camera *camera.Camera
Encoder *encoder.Encoder
Vision *vision.Vision
Stream *vision.Stream
Storage *storage.Storage
Context context.Context
Cancel context.CancelFunc
Handlers int
Config *config.Config
Telegram *telegram.Telegram
TelegramAlways bool
ChatId int64
Camera *camera.Camera
Encoder *encoder.Encoder
Vision *vision.Vision
Stream *vision.Stream
Storage *storage.Storage
Context context.Context
Cancel context.CancelFunc
Handlers int
}

func NewCatoso(cfg *config.Config) (*Catoso, error) {
Expand Down Expand Up @@ -117,14 +118,15 @@ func NewCatoso(cfg *config.Config) (*Catoso, error) {
}

return &Catoso{
Config: cfg,
Telegram: tel,
ChatId: chatId,
Camera: cam,
Encoder: enc,
Vision: vis,
Stream: st,
Storage: s,
Config: cfg,
Telegram: tel,
TelegramAlways: cfg.TelegramAlways == "true",
ChatId: chatId,
Camera: cam,
Encoder: enc,
Vision: vis,
Stream: st,
Storage: s,
}, nil

}
Expand Down Expand Up @@ -169,8 +171,9 @@ func (h *Catoso) Start() {
case img := <-cvimg:
if h.Storage != nil && h.Handlers == 0 {
ts := strconv.FormatInt(time.Now().UnixMilli(), 10)
if err := h.Storage.UploadFile(h.Context, "/raw/"+ts+".jpeg", img); err != nil {
log.Println("failed to upload file. falling back to telegram")
err := h.Storage.UploadFile(h.Context, "/raw/"+ts+".jpeg", img)
if err != nil || h.TelegramAlways {
log.Println("sending to telegram")
if err := h.Telegram.SendPhoto(h.ChatId, img); err != nil {
h.Cancel()
log.Println("SendPhoto error: ", err)
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
type Config struct {
TelegramToken string `json:"-"`
TelegramChat string `json:"telegramChat"`
TelegramAlways string `json:"telegramAlways"`
OnvifIP string `json:"onvifIP"`
OnvifPort string `json:"onvifPort"`
InputImage string `json:"inputImage"`
Expand Down Expand Up @@ -37,6 +38,7 @@ func NewConfig() (*Config, error) {
cfg := Config{
TelegramToken: os.Getenv("TELEGRAM_TOKEN"),
TelegramChat: os.Getenv("TELEGRAM_CHAT"),
TelegramAlways: os.Getenv("TELEGRAM_ALWAYS"),
OnvifIP: os.Getenv("ONVIF_IP"),
OnvifPort: os.Getenv("ONVIF_PORT"),
InputImage: os.Getenv("INPUT_IMAGE"),
Expand Down

0 comments on commit 79da22a

Please sign in to comment.