Get Telegram Bot API from config instead of env
This commit is contained in:
parent
0e59be7421
commit
f6ff93c783
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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")
|
||||
|
|
2
main.go
2
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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue