fix: seguridad del webhook de soporte, pagos en contabilidad y Telegram para tareas
- soporte: el webhook de correo entrante era público sin ninguna validación; ahora exige una API key (query ?key= o header) comparada en tiempo constante. Además evita tickets duplicados por reintentos del proveedor (dedup por Message-Id) y enhebra respuestas del mismo remitente en vez de abrir un ticket nuevo por cada correo. - contabilidad: marcar una cuenta por cobrar/pagar como pagada ahora crea y vincula la Transaccion correspondiente (antes el dashboard de ingresos/ egresos nunca reflejaba esos pagos). Se corrige además que actualizar una cuenta por cobrar borraba su transaccion_id en cada PUT. - tareas: se activa por defecto el canal Telegram para tarea_asignada (estaba apagado desde el seed original) y se agrega un flujo real de vinculación de Telegram para el staff interno (código temporal + verificación), igual al que ya existía para los usuarios del portal — sin esto el chat_id de cada usuario había que pegarlo a mano y la notificación nunca llegaba. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
1127d944c7
commit
d2bf699b60
@@ -494,6 +494,31 @@ func DeleteCuentaCobro(c *fiber.Ctx) error {
|
||||
return c.JSON(fiber.Map{"ok": true})
|
||||
}
|
||||
|
||||
// MarcarCuentaCobroPagada registra el pago y crea la transacción de ingreso vinculada.
|
||||
// POST /contabilidad/cuentas-cobro/:id/pagar
|
||||
func MarcarCuentaCobroPagada(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 32)
|
||||
if err != nil {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "ID inválido"})
|
||||
}
|
||||
var req struct {
|
||||
FechaPago string `json:"fecha_pago"`
|
||||
}
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return c.Status(400).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
fecha := time.Now()
|
||||
if req.FechaPago != "" {
|
||||
if parsed, err := time.Parse("2006-01-02", req.FechaPago); err == nil {
|
||||
fecha = parsed
|
||||
}
|
||||
}
|
||||
if err := models.MarcarCuentaCobroPagada(uint(id), fecha); err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"ok": true})
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// ─── CRUD: Cuentas por Pagar ────────────────────────────────────────────────
|
||||
// =============================================================================
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"crypto/subtle"
|
||||
"log"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -13,9 +15,43 @@ import (
|
||||
|
||||
// ─── Webhook de correo entrante ───────────────────────────────────────────────
|
||||
// Recibe notificaciones de SendGrid, Mailgun, etc.
|
||||
// POST /webhooks/soporte/:provider
|
||||
// POST /webhooks/soporte/:provider?key=<ApiKey de la config activa>
|
||||
// provider: sendgrid, mailgun, generic
|
||||
|
||||
type soporteEmailIn struct {
|
||||
From string `json:"from" form:"from"`
|
||||
Subject string `json:"subject" form:"subject"`
|
||||
Text string `json:"text" form:"text"`
|
||||
Html string `json:"html" form:"html"`
|
||||
Sender string `json:"sender" form:"sender"`
|
||||
FromName string `json:"from_name" form:"from_name"`
|
||||
MessageID string `json:"message_id" form:"message_id"`
|
||||
}
|
||||
|
||||
var ticketRefRe = regexp.MustCompile(`(?i)\[Ticket #(\d+)\]`)
|
||||
var messageIDHeaderRe = regexp.MustCompile(`(?im)^Message-ID:\s*(<[^>\r\n]+>)`)
|
||||
|
||||
// validarWebhookKey compara la key recibida (query ?key= o header X-Webhook-Key /
|
||||
// X-Api-Key) contra el ApiKey guardado en la config activa, en tiempo constante.
|
||||
// Si la config no tiene ApiKey configurado, se rechaza toda petición: hay que
|
||||
// definirlo en /app/soporte-webhook y usar esa misma URL con ?key=... en el proveedor.
|
||||
func validarWebhookKey(c *fiber.Ctx, cfg *models.SoporteWebhookConfig) bool {
|
||||
if cfg.ApiKey == "" {
|
||||
return false
|
||||
}
|
||||
key := c.Query("key")
|
||||
if key == "" {
|
||||
key = c.Get("X-Webhook-Key")
|
||||
}
|
||||
if key == "" {
|
||||
key = c.Get("X-Api-Key")
|
||||
}
|
||||
if key == "" {
|
||||
return false
|
||||
}
|
||||
return subtle.ConstantTimeCompare([]byte(key), []byte(cfg.ApiKey)) == 1
|
||||
}
|
||||
|
||||
func SoporteWebhook(c *fiber.Ctx) error {
|
||||
provider := c.Params("provider", "generic")
|
||||
|
||||
@@ -25,78 +61,62 @@ func SoporteWebhook(c *fiber.Ctx) error {
|
||||
return c.Status(200).JSON(fiber.Map{"ok": false, "error": "sin config"})
|
||||
}
|
||||
|
||||
var emails []struct {
|
||||
From string `json:"from" form:"from"`
|
||||
Subject string `json:"subject" form:"subject"`
|
||||
Text string `json:"text" form:"text"`
|
||||
Html string `json:"html" form:"html"`
|
||||
Sender string `json:"sender" form:"sender"`
|
||||
FromName string `json:"from_name" form:"from_name"`
|
||||
if !validarWebhookKey(c, cfg) {
|
||||
log.Printf("[SoporteWebhook] Petición rechazada (key inválida o ausente) desde IP %s", c.IP())
|
||||
return c.Status(401).JSON(fiber.Map{"ok": false, "error": "no autorizado"})
|
||||
}
|
||||
|
||||
var emails []soporteEmailIn
|
||||
|
||||
switch provider {
|
||||
case "sendgrid":
|
||||
var sg struct {
|
||||
From string `json:"from"`
|
||||
Subject string `json:"subject"`
|
||||
Text string `json:"text"`
|
||||
Html string `json:"html"`
|
||||
Sender string `json:"sender"`
|
||||
FromName string `json:"from_name"`
|
||||
From string `json:"from" form:"from"`
|
||||
Subject string `json:"subject" form:"subject"`
|
||||
Text string `json:"text" form:"text"`
|
||||
Html string `json:"html" form:"html"`
|
||||
Sender string `json:"sender" form:"sender"`
|
||||
FromName string `json:"from_name" form:"from_name"`
|
||||
Headers string `json:"headers" form:"headers"`
|
||||
}
|
||||
if err := c.BodyParser(&sg); err != nil {
|
||||
return c.Status(200).JSON(fiber.Map{"ok": false, "error": "body inválido"})
|
||||
}
|
||||
emails = append(emails, struct {
|
||||
From string `json:"from" form:"from"`
|
||||
Subject string `json:"subject" form:"subject"`
|
||||
Text string `json:"text" form:"text"`
|
||||
Html string `json:"html" form:"html"`
|
||||
Sender string `json:"sender" form:"sender"`
|
||||
FromName string `json:"from_name" form:"from_name"`
|
||||
}{From: sg.From, Subject: sg.Subject, Text: sg.Text, Html: sg.Html, Sender: sg.Sender, FromName: sg.FromName})
|
||||
emails = append(emails, soporteEmailIn{
|
||||
From: sg.From, Subject: sg.Subject, Text: sg.Text, Html: sg.Html,
|
||||
Sender: sg.Sender, FromName: sg.FromName, MessageID: extractMessageIDFromHeaders(sg.Headers),
|
||||
})
|
||||
case "mailgun":
|
||||
var mg struct {
|
||||
From string `form:"from"`
|
||||
Subject string `form:"subject"`
|
||||
Text string `form:"body-plain"`
|
||||
Html string `form:"body-html"`
|
||||
Sender string `form:"sender"`
|
||||
FromName string `form:"from_name"`
|
||||
From string `form:"from"`
|
||||
Subject string `form:"subject"`
|
||||
Text string `form:"body-plain"`
|
||||
Html string `form:"body-html"`
|
||||
Sender string `form:"sender"`
|
||||
FromName string `form:"from_name"`
|
||||
MessageID string `form:"Message-Id"`
|
||||
}
|
||||
if err := c.BodyParser(&mg); err != nil {
|
||||
return c.Status(200).JSON(fiber.Map{"ok": false})
|
||||
}
|
||||
emails = append(emails, struct {
|
||||
From string `json:"from" form:"from"`
|
||||
Subject string `json:"subject" form:"subject"`
|
||||
Text string `json:"text" form:"text"`
|
||||
Html string `json:"html" form:"html"`
|
||||
Sender string `json:"sender" form:"sender"`
|
||||
FromName string `json:"from_name" form:"from_name"`
|
||||
}{
|
||||
emails = append(emails, soporteEmailIn{
|
||||
From: mg.From, Subject: mg.Subject, Text: mg.Text,
|
||||
Html: mg.Html, Sender: mg.Sender, FromName: mg.FromName,
|
||||
Html: mg.Html, Sender: mg.Sender, FromName: mg.FromName, MessageID: mg.MessageID,
|
||||
})
|
||||
default:
|
||||
var generic struct {
|
||||
From string `json:"from"`
|
||||
Subject string `json:"subject"`
|
||||
Text string `json:"text"`
|
||||
Html string `json:"html"`
|
||||
From string `json:"from"`
|
||||
Subject string `json:"subject"`
|
||||
Text string `json:"text"`
|
||||
Html string `json:"html"`
|
||||
MessageID string `json:"message_id"`
|
||||
}
|
||||
if err := c.BodyParser(&generic); err != nil {
|
||||
return c.Status(200).JSON(fiber.Map{"ok": false})
|
||||
}
|
||||
emails = append(emails, struct {
|
||||
From string `json:"from" form:"from"`
|
||||
Subject string `json:"subject" form:"subject"`
|
||||
Text string `json:"text" form:"text"`
|
||||
Html string `json:"html" form:"html"`
|
||||
Sender string `json:"sender" form:"sender"`
|
||||
FromName string `json:"from_name" form:"from_name"`
|
||||
}{
|
||||
emails = append(emails, soporteEmailIn{
|
||||
From: generic.From, Subject: generic.Subject, Text: generic.Text, Html: generic.Html,
|
||||
MessageID: generic.MessageID,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -104,6 +124,13 @@ func SoporteWebhook(c *fiber.Ctx) error {
|
||||
if e.From == "" || e.Subject == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Deduplicación: el proveedor puede reintentar la entrega del mismo correo.
|
||||
if models.EmailMessageIDYaProcesado(e.MessageID) {
|
||||
log.Printf("[SoporteWebhook] Correo duplicado ignorado (message_id=%s)", e.MessageID)
|
||||
continue
|
||||
}
|
||||
|
||||
fromEmail := extractEmail(e.From)
|
||||
fromName := e.FromName
|
||||
if fromName == "" {
|
||||
@@ -122,6 +149,29 @@ func SoporteWebhook(c *fiber.Ctx) error {
|
||||
contenido = contenido[:5000]
|
||||
}
|
||||
|
||||
// Enhebrado: si el asunto trae "[Ticket #N]" (lo agregamos nosotros en el
|
||||
// auto-ack) y ese ticket es del mismo remitente, es una respuesta — se
|
||||
// agrega como mensaje en vez de abrir un ticket nuevo. Si no hay token
|
||||
// pero el remitente tiene un ticket abierto reciente, también se enhebra.
|
||||
if hilo := buscarTicketDeHilo(fromEmail, e.Subject); hilo != nil {
|
||||
msg := &models.TicketMensaje{
|
||||
TicketID: hilo.ID,
|
||||
Contenido: contenido,
|
||||
EsAdmin: false,
|
||||
AutorNombre: fromName,
|
||||
MessageID: e.MessageID,
|
||||
}
|
||||
if err := models.CreateTicketMensaje(msg); err != nil {
|
||||
log.Printf("[SoporteWebhook] Error agregando mensaje al ticket #%d: %v", hilo.ID, err)
|
||||
continue
|
||||
}
|
||||
if hilo.Estado == "resuelto" || hilo.Estado == "cerrado" {
|
||||
_ = models.UpdateTicketEstado(hilo.ID, "abierto")
|
||||
}
|
||||
log.Printf("[SoporteWebhook] Respuesta agregada al ticket #%d (%s)", hilo.ID, fromEmail)
|
||||
continue
|
||||
}
|
||||
|
||||
ticket := &models.ProyectoTicket{
|
||||
AutorNombre: fromName,
|
||||
EmailFrom: fromEmail,
|
||||
@@ -129,6 +179,7 @@ func SoporteWebhook(c *fiber.Ctx) error {
|
||||
Descripcion: contenido,
|
||||
Estado: "abierto",
|
||||
Origen: "email",
|
||||
MessageID: e.MessageID,
|
||||
}
|
||||
if cfg.AsignarA != nil {
|
||||
ticket.AsignadoA = cfg.AsignarA
|
||||
@@ -142,7 +193,7 @@ func SoporteWebhook(c *fiber.Ctx) error {
|
||||
// Notificar admin
|
||||
services.SendSoporteNotifAdmin(ticket)
|
||||
|
||||
// Auto-responder
|
||||
// Auto-responder (el asunto incluye [Ticket #N] para poder enhebrar la respuesta)
|
||||
if cfg.ResponderAuto {
|
||||
services.SendSoporteAutoRespuesta(ticket)
|
||||
}
|
||||
@@ -151,12 +202,48 @@ func SoporteWebhook(c *fiber.Ctx) error {
|
||||
return c.Status(200).JSON(fiber.Map{"ok": true})
|
||||
}
|
||||
|
||||
// buscarTicketDeHilo intenta encontrar el ticket al que pertenece una respuesta:
|
||||
// primero por el token "[Ticket #N]" en el asunto (verificando que sea del mismo
|
||||
// remitente, para que nadie pueda inyectar mensajes en el ticket de otro
|
||||
// adivinando el número), y si no hay token, por el último ticket abierto de ese
|
||||
// remitente cuando el asunto tiene pinta de respuesta (Re:/RE:/Fwd:).
|
||||
func buscarTicketDeHilo(fromEmail, subject string) *models.ProyectoTicket {
|
||||
if m := ticketRefRe.FindStringSubmatch(subject); m != nil {
|
||||
id, _ := strconv.ParseUint(m[1], 10, 32)
|
||||
if id > 0 {
|
||||
t, err := models.GetTicketByID(uint(id))
|
||||
if err == nil && strings.EqualFold(t.EmailFrom, fromEmail) {
|
||||
return t
|
||||
}
|
||||
}
|
||||
}
|
||||
lower := strings.ToLower(strings.TrimSpace(subject))
|
||||
if strings.HasPrefix(lower, "re:") || strings.HasPrefix(lower, "fwd:") || strings.HasPrefix(lower, "fw:") {
|
||||
if t, err := models.GetUltimoTicketAbiertoPorEmail(fromEmail); err == nil {
|
||||
return t
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func extractMessageIDFromHeaders(headers string) string {
|
||||
if headers == "" {
|
||||
return ""
|
||||
}
|
||||
if m := messageIDHeaderRe.FindStringSubmatch(headers); m != nil {
|
||||
return m[1]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ─── Asignar ticket a usuario ─────────────────────────────────────────────────
|
||||
// PUT /app/tickets/:ticketID/asignar
|
||||
|
||||
func AsignarTicket(c *fiber.Ctx) error {
|
||||
ticketID, _ := strconv.ParseUint(c.Params("ticketID"), 10, 32)
|
||||
type Req struct{ AsignadoID uint `json:"asignado_id"` }
|
||||
type Req struct {
|
||||
AsignadoID uint `json:"asignado_id"`
|
||||
}
|
||||
var req Req
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "body inválido"})
|
||||
@@ -209,21 +296,21 @@ func GetSoporteWebhookConfig(c *fiber.Ctx) error {
|
||||
|
||||
func SaveSoporteWebhookConfig(c *fiber.Ctx) error {
|
||||
type body struct {
|
||||
ID uint `json:"id"`
|
||||
Nombre string `json:"nombre"`
|
||||
Provider string `json:"provider"`
|
||||
ApiKey string `json:"api_key"`
|
||||
EmailDestino string `json:"email_destino"`
|
||||
ResponderAuto bool `json:"responder_auto"`
|
||||
MensajeAuto string `json:"mensaje_auto"`
|
||||
AsignarA *uint `json:"asignar_a"`
|
||||
SmtpHost string `json:"smtp_host"`
|
||||
SmtpPort int `json:"smtp_port"`
|
||||
SmtpUsername string `json:"smtp_username"`
|
||||
SmtpPassword string `json:"smtp_password"`
|
||||
ID uint `json:"id"`
|
||||
Nombre string `json:"nombre"`
|
||||
Provider string `json:"provider"`
|
||||
ApiKey string `json:"api_key"`
|
||||
EmailDestino string `json:"email_destino"`
|
||||
ResponderAuto bool `json:"responder_auto"`
|
||||
MensajeAuto string `json:"mensaje_auto"`
|
||||
AsignarA *uint `json:"asignar_a"`
|
||||
SmtpHost string `json:"smtp_host"`
|
||||
SmtpPort int `json:"smtp_port"`
|
||||
SmtpUsername string `json:"smtp_username"`
|
||||
SmtpPassword string `json:"smtp_password"`
|
||||
SmtpEncryption string `json:"smtp_encryption"`
|
||||
SmtpFromAddr string `json:"smtp_from_addr"`
|
||||
SmtpFromName string `json:"smtp_from_name"`
|
||||
SmtpFromAddr string `json:"smtp_from_addr"`
|
||||
SmtpFromName string `json:"smtp_from_name"`
|
||||
}
|
||||
var b body
|
||||
if err := c.BodyParser(&b); err != nil {
|
||||
@@ -238,21 +325,21 @@ func SaveSoporteWebhookConfig(c *fiber.Ctx) error {
|
||||
enc = "starttls"
|
||||
}
|
||||
cfg := &models.SoporteWebhookConfig{
|
||||
Nombre: b.Nombre,
|
||||
Provider: b.Provider,
|
||||
ApiKey: b.ApiKey,
|
||||
EmailDestino: b.EmailDestino,
|
||||
ResponderAuto: b.ResponderAuto,
|
||||
MensajeAuto: b.MensajeAuto,
|
||||
AsignarA: b.AsignarA,
|
||||
SmtpHost: b.SmtpHost,
|
||||
SmtpPort: port,
|
||||
SmtpUsername: b.SmtpUsername,
|
||||
SmtpPassword: b.SmtpPassword,
|
||||
Nombre: b.Nombre,
|
||||
Provider: b.Provider,
|
||||
ApiKey: b.ApiKey,
|
||||
EmailDestino: b.EmailDestino,
|
||||
ResponderAuto: b.ResponderAuto,
|
||||
MensajeAuto: b.MensajeAuto,
|
||||
AsignarA: b.AsignarA,
|
||||
SmtpHost: b.SmtpHost,
|
||||
SmtpPort: port,
|
||||
SmtpUsername: b.SmtpUsername,
|
||||
SmtpPassword: b.SmtpPassword,
|
||||
SmtpEncryption: enc,
|
||||
SmtpFromAddr: b.SmtpFromAddr,
|
||||
SmtpFromName: b.SmtpFromName,
|
||||
Activo: true,
|
||||
SmtpFromAddr: b.SmtpFromAddr,
|
||||
SmtpFromName: b.SmtpFromName,
|
||||
Activo: true,
|
||||
}
|
||||
cfg.ID = b.ID
|
||||
if err := models.SaveSoporteWebhookConfig(cfg); err != nil {
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/sujit-baniya/fiber-boilerplate/pkg/models"
|
||||
"github.com/sujit-baniya/fiber-boilerplate/pkg/services"
|
||||
)
|
||||
|
||||
// staffUserID extrae el ID del usuario interno autenticado desde c.Locals("user").
|
||||
func staffUserID(c *fiber.Ctx) (uint, bool) {
|
||||
user, ok := c.Locals("user").(map[string]interface{})
|
||||
if !ok || user == nil {
|
||||
return 0, false
|
||||
}
|
||||
switch v := user["ID"].(type) {
|
||||
case uint:
|
||||
return v, true
|
||||
case int:
|
||||
return uint(v), true
|
||||
case float64:
|
||||
return uint(v), true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// TelegramStaffStatus indica si el usuario interno autenticado ya vinculó su Telegram.
|
||||
// GET /app/profile/telegram-status
|
||||
func TelegramStaffStatus(c *fiber.Ctx) error {
|
||||
userID, ok := staffUserID(c)
|
||||
if !ok {
|
||||
return c.Status(401).JSON(fiber.Map{"error": "No autenticado"})
|
||||
}
|
||||
u, err := models.FindUserByID(userID)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"linked": u.TelegramChatID != "", "chat_id": u.TelegramChatID})
|
||||
}
|
||||
|
||||
// TelegramStaffInit genera un código de vinculación temporal para el usuario interno.
|
||||
// POST /app/profile/telegram-init
|
||||
func TelegramStaffInit(c *fiber.Ctx) error {
|
||||
userID, ok := staffUserID(c)
|
||||
if !ok {
|
||||
return c.Status(401).JSON(fiber.Map{"error": "No autenticado"})
|
||||
}
|
||||
token, err := models.GenerateTelegramStaffToken(userID)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "No se pudo generar el código"})
|
||||
}
|
||||
|
||||
configs, _ := models.GetAllTelegramConfigs()
|
||||
botToken := ""
|
||||
for _, cfg := range configs {
|
||||
if cfg.Activo && cfg.BotToken != "" {
|
||||
botToken = cfg.BotToken
|
||||
break
|
||||
}
|
||||
}
|
||||
botUsername := services.GetBotUsername(botToken)
|
||||
|
||||
return c.JSON(fiber.Map{
|
||||
"token": token.Token,
|
||||
"bot_username": botUsername,
|
||||
"bot_link": "https://t.me/" + botUsername,
|
||||
})
|
||||
}
|
||||
|
||||
// TelegramStaffValidar busca en getUpdates de los bots activos el mensaje con el
|
||||
// token del usuario y, si lo encuentra, vincula su chat_id.
|
||||
// POST /app/profile/telegram-validar
|
||||
func TelegramStaffValidar(c *fiber.Ctx) error {
|
||||
userID, ok := staffUserID(c)
|
||||
if !ok {
|
||||
return c.Status(401).JSON(fiber.Map{"error": "No autenticado"})
|
||||
}
|
||||
|
||||
tkn, err := models.GetTelegramStaffTokenByUser(userID)
|
||||
if err != nil || tkn == nil {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "No tienes un código activo. Genera uno primero."})
|
||||
}
|
||||
|
||||
configs, _ := models.GetAllTelegramConfigs()
|
||||
for _, cfg := range configs {
|
||||
if !cfg.Activo || cfg.BotToken == "" {
|
||||
continue
|
||||
}
|
||||
chatID, found := searchTokenInUpdates(cfg.BotToken, tkn.Token)
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
chatIDStr := fmt.Sprintf("%d", chatID)
|
||||
if err := models.UpdateUserTelegramChatID(userID, chatIDStr); err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "No se pudo vincular. Intenta de nuevo."})
|
||||
}
|
||||
models.DeleteTelegramStaffToken(userID)
|
||||
svc := &services.TelegramService{BotToken: cfg.BotToken}
|
||||
_ = svc.SendMessage(chatID, "✅ Tu Telegram quedó vinculado a tu usuario de U-Site.\n\nRecibirás aquí las tareas que te asignen y otras notificaciones personales.")
|
||||
return c.JSON(fiber.Map{"ok": true, "chat_id": chatIDStr})
|
||||
}
|
||||
|
||||
return c.Status(404).JSON(fiber.Map{"error": "Todavía no encontramos tu mensaje. Envía el código al bot y vuelve a intentar."})
|
||||
}
|
||||
Reference in New Issue
Block a user