From 03af708f11177506ef078e2571519b1ba3342d07 Mon Sep 17 00:00:00 2001 From: Bernhard B Date: Fri, 16 Feb 2024 19:18:48 +0100 Subject: [PATCH] added hidden 'recipient' parameter to /v2/send endpoint * some REST API consumers (like the Synology NAS) do not allow to use an array for the recipients. So, in order to support those platforms as well, a 'recipient' string parameter is added. As most users are perfectly fine with the array parameter, the recipient parameter won't be exposed in the Swagger UI. see #428 --- src/api/api.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/api/api.go b/src/api/api.go index fc2f595..b8071bc 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -102,6 +102,7 @@ type SendMessageV1 struct { type SendMessageV2 struct { Number string `json:"number"` Recipients []string `json:"recipients"` + Recipient string `json:"recipient" swaggerignore:"true"` //some REST API consumers (like the Synology NAS) do not support an array as recipients, so we provide this string parameter here as backup. In order to not confuse anyone, the parameter won't be exposed in the Swagger UI (most users are fine with the recipients parameter). Message string `json:"message"` Base64Attachments []string `json:"base64_attachments" example:",data:;base64,data:;filename=;base64"` Sticker string `json:"sticker"` @@ -363,6 +364,13 @@ func (a *Api) SendV2(c *gin.Context) { return } + //some REST API consumers (like the Synology NAS) do not allow to use an array for the recipients. + //so, in order to also support those platforms, a fallback parameter (recipient) is provided. + //this parameter is hidden in the swagger ui in order to not confuse users (most of them are fine with the recipients parameter). + if req.Recipient != "" { + req.Recipients = append(req.Recipients, req.Recipient) + } + if len(req.Recipients) == 0 { c.JSON(400, gin.H{"error": "Couldn't process request - please provide at least one recipient"}) return