// Entry point of server, initializes BotAPI, gets updates channel and listens for updates
Entry point of server, initializes BotAPI, gets updates channel and listens for updates
// Entry point of server initializes BotAPI gets updates channel and listens for updates
func main() {
	if len(os.Args) != 6 {
		log.Panic("This service requires 4 args: 1-botToken, 2-logFile, 3-redisHost, 4-redisPassword 5-ignoreRedisPassword")
	}
	botToken = os.Args[1]
	logFile = os.Args[2]
	redisHost = os.Args[3]
	redisPassword = os.Args[4]
	ignoreRedisPassword = os.Args[5]
	log.Println("Args %s %s %s %s %s", botToken, logFile, redisHost, len(redisPassword), ignoreRedisPassword)
	f, err := os.OpenFile(logFile, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
	if err != nil {
	    log.Panic("Opening log file failed, err: ", err.Error())
	}
	defer f.Close()
	log.SetOutput(f)
	initRedisClient()
	bot, err := tgbotapi.NewBotAPI(botToken)
	if err != nil {
		log.Panic("AppFinder bot creation failed, err: " + err.Error())
	}
	log.Println("Bot Authorized on account %s", bot.Self.UserName)
	u := tgbotapi.NewUpdate(0)
	u.Timeout = 40
	updates, err := bot.GetUpdatesChan(u)
	if err != nil {
		log.Panic("Getting updates channel failed, err: " + err.Error())
	}
	for update := range updates {
		if update.Message == nil || update.Message.Text == "" {
			continue
		}
		log.Printf("text message received from [%s]: %s", update.Message.From.UserName, update.Message.Text)
		dispatchUpdate(bot, update)
	}
}
func main ( ) { if len ( os . Args ) != 6 { log . Panic ( " " ) } botToken = os . Args [ 1 ] logFile = os . Args [ 2 ] redisHost = os . Args [ 3 ] redisPassword = os . Args [ 4 ] ignoreRedisPassword = os . Args [ 5 ] log . Println ( " " , botToken , logFile , redisHost , len ( redisPassword ) , ignoreRedisPassword ) f , err := os . OpenFile ( logFile , os . O_RDWR | os . O_CREATE | os . O_APPEND , 0666 ) if err != nil { log . Panic ( " " , err . Error ( ) ) } defer f . Close ( ) log . SetOutput ( f ) initRedisClient ( ) bot , err := tgbotapi . NewBotAPI ( botToken ) if err != nil { log . Panic ( " " + err . Error ( ) ) } log . Println ( " " , bot . Self . UserName ) u := tgbotapi . NewUpdate ( 0 ) u . Timeout = 40 updates , err := bot . GetUpdatesChan ( u ) if err != nil { log . Panic ( " " + err . Error ( ) ) } for update := range updates { if update . Message == nil || update . Message . Text == " " { continue } log . Printf ( " " , update . Message . From . UserName , update . Message . Text ) dispatchUpdate ( bot , update ) } }
Entry point of server, initializes BotAPI, gets updates channel and listens for updates
Entry point of server initializes BotAPI gets updates channel and listens for updates