diff --git a/README.md b/README.md index 731d4a8..41a6c1b 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ In other words - treat it as a toy, not as a tool that will save your life or va ## Running ``` -$ TELEGRAM_APITOKEN=YOUR_API_TOKEN ./alarm-bot +$ ./alarm-bot ``` Remember that `hswro-alarm-bot.yml` should be present in the current directory. @@ -32,6 +32,7 @@ allowed-indexes: - 5678 - 1337 pool-interval: 5m +telegram-api-key: "telegram api key" arm-callback-urls: - "http://192.168.1.10/hello" - "http://example.com/api" @@ -51,6 +52,7 @@ matterbridge: - `pool-interval` sets how often will the Satel device be asked for changes - `satel-addr` sets the IP address of the Satel device - `tg-chat-ids` sets which telegram groups will receive notifications about alarm state changes + - `telegram-api-key` sets the Bot API key for Telegram that was obtained from BotFather ### Matterbridge integration @@ -132,7 +134,6 @@ After=network.target [Service] Type=simple ExecStart=/path/to/alarm_bot -Environment=TELEGRAM_APITOKEN=YOUR_API_TOKEN DynamicUser=True RuntimeDirectory=hswro-alarm-bot StateDirectory=hswro-alarm-bot diff --git a/config.go b/config.go index f8fb846..cbbbf43 100644 --- a/config.go +++ b/config.go @@ -44,6 +44,7 @@ type AppConfig struct { AlarmCallbackUrls []string `yaml:"alarm-callback-urls"` WriteMemoryProfile bool `yaml:"write-memory-profile"` Matterbridge []MatterbridgeConfig `yaml:"matterbridge"` + TelegramApiKey string `yaml:"telegram-api-key"` } func (m *SatelChangeType) UnmarshalYAML(unmarshal func(interface{}) error) error { diff --git a/config_test.go b/config_test.go index 46ecf40..8642935 100644 --- a/config_test.go +++ b/config_test.go @@ -32,6 +32,7 @@ disarm-callback-urls: alarm-callback-urls: - "test alarm callback url" - "second test alarm callback url" +telegram-api-key: "test api key" matterbridge: - uri: test_uri_1 token: test_token_1 @@ -56,6 +57,7 @@ func TestParseYamlConfig(t *testing.T) { a.ElementsMatch([]string{"test arm callback url", "second test arm callback url"}, actualConfig.ArmCallbackUrls) a.ElementsMatch([]string{"test disarm callback url", "second test disarm callback url"}, actualConfig.DisarmCallbackUrls) a.ElementsMatch([]string{"test alarm callback url", "second test alarm callback url"}, actualConfig.AlarmCallbackUrls) + a.Equal("test api key", actualConfig.TelegramApiKey) a.Equal(actualConfig.Matterbridge[0].URI, "test_uri_1") a.Equal(actualConfig.Matterbridge[0].Token, "test_token_1") diff --git a/main.go b/main.go index 8c9c8db..bd32655 100644 --- a/main.go +++ b/main.go @@ -61,7 +61,7 @@ func main() { s := makeSatel(config.SatelAddr, config.PoolInterval.GetDuration()) logger.Printf("Connected to Satel: %s", config.SatelAddr) - bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_APITOKEN")) + bot, err := tgbotapi.NewBotAPI(config.TelegramApiKey) if err != nil { panic(err) }