Skip to content
10 changes: 4 additions & 6 deletions src/controller/deviceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,21 +377,19 @@ export async function getChatById(req: Request, res: Response) {
schema: 'NERDWHATS_AMERICA'
}
#swagger.parameters["phone"] = {
schema: '5521999999999'
schema: '5521999999999@c.us'
}
#swagger.parameters["isGroup"] = {
schema: 'false'
}
*/
const { phone } = req.params;
const { isGroup } = req.query;
const { isGroup = false } = req.query;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { isGroup = false } = req.query;
const normalizedPN = phone?.split('@')?.[0]
const { isGroup = false } = req.query;


try {
let result = {} as Chat;
if (isGroup) {
result = await req.client.getChatById(`${phone}@g.us`);
} else {
result = await req.client.getChatById(`${phone}@c.us`);
for (const contato of contactToArray(phone as string, isGroup as boolean)) {
result = await req.client.getChatById(contato);
Comment on lines +391 to +392
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (const contato of contactToArray(phone as string, isGroup as boolean)) {
result = await req.client.getChatById(contato);
if (isGroup) {
result = await req.client.getChatById(`${normalizedPN}@g.us`);
} else {
result = await req.client.getChatById(`${normalizedPN}@c.us`);

}

res.status(200).json(result);
Expand Down
Loading