Cómo empezar un bot de Telegram con diferentes tokens en un servidor en Golang.
Hay un fragmento de código funcional que lanza un bot para recibir webhooks.
paquete principal
importar (
"registro"
"net/http"
)
función principal() {
bot, err := tgbotapi.NewBotAPI("MiAwesomeBotToken")
if err != nulo {
registro.Fatal(err)
}
bot.Debug = verdadero
registro.Printf("Autorizado en la cuenta %s", bot.Self.UserName)
_, err = bot.SetWebhook(tgbotapi.NewWebhookWithCert("https://example.com:8443/"+bot.Token, "cert.pem"))
si err! = nulo {
registro.Fatal(err)
}
info, err := bot.GetWebhookInfo()
si err! = nulo {
registro.Fatal(err)
}
si info.LastErrorDate! = 0 {
registro.Printf("Fallo de callback de Telegram: %s", info.LastErrorMessage)
}
actualizaciones: = bot.ListenForWebhook("/" + bot.Token)
go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nulo)
for update: =range actualizaciones {
registro.Printf("%+v\n", actualización)
}
}
Biblioteca para golang – tgbotapi
Cuando intento lanzar otro bot en el mismo servidor, con el mismo código, pero con un token diferente, por supuesto, sucede lo siguiente, el bot se autoriza correctamente pero no responde a los comandos, o simplemente no recibe un webhook, quién sabe la razón?
Apago 1 bot, luego el segundo se inicia sin problemas, al mismo tiempo no quieren …
davy.ai
paquete principal
import (
“log”
“net/http”
)
func main() {
bot1, err := tgbotapi.NewBotAPI(“MiMarcaBotToken1”)
if err != nil {
log.Fatal(err)
}
}