Desabilitação do recurso de pesquisar relatorio a partir de datas anteriores a atual. Desabilitação do metodo que verifica o bot para interação com o usuario

pull/12/head
adriano 2022-07-20 12:34:12 -03:00
parent 10819163e9
commit 75fd79fc8d
7 changed files with 66 additions and 52 deletions

View File

@ -48,12 +48,35 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
if (medias) { if (medias) {
await Promise.all( await Promise.all(
medias.map(async (media: Express.Multer.File) => { medias.map(async (media: Express.Multer.File) => {
console.log(`\n >>>>>>>>>> SENDING MESSAGE MEDIA
Parcial ticket info and media:
ticket.id: ${ticket.id}
ticket.status: ${ticket.status}
ticket.whatsapp.id: ${ticket.whatsappId}
ticket.contact.number: ${ticket.contact.number}
ticket.contact.name: ${ticket.contact.name}
ticket.contact.profilePicUrl: ${ticket.contact.profilePicUrl}
ticket.user.id: ${ticket.user.id}
ticket.user.name: ${ticket.user.name}
media:`, media,'\n')
await SendWhatsAppMedia({ media, ticket }); await SendWhatsAppMedia({ media, ticket });
}) })
); );
} else { } else {
console.log('------- quotedMsg: ', quotedMsg, ' | ticket: ', ticket) console.log(`\n >>>>>>>>>> SENDING MESSAGE
Parcial ticket info:
ticket.id: ${ticket.id}
ticket.status: ${ticket.status}
ticket.whatsapp.id: ${ticket.whatsappId}
ticket.contact.number: ${ticket.contact.number}
ticket.contact.name: ${ticket.contact.name}
ticket.contact.profilePicUrl: ${ticket.contact.profilePicUrl}
ticket.user.id: ${ticket.user.id}
ticket.user.name: ${ticket.user.name}\n`)
await SendWhatsAppMessage({ body, ticket, quotedMsg }); await SendWhatsAppMessage({ body, ticket, quotedMsg });
} }

View File

@ -44,7 +44,8 @@ const restart = async (req: Request, res: Response): Promise<Response> => {
const whatsapp = await ShowWhatsAppService(whatsappId); const whatsapp = await ShowWhatsAppService(whatsappId);
restartWhatsSession(whatsapp, true) // restartWhatsSession(whatsapp, true)
restartWhatsSession(whatsapp)
return res.status(200).json({ message: "Starting session." }); return res.status(200).json({ message: "Starting session." });
}; };

View File

