uptime kuma webhook endpoint
This commit is contained in:
parent
674714f0f3
commit
8f5e717f9f
|
@ -311,3 +311,45 @@ func (h MessageHandler) sendMessageInternal(g *gin.Context, ctx *logic.AppContex
|
||||||
CompatMessageID: compatMsgID,
|
CompatMessageID: compatMsgID,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UptimeKumaWebHook swaggerdoc
|
||||||
|
//
|
||||||
|
// @Summary Send a new message
|
||||||
|
// @Description All parameter can be set via query-parameter or the json body. Only UserID, UserKey and Title are required
|
||||||
|
// @Tags External
|
||||||
|
//
|
||||||
|
// @Param query_data query handler.UptimeKumaWebHook.query false " "
|
||||||
|
// @Param post_body body handler.UptimeKumaWebHook.body false " "
|
||||||
|
//
|
||||||
|
// @Success 200 {object} any
|
||||||
|
// @Failure 400 {object} ginresp.apiError
|
||||||
|
// @Failure 401 {object} ginresp.apiError "The user_id was not found or the user_key is wrong"
|
||||||
|
// @Failure 403 {object} ginresp.apiError "The user has exceeded its daily quota - wait 24 hours or upgrade your account"
|
||||||
|
// @Failure 500 {object} ginresp.apiError "An internal server error occurred - try again later"
|
||||||
|
//
|
||||||
|
// @Router /webhook/uptime-kuma [POST]
|
||||||
|
func (h MessageHandler) UptimeKumaWebHook(g *gin.Context) ginresp.HTTPResponse {
|
||||||
|
type query struct {
|
||||||
|
UserID *models.UserID `form:"user_id" example:"7725"`
|
||||||
|
KeyToken *string `form:"key" example:"P3TNH8mvv14fm"`
|
||||||
|
}
|
||||||
|
type body struct {
|
||||||
|
Title string `json:"Title"`
|
||||||
|
Body string `json:"Body"`
|
||||||
|
}
|
||||||
|
var b body
|
||||||
|
var q query
|
||||||
|
|
||||||
|
ctx, httpErr := h.app.StartRequest(g, nil, &q, &b, nil)
|
||||||
|
|
||||||
|
if httpErr != nil {
|
||||||
|
return *httpErr
|
||||||
|
}
|
||||||
|
|
||||||
|
okResp, errResp := h.sendMessageInternal(g, ctx, q.UserID, q.KeyToken, nil, &b.Title, &b.Body, langext.Ptr(1), nil, nil, nil)
|
||||||
|
|
||||||
|
if errResp != nil {
|
||||||
|
return *errResp
|
||||||
|
}
|
||||||
|
return ginresp.JSON(http.StatusOK, okResp)
|
||||||
|
}
|
||||||
|
|
|
@ -122,7 +122,6 @@ func (r *Router) Init(e *gin.Engine) error {
|
||||||
|
|
||||||
apiv2 := e.Group("/api/v2/")
|
apiv2 := e.Group("/api/v2/")
|
||||||
{
|
{
|
||||||
|
|
||||||
apiv2.POST("/users", r.Wrap(r.apiHandler.CreateUser))
|
apiv2.POST("/users", r.Wrap(r.apiHandler.CreateUser))
|
||||||
apiv2.GET("/users/:uid", r.Wrap(r.apiHandler.GetUser))
|
apiv2.GET("/users/:uid", r.Wrap(r.apiHandler.GetUser))
|
||||||
apiv2.PATCH("/users/:uid", r.Wrap(r.apiHandler.UpdateUser))
|
apiv2.PATCH("/users/:uid", r.Wrap(r.apiHandler.UpdateUser))
|
||||||
|
@ -164,6 +163,9 @@ func (r *Router) Init(e *gin.Engine) error {
|
||||||
sendAPI.POST("/", r.Wrap(r.messageHandler.SendMessage))
|
sendAPI.POST("/", r.Wrap(r.messageHandler.SendMessage))
|
||||||
sendAPI.POST("/send", r.Wrap(r.messageHandler.SendMessage))
|
sendAPI.POST("/send", r.Wrap(r.messageHandler.SendMessage))
|
||||||
sendAPI.POST("/send.php", r.Wrap(r.messageHandler.SendMessageCompat))
|
sendAPI.POST("/send.php", r.Wrap(r.messageHandler.SendMessageCompat))
|
||||||
|
|
||||||
|
apiv2.POST("/webhook/uptime-kuma", r.Wrap(r.messageHandler.UptimeKumaWebHook))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================
|
// ================
|
||||||
|
|
|
@ -4,7 +4,7 @@ package models
|
||||||
|
|
||||||
import "gogs.mikescher.com/BlackForestBytes/goext/langext"
|
import "gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||||
|
|
||||||
const ChecksumGenerator = "a41b8d265c326a65d7be07c74aa2318064c6307256bd92b684c5adb4a8f82d97"
|
const ChecksumGenerator = "38908fc9adc16eb3a1266e4bca06e50ebc8613c5d3c9a4fea39314115f66544e"
|
||||||
|
|
||||||
type Enum interface {
|
type Enum interface {
|
||||||
Valid() bool
|
Valid() bool
|
||||||
|
|
|
@ -2731,6 +2731,69 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"/webhook/uptime-kuma": {
|
||||||
|
"post": {
|
||||||
|
"description": "All parameter can be set via query-parameter or the json body. Only UserID, UserKey and Title are required",
|
||||||
|
"tags": [
|
||||||
|
"External"
|
||||||
|
],
|
||||||
|
"summary": "Send a new message",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"example": "P3TNH8mvv14fm",
|
||||||
|
"name": "key",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"example": "7725",
|
||||||
|
"name": "user_id",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": " ",
|
||||||
|
"name": "post_body",
|
||||||
|
"in": "body",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/handler.UptimeKumaWebHook.body"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/ginresp.apiError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "The user_id was not found or the user_key is wrong",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/ginresp.apiError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"403": {
|
||||||
|
"description": "The user has exceeded its daily quota - wait 24 hours or upgrade your account",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/ginresp.apiError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "An internal server error occurred - try again later",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/ginresp.apiError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"definitions": {
|
"definitions": {
|
||||||
|
@ -3386,6 +3449,17 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"handler.UptimeKumaWebHook.body": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"Body": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"Title": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"handler.pingResponse": {
|
"handler.pingResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -3633,9 +3707,30 @@
|
||||||
"default_channel": {
|
"default_channel": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"default_priority": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"is_pro": {
|
"is_pro": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"max_body_size": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"max_channel_description_length": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"max_channel_name_length": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"max_sender_name_length": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"max_title_length": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"max_user_message_id_length": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"messages_sent": {
|
"messages_sent": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
@ -3680,9 +3775,30 @@
|
||||||
"default_channel": {
|
"default_channel": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"default_priority": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"is_pro": {
|
"is_pro": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"max_body_size": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"max_channel_description_length": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"max_channel_name_length": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"max_sender_name_length": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"max_title_length": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"max_user_message_id_length": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"messages_sent": {
|
"messages_sent": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
|
|
@ -458,6 +458,13 @@ definitions:
|
||||||
user_id:
|
user_id:
|
||||||
type: integer
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
|
handler.UptimeKumaWebHook.body:
|
||||||
|
properties:
|
||||||
|
Body:
|
||||||
|
type: string
|
||||||
|
Title:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
handler.pingResponse:
|
handler.pingResponse:
|
||||||
properties:
|
properties:
|
||||||
info:
|
info:
|
||||||
|
@ -621,8 +628,22 @@ definitions:
|
||||||
properties:
|
properties:
|
||||||
default_channel:
|
default_channel:
|
||||||
type: string
|
type: string
|
||||||
|
default_priority:
|
||||||
|
type: integer
|
||||||
is_pro:
|
is_pro:
|
||||||
type: boolean
|
type: boolean
|
||||||
|
max_body_size:
|
||||||
|
type: integer
|
||||||
|
max_channel_description_length:
|
||||||
|
type: integer
|
||||||
|
max_channel_name_length:
|
||||||
|
type: integer
|
||||||
|
max_sender_name_length:
|
||||||
|
type: integer
|
||||||
|
max_title_length:
|
||||||
|
type: integer
|
||||||
|
max_user_message_id_length:
|
||||||
|
type: integer
|
||||||
messages_sent:
|
messages_sent:
|
||||||
type: integer
|
type: integer
|
||||||
quota_max:
|
quota_max:
|
||||||
|
@ -652,8 +673,22 @@ definitions:
|
||||||
type: array
|
type: array
|
||||||
default_channel:
|
default_channel:
|
||||||
type: string
|
type: string
|
||||||
|
default_priority:
|
||||||
|
type: integer
|
||||||
is_pro:
|
is_pro:
|
||||||
type: boolean
|
type: boolean
|
||||||
|
max_body_size:
|
||||||
|
type: integer
|
||||||
|
max_channel_description_length:
|
||||||
|
type: integer
|
||||||
|
max_channel_name_length:
|
||||||
|
type: integer
|
||||||
|
max_sender_name_length:
|
||||||
|
type: integer
|
||||||
|
max_title_length:
|
||||||
|
type: integer
|
||||||
|
max_user_message_id_length:
|
||||||
|
type: integer
|
||||||
messages_sent:
|
messages_sent:
|
||||||
type: integer
|
type: integer
|
||||||
quota_max:
|
quota_max:
|
||||||
|
@ -2548,6 +2583,49 @@ paths:
|
||||||
summary: Send a new message (compatibility)
|
summary: Send a new message (compatibility)
|
||||||
tags:
|
tags:
|
||||||
- External
|
- External
|
||||||
|
/webhook/uptime-kuma:
|
||||||
|
post:
|
||||||
|
description: All parameter can be set via query-parameter or the json body.
|
||||||
|
Only UserID, UserKey and Title are required
|
||||||
|
parameters:
|
||||||
|
- example: P3TNH8mvv14fm
|
||||||
|
in: query
|
||||||
|
name: key
|
||||||
|
type: string
|
||||||
|
- example: "7725"
|
||||||
|
in: query
|
||||||
|
name: user_id
|
||||||
|
type: string
|
||||||
|
- description: ' '
|
||||||
|
in: body
|
||||||
|
name: post_body
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.UptimeKumaWebHook.body'
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/ginresp.apiError'
|
||||||
|
"401":
|
||||||
|
description: The user_id was not found or the user_key is wrong
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/ginresp.apiError'
|
||||||
|
"403":
|
||||||
|
description: The user has exceeded its daily quota - wait 24 hours or upgrade
|
||||||
|
your account
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/ginresp.apiError'
|
||||||
|
"500":
|
||||||
|
description: An internal server error occurred - try again later
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/ginresp.apiError'
|
||||||
|
summary: Send a new message
|
||||||
|
tags:
|
||||||
|
- External
|
||||||
swagger: "2.0"
|
swagger: "2.0"
|
||||||
tags:
|
tags:
|
||||||
- name: External
|
- name: External
|
||||||
|
|
Loading…
Reference in New Issue