Adding start of bot, working!

This commit is contained in:
Matt Burchett 2018-07-16 13:44:27 -05:00
parent 585953760b
commit 8292eda4d4
3 changed files with 54 additions and 0 deletions

3
config.json Normal file
View File

@ -0,0 +1,3 @@
{
"Token": "your token here"
}

BIN
go_telegram Executable file

Binary file not shown.

51
main.go Normal file
View File

@ -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()
}