Skip to content

Commit

Permalink
Correções
Browse files Browse the repository at this point in the history
  • Loading branch information
rtenorioh authored Jun 10, 2022
1 parent baf20fb commit 95aea72
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 24 deletions.
18 changes: 13 additions & 5 deletions backend/src/controllers/ContactController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type IndexQuery = {
type IndexGetContactQuery = {
name: string;
number: string;
email: string;
};

interface ExtraInfo {
Expand All @@ -47,19 +48,26 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
};

export const getContact = async (req: Request, res: Response): Promise<Response> => {
const { name, number } = req.body as IndexGetContactQuery;
const { name, number, email } = req.body as IndexGetContactQuery;

const contact = await GetContactService({
name,
number
number,
email
});

return res.status(200).json(contact);
};

export const store = async (req: Request, res: Response): Promise<Response> => {
const newContact: ContactData = req.body;
newContact.number = newContact.number.replace("-", "").replace(" ", "");
newContact.number = newContact.number.replace("-", "")
.replace(" ", "")
.replace("(", "")
.replace(")", "")
.replace("+", "")
.replace(".", "")
.replace("_", "");;

const schema = Yup.object().shape({
name: Yup.string().required(),
Expand All @@ -75,8 +83,8 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
}

await CheckIsValidContact(newContact.number);
const validNumber : any = await CheckContactNumber(newContact.number)
const validNumber: any = await CheckContactNumber(newContact.number)

const profilePicUrl = await GetProfilePicUrl(validNumber);

let name = newContact.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ module.exports = {
value: "disabled",
createdAt: new Date(),
updatedAt: new Date()
},
{
key: "darkMode",
value: "disabled",
createdAt: new Date(),
updatedAt: new Date()
}
],
{}
Expand Down
9 changes: 8 additions & 1 deletion backend/src/services/ContactServices/ListContactsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ const ListContactsService = async ({
`%${searchParam.toLowerCase().trim()}%`
)
},
{ number: { [Op.like]: `%${searchParam.toLowerCase().trim()}%` } }
{ number: { [Op.like]: `%${searchParam.toLowerCase().trim()}%` } },
{
email: Sequelize.where(
Sequelize.fn("LOWER", Sequelize.col("email")),
"LIKE",
`%${searchParam.toLowerCase().trim()}%`
)
},
]
};
const limit = 20;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/services/TicketServices/ShowTicketService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ShowTicketService = async (id: string | number): Promise<Ticket> => {
{
model: Contact,
as: "contact",
attributes: ["id", "name", "number", "profilePicUrl"],
attributes: ["id", "name", "number", "email", "profilePicUrl"],
include: ["extraInfo"]
},
{
Expand Down
33 changes: 18 additions & 15 deletions backend/src/services/WbotServices/wbotMessageListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService";
import { debounce } from "../../helpers/Debounce";
import UpdateTicketService from "../TicketServices/UpdateTicketService";
import CreateContactService from "../ContactServices/CreateContactService";
import GetContactService from "../ContactServices/GetContactService";
// import GetContactService from "../ContactServices/GetContactService";
import formatBody from "../../helpers/Mustache";

interface Session extends Client {
Expand Down Expand Up @@ -214,7 +214,7 @@ const isValidMsg = (msg: WbotMessage): boolean => {
msg.type === "document" ||
msg.type === "vcard" ||
msg.type === "call_log" ||
//msg.type === "multi_vcard" ||
// msg.type === "multi_vcard" ||
msg.type === "sticker"
)
return true;
Expand All @@ -229,21 +229,24 @@ const handleMessage = async (
return;
}

//IGNORAR MENSAGENS DE GRUPO
// IGNORAR MENSAGENS DE GRUPO
const Settingdb = await Settings.findOne({
where: { key: 'CheckMsgIsGroup' }
});
if (Settingdb?.value == 'enabled') {
if (Settingdb?.value === 'enabled') {
const chat = await msg.getChat();
if (
msg.type === "sticker" ||
msg.type === "e2e_notification" ||
msg.type === "notification_template" ||
msg.from === "status@broadcast" ||
msg.author != null ||
chat.isGroup
) {
return;
}
}
//IGNORAR MENSAGENS DE GRUPO
// IGNORAR MENSAGENS DE GRUPO

try {
let msgContact: WbotContact;
Expand All @@ -261,16 +264,16 @@ const handleMessage = async (
!msg.hasMedia &&
msg.type !== "chat" &&
msg.type !== "vcard"
//&& msg.type !== "multi_vcard"
// && msg.type !== "multi_vcard"
)
return;

msgContact = await wbot.getContactById(msg.to);
} else {
const listSettingsService = await ListSettingsServiceOne({key: "call"});
var callSetting = listSettingsService?.value;
const listSettingsService = await ListSettingsServiceOne({ key: "call" });
let callSetting = listSettingsService?.value;

msgContact = await msg.getContact();
msgContact = await msg.getContact();
}

const chat = await msg.getChat();
Expand Down Expand Up @@ -350,7 +353,7 @@ const handleMessage = async (
}
}

/*if (msg.type === "multi_vcard") {
/* if (msg.type === "multi_vcard") {
try {
const array = msg.vCards.toString().split("\n");
let name = "";
Expand Down Expand Up @@ -409,12 +412,12 @@ const handleMessage = async (
} catch (error) {
console.log(error);
}
}*/
} */

if(msg.type==="call_log" && callSetting==="disabled"){
const sentMessage = await wbot.sendMessage(`${contact.number}@c.us`, "*Mensagem Automática:*\nAs chamadas de voz e vídeo estão desabilitas para esse WhatsApp, favor enviar uma mensagem de texto. Obrigado");
await verifyMessage(sentMessage, ticket, contact);
}
if (msg.type === "call_log" && callSetting === "disabled") {
const sentMessage = await wbot.sendMessage(`${contact.number}@c.us`, "*Mensagem Automática:*\nAs chamadas de voz e vídeo estão desabilitas para esse WhatsApp, favor enviar uma mensagem de texto. Obrigado");
await verifyMessage(sentMessage, ticket, contact);
}

} catch (err) {
Sentry.captureException(err);
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/translate/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,14 @@ const messages = {
disabled: "Disabled",
},
},
darkMode: {
name: "Enable Dark Mode",
note: "Switch between light mode and dark mode",
options: {
enabled: "Enabled",
disabled: "Disabled",
},
},
messagesList: {
header: {
assignedTo: "Assigned to:",
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/translate/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,17 @@ const messages = {
note: "Cierra automáticamente el ticket cuando se envía a través de API",
options: {
enabled: "Habilitado",
disabled: "Habilitado",
disabled: "Deshabilitado",
},
},
darkMode: {
name: "Habilitar modo oscuro",
note: "Cambiar entre el modo claro y el modo oscuro",
options: {
enabled: "Habilitado",
disabled: "Deshabilitado",
},
},
timeCreateNewTicket: {
name: "Crear nuevo ticket después",
note: "Selecciona el tiempo que tardará en abrir un nuevo ticket si el cliente te vuelve a contactar",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/translate/languages/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ const messages = {
},
darkMode: {
name: "Ativa Modo Escuro",
note: "Se habilitado, modo escuro no sistema",
note: "Alternar entre o modo claro e o modo escuro",
options: {
enabled: "Ativado",
disabled: "Desativado",
Expand Down

0 comments on commit 95aea72

Please sign in to comment.