Guest User

Telegram bot messenger

a guest
Feb 25th, 2021
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.00 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "bufio"
  5.     "fmt"
  6.     "io"
  7.     "log"
  8.     "os"
  9.  
  10.     tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
  11. )
  12.  
  13. func main() {
  14.     input := getStdin()
  15.     bot := setupTg()
  16.  
  17.     //log.Printf("Authorized on account %s", bot.Self.UserName)
  18.  
  19.     var myChatID int64
  20.     myChatID = chat-id-here
  21.     msg := tgbotapi.NewMessage(myChatID, input)
  22.     bot.Send(msg)
  23. }
  24.  
  25. func setupTg() *tgbotapi.BotAPI {
  26.     bot, err := tgbotapi.NewBotAPI(bot:key-here)
  27.     if err != nil {
  28.         log.Panic(err)
  29.     }
  30.     bot.Debug = false
  31.     return bot
  32. }
  33.  
  34. func getStdin() string {
  35.     info, err := os.Stdin.Stat()
  36.     if err != nil {
  37.         panic(err)
  38.     }
  39.  
  40.     if info.Mode()&os.ModeNamedPipe == 0 {
  41.         fmt.Println("The command is intended to work with pipes.")
  42.         fmt.Println("Usage: echo 'text' | telegramBot")
  43.         os.Exit(0)
  44.     }
  45.  
  46.     reader := bufio.NewReader(os.Stdin)
  47.     var output []rune
  48.  
  49.     for {
  50.         input, _, err := reader.ReadRune()
  51.         if err != nil && err == io.EOF {
  52.             break
  53.         }
  54.         output = append(output, input)
  55.     }
  56.  
  57.     return string(output)
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment