1
0
Fork 0

Get Telegram Bot API from config instead of env

This commit is contained in:
Michał Rudowicz 2025-01-03 20:33:36 +01:00
parent 0e59be7421
commit f6ff93c783
4 changed files with 7 additions and 3 deletions

View File

@ -10,7 +10,7 @@ In other words - treat it as a toy, not as a tool that will save your life or va
## Running ## Running
``` ```
$ TELEGRAM_APITOKEN=YOUR_API_TOKEN ./alarm-bot $ ./alarm-bot
``` ```
Remember that `hswro-alarm-bot.yml` should be present in the current directory. Remember that `hswro-alarm-bot.yml` should be present in the current directory.
@ -32,6 +32,7 @@ allowed-indexes:
- 5678 - 5678
- 1337 - 1337
pool-interval: 5m pool-interval: 5m
telegram-api-key: "telegram api key"
arm-callback-urls: arm-callback-urls:
- "http://192.168.1.10/hello" - "http://192.168.1.10/hello"
- "http://example.com/api" - "http://example.com/api"
@ -51,6 +52,7 @@ matterbridge:
- `pool-interval` sets how often will the Satel device be asked for changes - `pool-interval` sets how often will the Satel device be asked for changes
- `satel-addr` sets the IP address of the Satel device - `satel-addr` sets the IP address of the Satel device
- `tg-chat-ids` sets which telegram groups will receive notifications about alarm state changes - `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 ### Matterbridge integration
@ -132,7 +134,6 @@ After=network.target
[Service] [Service]
Type=simple Type=simple
ExecStart=/path/to/alarm_bot ExecStart=/path/to/alarm_bot
Environment=TELEGRAM_APITOKEN=YOUR_API_TOKEN
DynamicUser=True DynamicUser=True
RuntimeDirectory=hswro-alarm-bot RuntimeDirectory=hswro-alarm-bot
StateDirectory=hswro-alarm-bot StateDirectory=hswro-alarm-bot

View File

@ -44,6 +44,7 @@ type AppConfig struct {
AlarmCallbackUrls []string `yaml:"alarm-callback-urls"` AlarmCallbackUrls []string `yaml:"alarm-callback-urls"`
WriteMemoryProfile bool `yaml:"write-memory-profile"` WriteMemoryProfile bool `yaml:"write-memory-profile"`
Matterbridge []MatterbridgeConfig `yaml:"matterbridge"` Matterbridge []MatterbridgeConfig `yaml:"matterbridge"`
TelegramApiKey string `yaml:"telegram-api-key"`
} }
func (m *SatelChangeType) UnmarshalYAML(unmarshal func(interface{}) error) error { func (m *SatelChangeType) UnmarshalYAML(unmarshal func(interface{}) error) error {

View File

@ -32,6 +32,7 @@ disarm-callback-urls:
alarm-callback-urls: alarm-callback-urls:
- "test alarm callback url" - "test alarm callback url"
- "second test alarm callback url" - "second test alarm callback url"
telegram-api-key: "test api key"
matterbridge: matterbridge:
- uri: test_uri_1 - uri: test_uri_1
token: test_token_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 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 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.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].URI, "test_uri_1")
a.Equal(actualConfig.Matterbridge[0].Token, "test_token_1") a.Equal(actualConfig.Matterbridge[0].Token, "test_token_1")

View File

@ -61,7 +61,7 @@ func main() {
s := makeSatel(config.SatelAddr, config.PoolInterval.GetDuration()) s := makeSatel(config.SatelAddr, config.PoolInterval.GetDuration())
logger.Printf("Connected to Satel: %s", config.SatelAddr) 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 { if err != nil {
panic(err) panic(err)
} }