Skip to content

Instantly share code, notes, and snippets.

@igponce
Created February 24, 2021 22:30
Show Gist options
  • Save igponce/b3602eee457c846f43202bb8cda2fcc9 to your computer and use it in GitHub Desktop.
Save igponce/b3602eee457c846f43202bb8cda2fcc9 to your computer and use it in GitHub Desktop.
Telegram echo bot
package main
import (
"fmt"
tg_botapi "github.com/go-telegram-bot-api/telegram-bot-api"
)
func main() {
secret := "Pregunta al @botfather para esto"
fmt.Println("Using ApiKey: " + secret)
bot, err := tg_botapi.NewBotAPI(secret)
if err != nil {
fmt.Print("Err: " + err.Error())
}
fmt.Println("Bot Name: " + bot.Self.FirstName)
updates, err := bot.GetUpdatesChan(tg_botapi.NewUpdate(0))
for uu := range updates {
if uu.Message != nil {
fmt.Println("Update: " + uu.Message.Text)
// Devuelve el mensaje (echo server)
sendmsg := tg_botapi.NewMessage(uu.Message.Chat.ID, "> "+uu.Message.Text)
sendmsg.ParseMode = "markdown"
bot.Send(sendmsg)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment