Skip to content

Commit

Permalink
feat: Added reactions and poll functions and events
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Dec 15, 2022
1 parent f698f2a commit 37fef0a
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/config.json
Expand Up @@ -17,7 +17,8 @@
"listenAcks": true,
"onPresenceChanged": true,
"onParticipantsChanged": true,
"onReactionMessage": true
"onReactionMessage": true,
"onPollResponse": true
},
"archive": {
"enable": false,
Expand Down
23 changes: 23 additions & 0 deletions src/controller/deviceController.js
Expand Up @@ -727,6 +727,29 @@ export async function starMessage(req, res) {
}
}

export async function getReactions(req, res) {
const messageId = req.params.id;
try {
let response = await req.client.getReactions(messageId);

return res.status(200).json({ status: 'success', response: response });
} catch (error) {
req.logger.error(error);
return res.status(500).json({ status: 'error', message: 'Error on get reactions' });
}
}

export async function getVotes(req, res) {
const messageId = req.params.id;
try {
let response = await req.client.getVotes(messageId);

return res.status(200).json({ status: 'success', response: response });
} catch (error) {
req.logger.error(error);
return res.status(500).json({ status: 'error', message: 'Error on get votes' });
}
}
export async function chatWoot(req, res) {
const { session } = req.params;
const client = clientsArray[session];
Expand Down
2 changes: 2 additions & 0 deletions src/routes/index.js
Expand Up @@ -199,6 +199,8 @@ routes.post('/api/:session/temporary-messages', verifyToken, statusConnection, D
routes.post('/api/:session/typing', verifyToken, statusConnection, DeviceController.setTyping);
routes.post('/api/:session/recording', verifyToken, statusConnection, DeviceController.setRecording);
routes.post('/api/:session/star-message', verifyToken, statusConnection, DeviceController.starMessage);
routes.get('/api/:session/reactions/:id', verifyToken, statusConnection, DeviceController.getReactions);
routes.get('/api/:session/votes/:id', verifyToken, statusConnection, DeviceController.getVotes);
routes.post('/api/:session/reject-call', verifyToken, statusConnection, DeviceController.rejectCall);

// Catalog
Expand Down
238 changes: 238 additions & 0 deletions src/swagger.json
Expand Up @@ -5964,6 +5964,244 @@
"deprecated": false
}
},

"/reactions/{msgId}": {
"get": {
"tags": ["Chat"],
"summary": "Get reactions of a message",
"operationId": "getReactions",
"parameters": [
{
"name": "Content-Type",
"in": "header",
"description": "",
"required": true,
"style": "simple",
"schema": {
"type": "string",
"example": "application/json"
}
},
{
"in": "path",
"name": "msgId",
"schema": {
"type": "string"
},
"required": true,
"description": "The message id"
}
],
"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": "14300"
}
}
},
"ETag": {
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "W/\"37dc-Gh3xKCwbIdtSuq3hb/nlZD5wjYE\""
}
}
},
"Date": {
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "Thu, 13 May 2021 19:34:45 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/AllMessagesinChat"
},
"example": {
"status": "success",
"response": []
}
}
}
}
},
"deprecated": false
}
},

"/votes/{msgId}": {
"get": {
"tags": ["Chat"],
"summary": "Get votes of a message",
"operationId": "getVotes",
"parameters": [
{
"name": "Content-Type",
"in": "header",
"description": "",
"required": true,
"style": "simple",
"schema": {
"type": "string",
"example": "application/json"
}
},
{
"in": "path",
"name": "msgId",
"schema": {
"type": "string"
},
"required": true,
"description": "The message id"
}
],
"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": "14300"
}
}
},
"ETag": {
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "W/\"37dc-Gh3xKCwbIdtSuq3hb/nlZD5wjYE\""
}
}
},
"Date": {
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "Thu, 13 May 2021 19:34:45 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/AllMessagesinChat"
},
"example": {
"status": "success",
"response": []
}
}
}
}
},
"deprecated": false
}
},
"/send-file-base64": {
"post": {
"tags": ["Send Message"],
Expand Down
12 changes: 12 additions & 0 deletions src/util/createSessionUtil.js
Expand Up @@ -83,6 +83,10 @@ export default class CreateSessionUtil {
if (req.serverOptions.webhook.onReactionMessage) {
await this.onReactionMessage(client, req);
}

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

async onPollResponse(client, req) {
await client.isConnected();
await client.onPollResponse(async (response) => {
req.io.emit('onpollresponse', response);
callWebHook(client, req, 'onpollresponse', response);
});
}

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

0 comments on commit 37fef0a

Please sign in to comment.