Skip to content

Commit

Permalink
feat: Added '/edit-message' router
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Nov 15, 2023
1 parent baa1a8d commit 9d42589
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/controller/messageController.ts
Expand Up @@ -93,6 +93,53 @@ export async function sendMessage(req: Request, res: Response) {
}
}

export async function editMessage(req: Request, res: Response) {
/**
* #swagger.tags = ["Messages"]
#swagger.autoBody=false
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters["session"] = {
schema: 'NERDWHATS_AMERICA'
}
#swagger.requestBody = {
required: true,
"@content": {
"application/json": {
schema: {
type: "object",
properties: {
id: { type: "string" },
newText: { type: "string" },
options: { type: "object" },
}
},
examples: {
"Edit a message": {
value: {
id: 'true_5521999999999@c.us_3EB04FCAA1527EB6D9DEC8',
newText: 'New text for message'
}
},
}
}
}
}
*/
const { id, newText } = req.body;

const options = req.body.options || {};
try {
const edited = await (req.client as any).editMessage(id, newText, options);

req.io.emit('edited-message', edited);
returnSucess(res, edited);
} catch (error) {
returnError(req, res, error);
}
}

export async function sendFile(req: Request, res: Response) {
/**
* #swagger.tags = ["Messages"]
Expand Down
6 changes: 6 additions & 0 deletions src/routes/index.ts
Expand Up @@ -108,6 +108,12 @@ routes.post(
statusConnection,
MessageController.sendMessage
);
routes.post(
'/api/:session/edit-message',
verifyToken,
statusConnection,
MessageController.editMessage
);
routes.post(
'/api/:session/send-image',
upload.single('file'),
Expand Down
56 changes: 56 additions & 0 deletions src/swagger.json
Expand Up @@ -628,6 +628,62 @@
}
}
},
"/api/{session}/edit-message": {
"post": {
"tags": ["Messages"],
"description": "",
"parameters": [
{
"name": "session",
"in": "path",
"required": true,
"schema": {
"type": "string",
"example": "NERDWHATS_AMERICA"
}
}
],
"responses": {
"400": {
"description": "Bad Request"
}
},
"security": [
{
"bearerAuth": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"newText": {
"type": "string"
},
"options": {
"type": "object"
}
}
},
"examples": {
"Edit a message": {
"value": {
"id": "7787877872655655ad@ads858598.c.us",
"newText": "New text for message"
}
}
}
}
}
}
}
},
"/api/{session}/send-image": {
"post": {
"tags": ["Messages"],
Expand Down

0 comments on commit 9d42589

Please sign in to comment.