diff --git a/config.json b/config.json new file mode 100644 index 0000000..d2e8c79 --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ +"Token": "your token here" +} diff --git a/go_telegram b/go_telegram new file mode 100755 index 0000000..266d3dd Binary files /dev/null and b/go_telegram differ diff --git a/main.go b/main.go new file mode 100644 index 0000000..239a4cb --- /dev/null +++ b/main.go @@ -0,0 +1,51 @@ +package main + +import ( + "encoding/json" + "flag" + "log" + "os" + "time" + + tb "gopkg.in/tucnak/telebot.v2" +) + +// Configuration - Specify what to look for in Config file +type Configuration struct { + Token string +} + +// ReadConfig from file +func main() { + c := flag.String("c", "./config.json", "Specify the configuration file.") + flag.Parse() + file, err := os.Open(*c) + if err != nil { + log.Fatal("can't open config file: ", err) + } + defer file.Close() + decoder := json.NewDecoder(file) + Config := Configuration{} + err = decoder.Decode(&Config) + if err != nil { + log.Fatal("can't decode config JSON: ", err) + } + + b, err := tb.NewBot(tb.Settings{ + Token: Config.Token, + Poller: &tb.LongPoller{Timeout: 10 * time.Second}, + }) + + if err != nil { + log.Fatal(err) + return + } + + b.Handle("/ping", func(m *tb.Message) { + b.Send(m.Sender, "pong") + }) + + log.Print("Starting bot...") + + b.Start() +}