This commit is contained in:
Lizandro Guarnizo
2026-05-16 21:27:30 -05:00
parent fcc3ff7ca7
commit 4fa506c7d6
11 changed files with 586 additions and 13 deletions
+22
View File
@@ -57,6 +57,28 @@ func (ts *TelegramService) SendMessage(chatID interface{}, message string) error
return nil
}
// GetBotUsername obtiene el username (@nombre) del bot a partir de su token.
func GetBotUsername(botToken string) string {
if botToken == "" {
return ""
}
resp, err := http.Get(fmt.Sprintf("https://api.telegram.org/bot%s/getMe", botToken))
if err != nil {
return ""
}
defer resp.Body.Close()
var result struct {
OK bool `json:"ok"`
Result struct {
Username string `json:"username"`
} `json:"result"`
}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return ""
}
return result.Result.Username
}
// SendMessageWithToken envía un mensaje usando un bot token explícito (útil para notificar a usuarios con su propio chat_id).
func (ts *TelegramService) SendMessageWithToken(chatID interface{}, message, botToken string) error {
svc := &TelegramService{BotToken: botToken}