notification.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package notification
  2. import (
  3. "time"
  4. "github.com/0xJacky/Nginx-UI/model"
  5. )
  6. func Info(title string, content string, details any) {
  7. push(model.NotificationInfo, title, content, details)
  8. }
  9. func Error(title string, content string, details any) {
  10. push(model.NotificationError, title, content, details)
  11. }
  12. func Warning(title string, content string, details any) {
  13. push(model.NotificationWarning, title, content, details)
  14. }
  15. func Success(title string, content string, details any) {
  16. push(model.NotificationSuccess, title, content, details)
  17. }
  18. func Define(title string, content string, details any) *model.Notification {
  19. return &model.Notification{
  20. Type: model.NotificationInfo,
  21. Title: title,
  22. Content: content,
  23. Details: details,
  24. }
  25. }
  26. // SendTestMessage sends a test message with direct parameters
  27. func SendTestMessage(notifyType, language string, config map[string]string) error {
  28. timestamp := time.Now().Format(time.DateTime)
  29. data := Define("External Notification Test", "This is a test message sent at %{timestamp} from Nginx UI.", map[string]any{
  30. "timestamp": timestamp,
  31. })
  32. // Create external message and send with direct parameters
  33. extNotify := &ExternalMessage{data}
  34. err := extNotify.SendWithConfig(notifyType, language, config)
  35. if err != nil {
  36. return err
  37. }
  38. return nil
  39. }