Adding start of bot, working!
This commit is contained in:
		
							
								
								
									
										3
									
								
								config.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								config.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| { | ||||
| "Token": "your token here" | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								go_telegram
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								go_telegram
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										51
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								main.go
									
									
									
									
									
										Normal 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() | ||||
| } | ||||
		Reference in New Issue
	
	Block a user