Skip to content

Commit

Permalink
feat: Event onReactionMessage and SetGroup ProfilePic
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Jul 19, 2022
1 parent 7cf4a4a commit 86208a5
Show file tree
Hide file tree
Showing 6 changed files with 7,020 additions and 7,469 deletions.
6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -43,7 +43,8 @@
"moment": "^2.29.4",
"multer": "^1.4.4",
"socket.io": "^4.5.1",
"swagger-ui-express": "^4.5.0"
"swagger-ui-express": "^4.5.0",
"winston": "^3.8.1"
},
"devDependencies": {
"@babel/cli": "^7.18.6",
Expand Down Expand Up @@ -73,7 +74,8 @@
"release-it": "^15.1.2",
"rimraf": "^3.0.2",
"shx": "^0.3.4",
"swagger-ui-dist": "^4.12.0"
"swagger-ui-dist": "^4.12.0",
"webpack-cli": "^4.10.0"
},
"peerDependencies": {
"aws-sdk": "^2.1176.0",
Expand Down
3 changes: 2 additions & 1 deletion src/config.json
Expand Up @@ -16,7 +16,8 @@
"allUnreadOnStart": false,
"listenAcks": true,
"onPresenceChanged": true,
"onParticipantsChanged": true
"onParticipantsChanged": true,
"onReactionMessage": true
},
"archive": {
"enable": false,
Expand Down
9 changes: 2 additions & 7 deletions src/controller/groupController.js
Expand Up @@ -362,17 +362,12 @@ export async function changePrivacyGroup(req, res) {
}

export async function setGroupProfilePic(req, res) {
const { phone } = req.body;

if (!req.file) return res.status(400).json({ status: 'error', message: 'File parameter is required!' });
const { phone, path } = req.body;

try {
const { path: pathFile } = req.file;

for (const contato of contactToArray(phone, true)) {
await req.client.setProfilePic(pathFile, contato);
await req.client.setGroupIcon(contato, path);
}
await unlinkAsync(pathFile);

return res
.status(201)
Expand Down
151 changes: 151 additions & 0 deletions src/swagger.json
Expand Up @@ -9290,6 +9290,120 @@
"deprecated": false
}
},
"/group-pic": {
"post": {
"tags": ["Group"],
"summary": "Set Profile Pic for group",
"description": "Change Profile Pic of Group",
"operationId": "SetGroupProfilePic",
"parameters": [],
"requestBody": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SetGroupProfilePicRequest"
},
"example": {
"phone": "120363025416793270@g.us",
"path": "https://cdn.pixabay.com/photo/2016/02/10/21/57/heart-1192662__340.jpg",
"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": "36"
}
}
},
"ETag": {
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "W/\"24-Xm9Fmv/piJ8aftrp5VK0tqiuuAc\""
}
}
},
"Date": {
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "Fri, 14 May 2021 15:31:41 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/SetGroupProfilePicRequest"
},
"example": {
"status": "success",
"response": true
}
}
}
}
},
"deprecated": false
}
},
"/get-battery-level": {
"get": {
"tags": ["Phone Status"],
Expand Down Expand Up @@ -18451,6 +18565,43 @@
"value": true
}
},
"SetGroupProfilePicRequest": {
"title": "SetGroupProfilePicRequest",
"required": ["phone", "path", "isGroup"],
"type": "object",
"properties": {
"phone": {
"type": "string"
},
"path": {
"type": "string"
},
"isGroup": {
"type": "boolean"
}
},
"example": {
"phone": "120363025416793270@g.us",
"path": "https://www.camarabracodotrombudo.sc.gov.br/media/noticia/link-para-participacao-da-audiencia-publica-54.jpg"
}
},
"SetGroupProfilePic": {
"title": "SetGroupProfilePic",
"required": ["status", "response"],
"type": "object",
"properties": {
"status": {
"type": "string"
},
"response": {
"type": "boolean"
}
},
"example": {
"status": "success",
"response": true
}
},
"SetMessagesAdminsOnly": {
"title": "SetMessagesAdminsOnly",
"required": ["status", "response"],
Expand Down
12 changes: 12 additions & 0 deletions src/util/createSessionUtil.js
Expand Up @@ -76,6 +76,10 @@ export default class CreateSessionUtil {
if (req.serverOptions.webhook.onParticipantsChanged) {
await this.onParticipantsChanged(req, client);
}

if (req.serverOptions.webhook.onReactionMessage) {
await this.onReactionMessage(client, req);
}
} catch (e) {
req.logger.error(e);
}
Expand Down Expand Up @@ -189,6 +193,14 @@ export default class CreateSessionUtil {
});
}

async onReactionMessage(client, req) {
await client.isConnected();
await client.onReactionMessage(async (reaction) => {
req.io.emit('onreactionmessage', reaction);
callWebHook(client, req, 'onreactionmessage', reaction);
});
}

encodeFunction(data, webhook) {
data.webhook = webhook;
return JSON.stringify(data);
Expand Down

0 comments on commit 86208a5

Please sign in to comment.