chore: build

This commit is contained in:
2026-06-12 10:47:30 +02:00
parent 1d96d558b9
commit cc278ecef5
3 changed files with 63 additions and 2 deletions
+15 -2
View File
@@ -96,8 +96,21 @@ func handleLinkAccount(c *gin.Context, token string, chatID int64) {
if services.LBTelegram != nil && services.LBTelegram.IsConfigured() {
if err := services.LBTelegram.EnrollUser(chatID, username, role); err != nil {
log.Printf("⚠️ [LB] enrollment échoué pour %s: %v", username, err)
// fallback: confirmation directe via le bot principal
if services.TelegramBot != nil {
}
// Envoyer un message avec boutons vers les bots de notifications lbtelegram
if services.TelegramBot != nil && services.LBTelegram.Bot1Username != "" {
buttons := [][2]string{
{"🔔 Activer les notifications", "https://t.me/" + services.LBTelegram.Bot1Username},
}
if services.LBTelegram.Bot2Username != "" {
buttons = append(buttons, [2]string{"🔔 Bot secondaire", "https://t.me/" + services.LBTelegram.Bot2Username})
}
if err := services.TelegramBot.SendMessageWithButtons(chatID,
"✅ <b>Compte lié avec succès !</b>\n\nPour recevoir vos notifications de livraison, appuyez sur le bouton ci-dessous pour démarrer notre bot de notifications :",
buttons,
); err != nil {
log.Printf("⚠️ [TELEGRAM] Envoi message boutons échoué pour %s: %v", username, err)
services.TelegramBot.SendMessage(chatID,
"✅ <b>Compte lié avec succès !</b>\n\nVous recevrez désormais vos notifications ici.")
}
+2
View File
@@ -16,6 +16,7 @@ var LBTelegram *LBTelegramService
type LBTelegramService struct {
gatewayURL string
Bot1Username string
Bot2Username string
client *http.Client
}
@@ -27,6 +28,7 @@ func NewLBTelegramService() *LBTelegramService {
svc := &LBTelegramService{
gatewayURL: url,
Bot1Username: os.Getenv("LBTELEGRAM_BOT1_USERNAME"),
Bot2Username: os.Getenv("LBTELEGRAM_BOT2_USERNAME"),
client: &http.Client{Timeout: 10 * time.Second},
}
LBTelegram = svc
+46
View File
@@ -95,6 +95,52 @@ func (t *TelegramService) SendMessage(chatID int64, text string) error {
return nil
}
// SendMessageWithButtons envoie un message HTML avec des boutons inline (URL buttons).
// buttons est une liste de paires [texte, url].
func (t *TelegramService) SendMessageWithButtons(chatID int64, text string, buttons [][2]string) error {
if !t.IsConfigured() {
return fmt.Errorf("telegram non configuré")
}
row := make([]map[string]string, 0, len(buttons))
for _, b := range buttons {
row = append(row, map[string]string{"text": b[0], "url": b[1]})
}
payload := map[string]interface{}{
"chat_id": chatID,
"text": text,
"parse_mode": "HTML",
"reply_markup": map[string]interface{}{
"inline_keyboard": [][]map[string]string{row},
},
}
body, err := json.Marshal(payload)
if err != nil {
return fmt.Errorf("marshal: %w", err)
}
url := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", t.botToken)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(body))
if err != nil {
return fmt.Errorf("création requête: %w", err)
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("envoi: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("telegram API status %d", resp.StatusCode)
}
return nil
}
// SetWebhook enregistre l'URL webhook auprès de Telegram
func (t *TelegramService) SetWebhook(webhookURL string) error {
if !t.IsConfigured() {