Created
February 24, 2021 22:30
-
-
Save igponce/b3602eee457c846f43202bb8cda2fcc9 to your computer and use it in GitHub Desktop.
Telegram echo bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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