@ -35,7 +35,7 @@ const syncUnreadMessages = async (wbot: Session) => {
}); });
for (const msg of unreadMessages) { for (const msg of unreadMessages) {
console.log('--BACKEND MSG: ', msg) // console.log('--BACKEND MSG: ', msg)
await handleMessage(msg, wbot); await handleMessage(msg, wbot);
} }
@ -59,9 +59,15 @@ export const initWbot = async (whatsapp: Whatsapp, backupSessionRestore: boolean
//NOVA OPÇÃO MD //NOVA OPÇÃO MD
// const wbot: Session = new Client({
// session: sessionCfg, authStrategy: new LocalAuth({ clientId: 'bd_' + whatsapp.id }),
// puppeteer: { args: ['--no-sandbox', '--disable-setuid-sandbox'], executablePath: process.env.CHROME_BIN || undefined },
// });
// usando instancia do chrome
const wbot: Session = new Client({ const wbot: Session = new Client({
session: sessionCfg, authStrategy: new LocalAuth({ clientId: 'bd_' + whatsapp.id }), session: sessionCfg, authStrategy: new LocalAuth({ clientId: 'bd_' + whatsapp.id }),
puppeteer: { args: ['--no-sandbox', '--disable-setuid-sandbox'], executablePath: process.env.CHROME_BIN || undefined }, puppeteer: { args: ['--no-sandbox', '--disable-setuid-sandbox'], executablePath: process.env.CHROME_BIN || '/usr/bin/google-chrome-stable' },
}); });

View File

@ -28,7 +28,9 @@ const FindOrCreateTicketService = async (
const { queues, greetingMessage } = await ShowWhatsAppService(whatsappId); const { queues, greetingMessage } = await ShowWhatsAppService(whatsappId);
const botInfo = await BotIsOnQueue('botqueue') //Habilitar esse caso queira usar o bot
// const botInfo = await BotIsOnQueue('botqueue')
const botInfo = {isOnQueue: false}

View File

@ -18,11 +18,7 @@ const SendWhatsAppMedia = async ({
const newMedia = MessageMedia.fromFilePath(media.path); const newMedia = MessageMedia.fromFilePath(media.path);
const sentMessage = await wbot.sendMessage( const sentMessage = await wbot.sendMessage(`${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`, newMedia, { sendAudioAsVoice: true });
`${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`,
newMedia,
{ sendAudioAsVoice: true }
);
await ticket.update({ lastMessage: media.filename }); await ticket.update({ lastMessage: media.filename });

View File

@ -186,9 +186,9 @@ const verifyQueue = async (
let selectedOption = null; let selectedOption = null;
let choosenQueue = null let choosenQueue = null
//Habilitar esse caso queira usar o bot
const botInfo = await BotIsOnQueue('botqueue') // const botInfo = await BotIsOnQueue('botqueue')
const botInfo = {isOnQueue: false, botQueueId: 0, userIdBot: 0}
if (botInfo.isOnQueue) { if (botInfo.isOnQueue) {
@ -378,9 +378,19 @@ const handleMessage = async (
msgContact = await msg.getContact(); msgContact = await msg.getContact();
//console.log('-----msgContact TESTE MSG: ', msgContact, ' | msg.body: ', msg.body) // console.log('-----msgContact TESTE MSG2: ', msgContact, ' | msg: ', msg)
console.log('-----msgContact TESTE MSG2: ', msgContact, ' | msg: ', msg) console.log(`\n <<<<<<<<<< RECEIVING MESSAGE:
Parcial msg and msgContact info:
msgContact.name: ${msgContact.name}
msgContact.pushname: ${msgContact.pushname}
msgContact.shortName: ${msgContact.shortName}
msg.id.fromMe: ${msg.id.fromMe}
msg.id.id: ${msg.id.id}
msg.body: ${msg.body}
msg.type: ${msg.type}
msg.from: ${msg.from}
msg.to: ${msg.to}\n`)
} }
@ -449,7 +459,9 @@ const handleMessage = async (
// O bot interage com o cliente e encaminha o atendimento para fila de atendende quando o usuário escolhe a opção falar com atendente // O bot interage com o cliente e encaminha o atendimento para fila de atendende quando o usuário escolhe a opção falar com atendente
const botInfo = await BotIsOnQueue('botqueue') //Habilitar esse caso queira usar o bot
// const botInfo = await BotIsOnQueue('botqueue')
const botInfo = {isOnQueue: false, botQueueId: 0, userIdBot: 0}
if (botInfo.isOnQueue && !msg.fromMe && ticket.userId == botInfo.userIdBot) { if (botInfo.isOnQueue && !msg.fromMe && ticket.userId == botInfo.userIdBot) {
@ -755,32 +767,6 @@ const handleMessage = async (
// } // }
// console.log('>>>>>>>>>>>> whatsapp.status: ', whatsapp.status)
//
// test del
// console.log('WBOT.id: ',wbot.id)
// const sourcePath = path.join(__dirname,`../../../.wwebjs_auth/sessions/`, `session-bd_${wbot.id}`)
// const destPath = path.join(__dirname,`../../../.wwebjs_auth/`, `session-bd_${wbot.id}`)
// console.log('================sourcePath: ', sourcePath)
// console.log('================sourcePath: ', destPath)
// removeWbot(33)
// await removeDir(destPath)
// copyFolder(sourcePath, destPath)
// await StartWhatsAppSession(whatsapp);
// console.log('RESTARTING SESSION...')
//
} catch (err) { } catch (err) {
Sentry.captureException(err); Sentry.captureException(err);
logger.error(`Error handling whatsapp message: Err: ${err}`); logger.error(`Error handling whatsapp message: Err: ${err}`);

View File

@ -639,7 +639,7 @@ const Report = () => {
return { 'value': obj.id, 'label': obj.name } return { 'value': obj.id, 'label': obj.name }
})} /></Item> })} /></Item>
<Item><DatePicker1 func={datePicker1Value} minDate={false} startEmpty={false} title={'Data inicio'} /></Item> <Item><DatePicker1 func={datePicker1Value} minDate={true} startEmpty={false} title={'Data inicio'} /></Item>
<Item><DatePicker2 func={datePicker2Value} minDate={false} startEmpty={false} title={'Data fim'} /></Item> <Item><DatePicker2 func={datePicker2Value} minDate={false} startEmpty={false} title={'Data fim'} /></Item>
<Item sx={{ display: 'grid', gridColumn: '4 / 5', }}> <Item sx={{ display: 'grid', gridColumn: '4 / 5', }}>
@ -651,13 +651,13 @@ const Report = () => {
{reportOption === '1' && {reportOption === '1' &&
<div> <div>
<Button {/* <Button
variant="contained" variant="contained"
color="primary" color="primary"
onClick={(e) => handleCSVMessages()} onClick={(e) => handleCSVMessages()}
> >
{"CSV ALL"} {"CSV ALL"}
</Button> </Button> */}
<div> <div>
<CSVLink <CSVLink