7 "github.com/go-telegram-bot-api/telegram-bot-api"
8 "github.com/jessevdk/go-flags"
12 Token string `short:"t" long:"token" description:"Telegram API Token" required:"true"`
15 func recv_task(bot *tgbotapi.BotAPI, sendChannel chan tgbotapi.Chattable, ctx context.Context) {
16 u := tgbotapi.NewUpdate(0)
19 updates, _ := bot.GetUpdatesChan(u)
23 case update := <-updates:
24 log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
26 msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
27 msg.ReplyToMessageID = update.Message.MessageID
35 func send_task(bot *tgbotapi.BotAPI, sendChannel chan tgbotapi.Chattable, ctx context.Context) {
38 case msg := <-sendChannel:
47 _, err := flags.Parse(&config)
52 bot, err := tgbotapi.NewBotAPI(config.Token)
59 log.Printf("Authorized on account %s", bot.Self.UserName)
61 ctx, cancel := context.WithCancel(context.Background())
62 sendChannel := make(chan tgbotapi.Chattable)
63 go send_task(bot, sendChannel, ctx)
64 recv_task(bot, sendChannel, ctx)