Skip to content

Commit 3a123cf

Browse files
committed
feat(notification): add test message API #1262
1 parent f29238f commit 3a123cf

File tree

27 files changed

+3048
-1266
lines changed

27 files changed

+3048
-1266
lines changed

api/external_notify/external_notify.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package external_notify
22

33
import (
4+
"net/http"
5+
6+
"github.com/0xJacky/Nginx-UI/internal/notification"
47
"github.com/0xJacky/Nginx-UI/model"
58
"github.com/gin-gonic/gin"
69
"github.com/uozi-tech/cosy"
@@ -10,4 +13,29 @@ func InitRouter(r *gin.RouterGroup) {
1013
c := cosy.Api[model.ExternalNotify]("/external_notifies")
1114

1215
c.InitRouter(r)
16+
17+
r.POST("/external_notifies/test", testMessage)
18+
}
19+
20+
// testMessage sends a test message with direct parameters
21+
func testMessage(c *gin.Context) {
22+
var req struct {
23+
Type string `json:"type" binding:"required"`
24+
Language string `json:"language" binding:"required"`
25+
Config map[string]string `json:"config" binding:"required"`
26+
}
27+
if !cosy.BindAndValid(c, &req) {
28+
return
29+
}
30+
31+
// Send test notification with direct parameters
32+
err := notification.SendTestMessage(req.Type, req.Language, req.Config)
33+
if err != nil {
34+
cosy.ErrHandler(c, err)
35+
return
36+
}
37+
38+
c.JSON(http.StatusOK, gin.H{
39+
"message": "ok",
40+
})
1341
}

app/src/api/external_notify.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
import type { ModelBase } from '@/api/curd'
2-
import { useCurdApi } from '@uozi-admin/request'
2+
import { http, useCurdApi } from '@uozi-admin/request'
33

44
export interface ExternalNotify extends ModelBase {
55
type: string
6+
language: string
7+
config: Record<string, string>
8+
}
9+
10+
export interface TestMessageRequest {
11+
type: string
12+
language: string
613
config: Record<string, string>
714
}
815

916
const baseUrl = '/external_notifies'
1017

1118
const externalNotify = useCurdApi<ExternalNotify>(baseUrl)
1219

20+
// Add test message API with direct parameters
21+
export function testMessage(params: TestMessageRequest): Promise<{ message: string }> {
22+
return http.post(`${baseUrl}/test`, params)
23+
}
24+
1325
export default externalNotify

app/src/components/Notification/notifications.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ const notifications: Record<string, { title: () => string, content: (args: any)
8989
title: () => $gettext('Delete Remote Config Success'),
9090
content: (args: any) => $gettext('Delete %{path} on %{env_name} successfully', args, true),
9191
},
92+
'External Notification Test': {
93+
title: () => $gettext('External Notification Test'),
94+
content: (args: any) => $gettext('This is a test message sent at %{timestamp} from Nginx UI.', args, true),
95+
},
9296
'Delete Remote Site Error': {
9397
title: () => $gettext('Delete Remote Site Error'),
9498
content: (args: any) => $gettext('Delete site %{name} from %{node} failed', args, true),
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export default {
22
404001: () => $gettext('Notifier not found'),
33
400001: () => $gettext('Invalid notifier config'),
4+
400002: () => $gettext('Invalid notification ID'),
5+
404002: () => $gettext('External notification configuration not found'),
46
}

0 commit comments

Comments
 (0)