From 0d96b0c2bd86e75c9e0d0789c496f6011409a6b8 Mon Sep 17 00:00:00 2001 From: icleitoncosta Date: Mon, 18 Jul 2022 13:24:05 -0300 Subject: [PATCH] feat: Route SendSticker and SendSticker as GIF close #833 --- src/controller/messageController.js | 46 +++++ src/routes/index.js | 14 ++ src/swagger.json | 278 +++++++++++++++++++++++++++- 3 files changed, 334 insertions(+), 4 deletions(-) diff --git a/src/controller/messageController.js b/src/controller/messageController.js index 80d156fc60..d8e4b61b1d 100755 --- a/src/controller/messageController.js +++ b/src/controller/messageController.js @@ -327,3 +327,49 @@ export async function sendVideoStorie(req, res) { returnError(req, res, error); } } +export async function sendImageAsSticker(req, res) { + const { phone, path } = req.body; + + if (!path && !req.file) + return res.status(401).send({ + message: 'Sending the file is mandatory', + }); + + const pathFile = path || req.file.path; + + try { + let results = []; + for (const contato of phone) { + results.push(await req.client.sendImageAsSticker(contato, pathFile)); + } + + if (results.length === 0) return res.status(400).json('Error sending message'); + if (req.file) await unlinkAsync(pathFile); + returnSucess(res, results); + } catch (error) { + returnError(req, res, error); + } +} +export async function sendImageAsStickerGif(req, res) { + const { phone, path } = req.body; + + if (!path && !req.file) + return res.status(401).send({ + message: 'Sending the file is mandatory', + }); + + const pathFile = path || req.file.path; + + try { + let results = []; + for (const contato of phone) { + results.push(await req.client.sendImageAsStickerGif(contato, pathFile)); + } + + if (results.length === 0) return res.status(400).json('Error sending message'); + if (req.file) await unlinkAsync(pathFile); + returnSucess(res, results); + } catch (error) { + returnError(req, res, error); + } +} diff --git a/src/routes/index.js b/src/routes/index.js index 940ddd3e5b..f0928044cb 100755 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -60,6 +60,20 @@ routes.post( statusConnection, MessageController.sendImage ); +routes.post( + '/api/:session/send-sticker', + upload.single('file'), + verifyToken, + statusConnection, + MessageController.sendImageAsSticker +); +routes.post( + '/api/:session/send-sticker-gif', + upload.single('file'), + verifyToken, + statusConnection, + MessageController.sendImageAsStickerGif +); routes.post('/api/:session/send-reply', verifyToken, statusConnection, MessageController.replyMessage); routes.post( '/api/:session/send-file', diff --git a/src/swagger.json b/src/swagger.json index ece5aa8b77..8cc1f82aa7 100644 --- a/src/swagger.json +++ b/src/swagger.json @@ -5748,7 +5748,235 @@ "phone": "556593077171-1620997998", "message": "ola como isso funciona @556593077171@c.us", "mentioned": ["@556593077171@c.us"], - "isGruop": true + "isGroup": true + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "OK", + "headers": { + "X-Powered-By": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "Express" + } + } + }, + "Access-Control-Allow-Origin": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "*" + } + } + }, + "Content-Length": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "64" + } + } + }, + "ETag": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "W/\"40-aUMmvTS4ltJXN27NdzhnICW9ZI4\"" + } + } + }, + "Date": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "Fri, 14 May 2021 12:58:33 GMT" + } + } + }, + "Connection": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "keep-alive" + } + } + }, + "Keep-Alive": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "timeout=5" + } + } + } + }, + "content": { + "application/json; charset=utf-8": { + "schema": { + "$ref": "#/components/schemas/SendLinkPreview" + }, + "example": { + "status": "Success", + "message": "O link foi enviado com sucesso." + } + } + } + } + }, + "deprecated": false + } + }, + "/send-sticker": { + "post": { + "tags": ["Send Message"], + "summary": "Send Sticker", + "description": "Sends sticker", + "operationId": "SendSticker", + "parameters": [], + "requestBody": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SendStickerRequest" + }, + "example": { + "phone": "556593077171", + "path": "https://www.camarabracodotrombudo.sc.gov.br/media/noticia/link-para-participacao-da-audiencia-publica-54.jpg", + "isGroup": false + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "OK", + "headers": { + "X-Powered-By": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "Express" + } + } + }, + "Access-Control-Allow-Origin": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "*" + } + } + }, + "Content-Length": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "64" + } + } + }, + "ETag": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "W/\"40-aUMmvTS4ltJXN27NdzhnICW9ZI4\"" + } + } + }, + "Date": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "Fri, 14 May 2021 12:58:33 GMT" + } + } + }, + "Connection": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "keep-alive" + } + } + }, + "Keep-Alive": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "timeout=5" + } + } + } + }, + "content": { + "application/json; charset=utf-8": { + "schema": { + "$ref": "#/components/schemas/SendLinkPreview" + }, + "example": { + "status": "Success", + "message": "O link foi enviado com sucesso." + } + } + } + } + }, + "deprecated": false + } + }, + "/send-sticker-gif": { + "post": { + "tags": ["Send Message"], + "summary": "Send Sticker", + "description": "Sends sticker gif", + "operationId": "SendStickerGif", + "parameters": [], + "requestBody": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SendStickerGifRequest" + }, + "example": { + "phone": "556593077171", + "path": "https://media.giphy.com/media/hpXFi66bfQm7e81ohw/giphy.gif", + "isGroup": false } } }, @@ -16206,7 +16434,7 @@ }, "SendMentionedRequest": { "title": "SendMentionedRequest", - "required": ["phone", "message", "mentioned", "isGruop"], + "required": ["phone", "message", "mentioned", "isGroup"], "type": "object", "properties": { "phone": { @@ -16222,7 +16450,7 @@ }, "description": "" }, - "isGruop": { + "isGroup": { "type": "boolean" } }, @@ -16230,7 +16458,49 @@ "phone": "556593077171-1620997998", "message": "ola como isso funciona @556593077171@c.us", "mentioned": ["@556593077171@c.us"], - "isGruop": true + "isGroup": true + } + }, + "SendStickerRequest": { + "title": "SendStickerRequest", + "required": ["phone"], + "type": "object", + "properties": { + "phone": { + "type": "string" + }, + "path": { + "type": "string" + }, + "isGroup": { + "type": "boolean" + } + }, + "example": { + "phone": "556593077171", + "path": "https://www.camarabracodotrombudo.sc.gov.br/media/noticia/link-para-participacao-da-audiencia-publica-54.jpg", + "isGroup": false + } + }, + "SendStickerGifRequest": { + "title": "SendStickerGifRequest", + "required": ["phone"], + "type": "object", + "properties": { + "phone": { + "type": "string" + }, + "path": { + "type": "string" + }, + "isGroup": { + "type": "boolean" + } + }, + "example": { + "phone": "556593077171", + "path": "https://media.giphy.com/media/hpXFi66bfQm7e81ohw/giphy.gif", + "isGroup": false } }, "ChangeUsernameRequest": {