up
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user