FIX: correções encontradas na versão demo whatsapp-web.js
This commit is contained in:
parent
c681814cca
commit
a43c852573
@ -48,7 +48,7 @@ async function bootstrap() {
|
|||||||
|
|
||||||
const swaggerConfig = new DocumentBuilder()
|
const swaggerConfig = new DocumentBuilder()
|
||||||
.setTitle('Omnichannel Backend API')
|
.setTitle('Omnichannel Backend API')
|
||||||
.setDescription('Documentacao das rotas da API do Omnichannel Sothis.')
|
.setDescription('Documentacao das rotas da API do Sothis Connect.')
|
||||||
.setVersion('1.0.0')
|
.setVersion('1.0.0')
|
||||||
.addBearerAuth()
|
.addBearerAuth()
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@ -124,9 +124,11 @@ export class AttendanceAssignmentService {
|
|||||||
private readonly agentPresenceService: AgentPresenceService,
|
private readonly agentPresenceService: AgentPresenceService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async assignChat(chatId: string, userId: string | number, areaId?: string | number | null) {
|
async assignChat(chatId: string, userId: string | number, areaId?: string | number | null, skipPresenceCheck = false) {
|
||||||
this.logger.log(`Atribuindo chat ${chatId} ao usuario ${userId}`);
|
this.logger.log(`Atribuindo chat ${chatId} ao usuario ${userId}`);
|
||||||
await this.assertUserCanReceiveAssignment(Number(userId));
|
if (!skipPresenceCheck) {
|
||||||
|
await this.assertUserCanReceiveAssignment(Number(userId));
|
||||||
|
}
|
||||||
const result = await this.attendanceAssignmentRepository.assignChat(chatId, Number(userId), areaId ? Number(areaId) : null);
|
const result = await this.attendanceAssignmentRepository.assignChat(chatId, Number(userId), areaId ? Number(areaId) : null);
|
||||||
return this.enrichAssignment(result.rows[0]);
|
return this.enrichAssignment(result.rows[0]);
|
||||||
}
|
}
|
||||||
@ -996,7 +998,7 @@ export class AttendanceAssignmentService {
|
|||||||
if (!lastBotSentAt) return false;
|
if (!lastBotSentAt) return false;
|
||||||
|
|
||||||
const normalized = this.normalize(message).replace(/[!?.,\s]+/g, ' ').trim();
|
const normalized = this.normalize(message).replace(/[!?.,\s]+/g, ' ').trim();
|
||||||
const greetingOnlyMessages = ['oi', 'ola', 'olá', 'bom dia', 'boa tarde', 'boa noite'];
|
const greetingOnlyMessages = ['oi', 'ola', 'ol<EFBFBD>', 'bom dia', 'boa tarde', 'boa noite'];
|
||||||
if (!greetingOnlyMessages.includes(normalized)) return false;
|
if (!greetingOnlyMessages.includes(normalized)) return false;
|
||||||
|
|
||||||
const lastBotTime = new Date(lastBotSentAt).getTime();
|
const lastBotTime = new Date(lastBotSentAt).getTime();
|
||||||
|
|||||||
@ -77,8 +77,9 @@ export class AssignChatDto {
|
|||||||
userId: string;
|
userId: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@Type(() => Number)
|
||||||
areaId?: string;
|
@IsInt()
|
||||||
|
areaId?: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TransferChatDto {
|
export class TransferChatDto {
|
||||||
|
|||||||
@ -138,7 +138,7 @@ export class WhatsappController {
|
|||||||
})
|
})
|
||||||
@Post('assign')
|
@Post('assign')
|
||||||
async assignChat(@Body() body: AssignChatDto) {
|
async assignChat(@Body() body: AssignChatDto) {
|
||||||
return this.assignmentService.assignChat(body.chatId, body.userId, body.areaId);
|
return this.assignmentService.assignChat(body.chatId, body.userId, body.areaId, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
|
|||||||
@ -522,14 +522,23 @@ export class WhatsappService implements OnModuleInit {
|
|||||||
areaId?: number | null,
|
areaId?: number | null,
|
||||||
variables?: Record<string, string | null | undefined>,
|
variables?: Record<string, string | null | undefined>,
|
||||||
) {
|
) {
|
||||||
|
if (this.status !== 'CONNECTED') throw new Error('WhatsApp não está conectado');
|
||||||
|
|
||||||
|
const phone = to.replace(/@c\.us$/i, '');
|
||||||
|
const numberId = await this.client.getNumberId(phone).catch(() => null);
|
||||||
|
if (!numberId) {
|
||||||
|
throw new Error(`O número ${phone} não está registrado no WhatsApp.`);
|
||||||
|
}
|
||||||
|
const resolvedTo = numberId._serialized;
|
||||||
|
|
||||||
const template = await this.whatsappTemplateService.getTemplateById(templateId);
|
const template = await this.whatsappTemplateService.getTemplateById(templateId);
|
||||||
if (!template) {
|
if (!template) {
|
||||||
throw new Error('Template de WhatsApp nao encontrado');
|
throw new Error('Template de WhatsApp nao encontrado');
|
||||||
}
|
}
|
||||||
|
|
||||||
const renderedContent = this.renderTemplateContent(template.content, variables);
|
const renderedContent = this.renderTemplateContent(template.content, variables);
|
||||||
const sentMessage = await this.sendMessage(to, renderedContent);
|
const sentMessage = await this.sendMessage(resolvedTo, renderedContent);
|
||||||
const chatId = this.getSentMessageChatId(sentMessage, to);
|
const chatId = this.getSentMessageChatId(sentMessage, resolvedTo);
|
||||||
const assignment = await this.assignmentService.assignChat(chatId, userId, areaId || null);
|
const assignment = await this.assignmentService.assignChat(chatId, userId, areaId || null);
|
||||||
const lockedAssignment = await this.assignmentService.markAwaitingCustomerReply(chatId);
|
const lockedAssignment = await this.assignmentService.markAwaitingCustomerReply(chatId);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user