1
0

external_notify.go 952 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package external_notify
  2. import (
  3. "net/http"
  4. "github.com/0xJacky/Nginx-UI/internal/notification"
  5. "github.com/0xJacky/Nginx-UI/model"
  6. "github.com/gin-gonic/gin"
  7. "github.com/uozi-tech/cosy"
  8. )
  9. func InitRouter(r *gin.RouterGroup) {
  10. c := cosy.Api[model.ExternalNotify]("/external_notifies")
  11. c.InitRouter(r)
  12. r.POST("/external_notifies/test", testMessage)
  13. }
  14. // testMessage sends a test message with direct parameters
  15. func testMessage(c *gin.Context) {
  16. var req struct {
  17. Type string `json:"type" binding:"required"`
  18. Language string `json:"language" binding:"required"`
  19. Config map[string]string `json:"config" binding:"required"`
  20. }
  21. if !cosy.BindAndValid(c, &req) {
  22. return
  23. }
  24. // Send test notification with direct parameters
  25. err := notification.SendTestMessage(req.Type, req.Language, req.Config)
  26. if err != nil {
  27. cosy.ErrHandler(c, err)
  28. return
  29. }
  30. c.JSON(http.StatusOK, gin.H{
  31. "message": "ok",
  32. })
  33. }