Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "bufio"
- "fmt"
- "io"
- "log"
- "os"
- tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
- )
- func main() {
- input := getStdin()
- bot := setupTg()
- //log.Printf("Authorized on account %s", bot.Self.UserName)
- var myChatID int64
- myChatID = chat-id-here
- msg := tgbotapi.NewMessage(myChatID, input)
- bot.Send(msg)
- }
- func setupTg() *tgbotapi.BotAPI {
- bot, err := tgbotapi.NewBotAPI(bot:key-here)
- if err != nil {
- log.Panic(err)
- }
- bot.Debug = false
- return bot
- }
- func getStdin() string {
- info, err := os.Stdin.Stat()
- if err != nil {
- panic(err)
- }
- if info.Mode()&os.ModeNamedPipe == 0 {
- fmt.Println("The command is intended to work with pipes.")
- fmt.Println("Usage: echo 'text' | telegramBot")
- os.Exit(0)
- }
- reader := bufio.NewReader(os.Stdin)
- var output []rune
- for {
- input, _, err := reader.ReadRune()
- if err != nil && err == io.EOF {
- break
- }
- output = append(output, input)
- }
- return string(output)
- }
Advertisement
Add Comment
Please, Sign In to add comment