Implement /shoutrrr endpoint
This commit is contained in:
@@ -28,8 +28,10 @@ func NewExternalHandler(app *logic.Application) ExternalHandler {
|
||||
|
||||
// UptimeKuma 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
|
||||
// @Summary Send a new message (uses uptime-kuma notification schema)
|
||||
// @Description Set necessary parameter via query (key, channel etc.), title+message are build from uptime-kuma payload
|
||||
// @Description You can specify different channels/priorities for [up] and [down] notifications
|
||||
//
|
||||
// @Tags External
|
||||
//
|
||||
// @Param query_data query handler.UptimeKuma.query false " "
|
||||
@@ -136,3 +138,58 @@ func (h ExternalHandler) UptimeKuma(pctx ginext.PreContext) ginext.HTTPResponse
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// Shoutrrr swaggerdoc
|
||||
//
|
||||
// @Summary Send a new message (uses shoutrrr generic:// format=json schema)
|
||||
// @Description Set necessary parameter via query (key, channel etc.), title+message are set via the shoutrrr payload
|
||||
// @Description Use the shoutrrr format `generic://{{url}}?template=json`
|
||||
//
|
||||
// @Tags External
|
||||
//
|
||||
// @Param query_data query handler.Shoutrrr.query false " "
|
||||
// @Param post_body body handler.Shoutrrr.body false " "
|
||||
//
|
||||
// @Success 200 {object} handler.Shoutrrr.response
|
||||
// @Failure 400 {object} ginresp.apiError
|
||||
// @Failure 401 {object} ginresp.apiError "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 /external/v1/uptime-kuma [POST]
|
||||
func (h ExternalHandler) Shoutrrr(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type query struct {
|
||||
KeyToken *string `form:"key" example:"P3TNH8mvv14fm"`
|
||||
Channel *string `form:"channel"`
|
||||
Priority *int `form:"priority"`
|
||||
SenderName *string `form:"senderName"`
|
||||
}
|
||||
type body struct {
|
||||
Title string `json:"title"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
type response struct {
|
||||
MessageID models.MessageID `json:"message_id"`
|
||||
}
|
||||
|
||||
var b body
|
||||
var q query
|
||||
ctx, g, errResp := pctx.Query(&q).Body(&b).Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
return h.app.DoRequest(ctx, g, models.TLockReadWrite, func(ctx *logic.AppContext, finishSuccess func(r ginext.HTTPResponse) ginext.HTTPResponse) ginext.HTTPResponse {
|
||||
|
||||
okResp, errResp := h.app.SendMessage(g, ctx, q.KeyToken, q.Channel, &b.Title, &b.Message, q.Priority, nil, nil, q.SenderName)
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
|
||||
return finishSuccess(ginext.JSON(http.StatusOK, response{
|
||||
MessageID: okResp.Message.MessageID,
|
||||
}))
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user