Skip to content

Commit

Permalink
feat: Route SendSticker and SendSticker as GIF close #833
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Jul 18, 2022
1 parent 46c411d commit 0d96b0c
Show file tree
Hide file tree
Showing 3 changed files with 334 additions and 4 deletions.
46 changes: 46 additions & 0 deletions src/controller/messageController.js
Expand Up @@ -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);
}
}
14 changes: 14 additions & 0 deletions src/routes/index.js
Expand Up @@ -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',
Expand Down
278 changes: 274 additions & 4 deletions src/swagger.json
Expand Up @@ -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
}
}
},
Expand Down Expand Up @@ -16206,7 +16434,7 @@
},
"SendMentionedRequest": {
"title": "SendMentionedRequest",
"required": ["phone", "message", "mentioned", "isGruop"],
"required": ["phone", "message", "mentioned", "isGroup"],
"type": "object",
"properties": {
"phone": {
Expand All @@ -16222,15 +16450,57 @@
},
"description": ""
},
"isGruop": {
"isGroup": {
"type": "boolean"
}
},
"example": {
"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": {
Expand Down

0 comments on commit 0d96b0c

Please sign in to comment.