Compare commits
1 Commits
dev
...
v1.0.0-dem
| Author | SHA1 | Date | |
|---|---|---|---|
| dd23402238 |
@ -48,7 +48,7 @@ async function bootstrap() {
|
||||
|
||||
const swaggerConfig = new DocumentBuilder()
|
||||
.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')
|
||||
.addBearerAuth()
|
||||
.build();
|
||||
|
||||
@ -124,9 +124,11 @@ export class AttendanceAssignmentService {
|
||||
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}`);
|
||||
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);
|
||||
return this.enrichAssignment(result.rows[0]);
|
||||
}
|
||||
@ -996,7 +998,7 @@ export class AttendanceAssignmentService {
|
||||
if (!lastBotSentAt) return false;
|
||||
|
||||
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;
|
||||
|
||||
const lastBotTime = new Date(lastBotSentAt).getTime();
|
||||
|
||||
@ -77,8 +77,9 @@ export class AssignChatDto {
|
||||
userId: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
areaId?: string;
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
areaId?: number | null;
|
||||
}
|
||||
|
||||
export class TransferChatDto {
|
||||
|
||||
@ -138,7 +138,7 @@ export class WhatsappController {
|
||||
})
|
||||
@Post('assign')
|
||||
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({
|
||||
|
||||
@ -522,14 +522,23 @@ export class WhatsappService implements OnModuleInit {
|
||||
areaId?: number | null,
|
||||
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);
|
||||
if (!template) {
|
||||
throw new Error('Template de WhatsApp nao encontrado');
|
||||
}
|
||||
|
||||
const renderedContent = this.renderTemplateContent(template.content, variables);
|
||||
const sentMessage = await this.sendMessage(to, renderedContent);
|
||||
const chatId = this.getSentMessageChatId(sentMessage, to);
|
||||
const sentMessage = await this.sendMessage(resolvedTo, renderedContent);
|
||||
const chatId = this.getSentMessageChatId(sentMessage, resolvedTo);
|
||||
const assignment = await this.assignmentService.assignChat(chatId, userId, areaId || null);
|
||||
const lockedAssignment = await this.assignmentService.markAwaitingCustomerReply(chatId);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user