feat: API pública para envío de SMS vía WebSMS

Agrega POST /api/sms/send autenticado con Bearer token (secret_key
auto-generado en WebSmsConfig). Recibe numero y mensaje, llama a
LabsMobile y registra el resultado en websms_log.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-23 23:13:57 -05:00
co-authored by Claude Sonnet 4.6
parent df1eb75bdd
commit 704664afe7
3 changed files with 78 additions and 6 deletions
+23 -5
View File
@@ -1,6 +1,9 @@
package models
import (
"crypto/rand"
"encoding/hex"
"github.com/sujit-baniya/fiber-boilerplate/app"
"gorm.io/gorm"
)
@@ -12,6 +15,13 @@ type WebSmsConfig struct {
Sender string `json:"sender" gorm:"column:sender;size:30"`
Notas string `json:"notas" gorm:"column:notas;type:text"`
Activo bool `json:"activo" gorm:"column:activo;default:true"`
SecretKey string `json:"secret_key" gorm:"column:secret_key;size:64;uniqueIndex"`
}
func generateWebSmsSecret() string {
b := make([]byte, 24)
rand.Read(b)
return "sms_" + hex.EncodeToString(b)
}
func (WebSmsConfig) TableName() string { return "websms_config" }
@@ -30,14 +40,22 @@ func SaveWebSmsConfig(s WebSmsConfig) error {
Update("activo", false)
s.Activo = true
if s.ID > 0 {
// preserve existing secret_key
var existing WebSmsConfig
app.Http.Database.DB.First(&existing, s.ID)
if existing.SecretKey == "" {
existing.SecretKey = generateWebSmsSecret()
}
return app.Http.Database.DB.Model(&s).Updates(map[string]interface{}{
"username": s.Username,
"api_token": s.ApiToken,
"sender": s.Sender,
"notas": s.Notas,
"activo": true,
"username": s.Username,
"api_token": s.ApiToken,
"sender": s.Sender,
"notas": s.Notas,
"activo": true,
"secret_key": existing.SecretKey,
}).Error
}
s.SecretKey = generateWebSmsSecret()
return app.Http.Database.DB.Create(&s).Error
}