-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (39 loc) · 1.37 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"flag"
"io/ioutil"
"os"
"github.com/bb4L/rpi-radio-alarm-go-library/api"
"github.com/bb4L/rpi-radio-alarm-go-library/logging"
"github.com/bb4L/rpi-radio-alarm-go-library/storage"
"github.com/bb4L/rpi-radio-alarm-telegrambot-go/bot"
"github.com/bb4L/rpi-radio-alarm-telegrambot-go/types"
"gopkg.in/yaml.v2"
)
var logger = logging.GetLogger(os.Stdout, "main")
func main() {
logger.Println("start telegram bot")
var configFilePath string
flag.StringVar(&configFilePath, "c", "./rpi_telegrambot_helper_config.yaml", "Specify config file for the DataHelper used by the bot")
logger.Println("reading HelperConfig from: " + configFilePath)
fileData, err := ioutil.ReadFile(configFilePath)
if err != nil {
panic(err)
}
var helperConfig types.HelperConfig
source := []byte(fileData)
err = yaml.Unmarshal(source, &helperConfig)
if err != nil {
logger.Fatalf("error: %v", err)
}
if helperConfig.HelperType == "storage" {
bot.StartTelegramBot(&storage.Helper{})
} else if helperConfig.HelperType == "api" {
if helperConfig.AlarmURL == "" {
logger.Fatalf("no AlarmUrl set")
}
bot.StartTelegramBot(&api.Helper{AlarmURL: helperConfig.AlarmURL, ExtraHeader: helperConfig.ExtraHeader, ExtreaHeaderValue: helperConfig.ExtraHeaderValue})
} else {
logger.Fatalf("invalid config for Helpertype, was %s expected to be \"api\" or \"storage\" ", err)
}
}