zergon321

telegram bot

Jan 12th, 2022
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.81 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "log"
  6.  
  7.     tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
  8. )
  9.  
  10. func main() {
  11.     bot, err := tgbotapi.NewBotAPI("MY_SECRET_TOKEN")
  12.     handleError("Couldn't access the bot API", err)
  13.     bot.Debug = true
  14.  
  15.     fmt.Println("Authorized on account", bot.Self.UserName)
  16.  
  17.     upd := tgbotapi.NewUpdate(0)
  18.     upd.Timeout = 60
  19.     updates, err := bot.GetUpdatesChan(upd)
  20.     handleError("Couldn't get an updates channel for the bot", err)
  21.  
  22.     for update := range updates {
  23.         if update.Message != nil {
  24.             msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Hello!")
  25.  
  26.             bot.Send(msg)
  27.  
  28.             msg = tgbotapi.NewMessage(update.Message.Chat.ID, "Fuck you!")
  29.  
  30.             bot.Send(msg)
  31.         }
  32.     }
  33. }
  34.  
  35. func handleError(message string, err error) {
  36.     if err != nil {
  37.         log.Fatalf("%s: %s", message, err)
  38.     }
  39. }
Add Comment
Please, Sign In to add comment