mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 12:12:55 -06:00
feat: Added debounce time for typebot messages
This commit is contained in:
parent
0bf8e55144
commit
2776f113cb
@ -123,7 +123,7 @@ CACHE_REDIS_ENABLED=true
|
|||||||
CACHE_REDIS_URI=redis://localhost:6379/6
|
CACHE_REDIS_URI=redis://localhost:6379/6
|
||||||
CACHE_REDIS_PREFIX_KEY=evolution
|
CACHE_REDIS_PREFIX_KEY=evolution
|
||||||
CACHE_REDIS_SAVE_INSTANCES=false
|
CACHE_REDIS_SAVE_INSTANCES=false
|
||||||
CACHE_LOCAL_ENABLED=true
|
CACHE_LOCAL_ENABLED=false
|
||||||
|
|
||||||
AUTHENTICATION_API_KEY=429683C4C977415CAAFCCE10F7D57E11
|
AUTHENTICATION_API_KEY=429683C4C977415CAAFCCE10F7D57E11
|
||||||
AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true
|
AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Typebot" ADD COLUMN "debounceTime" INTEGER;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "TypebotSetting" ADD COLUMN "debounceTime" INTEGER;
|
@ -262,6 +262,7 @@ model Typebot {
|
|||||||
listeningFromMe Boolean? @default(false)
|
listeningFromMe Boolean? @default(false)
|
||||||
stopBotFromMe Boolean? @default(false)
|
stopBotFromMe Boolean? @default(false)
|
||||||
keepOpen Boolean? @default(false)
|
keepOpen Boolean? @default(false)
|
||||||
|
debounceTime Int? @db.Int
|
||||||
createdAt DateTime? @default(now()) @db.Date
|
createdAt DateTime? @default(now()) @db.Date
|
||||||
updatedAt DateTime? @updatedAt @db.Date
|
updatedAt DateTime? @updatedAt @db.Date
|
||||||
triggerType TriggerType?
|
triggerType TriggerType?
|
||||||
@ -279,6 +280,7 @@ model TypebotSession {
|
|||||||
sessionId String @db.VarChar(100)
|
sessionId String @db.VarChar(100)
|
||||||
status String @db.VarChar(100)
|
status String @db.VarChar(100)
|
||||||
prefilledVariables Json? @db.Json
|
prefilledVariables Json? @db.Json
|
||||||
|
debounceTime Int? @db.Int
|
||||||
createdAt DateTime? @default(now()) @db.Date
|
createdAt DateTime? @default(now()) @db.Date
|
||||||
updatedAt DateTime @updatedAt @db.Date
|
updatedAt DateTime @updatedAt @db.Date
|
||||||
Typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade)
|
Typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade)
|
||||||
|
@ -261,6 +261,7 @@ model Typebot {
|
|||||||
listeningFromMe Boolean? @default(false) @db.Boolean
|
listeningFromMe Boolean? @default(false) @db.Boolean
|
||||||
stopBotFromMe Boolean? @default(false) @db.Boolean
|
stopBotFromMe Boolean? @default(false) @db.Boolean
|
||||||
keepOpen Boolean? @default(false) @db.Boolean
|
keepOpen Boolean? @default(false) @db.Boolean
|
||||||
|
debounceTime Int? @db.Integer
|
||||||
createdAt DateTime? @default(now()) @db.Timestamp
|
createdAt DateTime? @default(now()) @db.Timestamp
|
||||||
updatedAt DateTime? @updatedAt @db.Timestamp
|
updatedAt DateTime? @updatedAt @db.Timestamp
|
||||||
triggerType TriggerType?
|
triggerType TriggerType?
|
||||||
@ -297,6 +298,7 @@ model TypebotSetting {
|
|||||||
listeningFromMe Boolean? @default(false) @db.Boolean
|
listeningFromMe Boolean? @default(false) @db.Boolean
|
||||||
stopBotFromMe Boolean? @default(false) @db.Boolean
|
stopBotFromMe Boolean? @default(false) @db.Boolean
|
||||||
keepOpen Boolean? @default(false) @db.Boolean
|
keepOpen Boolean? @default(false) @db.Boolean
|
||||||
|
debounceTime Int? @db.Integer
|
||||||
createdAt DateTime? @default(now()) @db.Timestamp
|
createdAt DateTime? @default(now()) @db.Timestamp
|
||||||
updatedAt DateTime @updatedAt @db.Timestamp
|
updatedAt DateTime @updatedAt @db.Timestamp
|
||||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||||
|
@ -7,7 +7,6 @@ import { v4 } from 'uuid';
|
|||||||
import { Auth, Chatwoot, ConfigService, HttpServer, WaBusiness } from '../../config/env.config';
|
import { Auth, Chatwoot, ConfigService, HttpServer, WaBusiness } from '../../config/env.config';
|
||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
import { BadRequestException, InternalServerErrorException, UnauthorizedException } from '../../exceptions';
|
import { BadRequestException, InternalServerErrorException, UnauthorizedException } from '../../exceptions';
|
||||||
import { Events as EventsArray } from '../../validate/validate.schema';
|
|
||||||
import { InstanceDto, SetPresenceDto } from '../dto/instance.dto';
|
import { InstanceDto, SetPresenceDto } from '../dto/instance.dto';
|
||||||
import { ChatwootService } from '../integrations/chatwoot/services/chatwoot.service';
|
import { ChatwootService } from '../integrations/chatwoot/services/chatwoot.service';
|
||||||
import { RabbitmqService } from '../integrations/rabbitmq/services/rabbitmq.service';
|
import { RabbitmqService } from '../integrations/rabbitmq/services/rabbitmq.service';
|
||||||
@ -154,7 +153,33 @@ export class InstanceController {
|
|||||||
try {
|
try {
|
||||||
let newEvents: string[] = [];
|
let newEvents: string[] = [];
|
||||||
if (webhookEvents.length === 0) {
|
if (webhookEvents.length === 0) {
|
||||||
newEvents = EventsArray;
|
newEvents = [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
];
|
||||||
} else {
|
} else {
|
||||||
newEvents = webhookEvents;
|
newEvents = webhookEvents;
|
||||||
}
|
}
|
||||||
@ -180,7 +205,33 @@ export class InstanceController {
|
|||||||
try {
|
try {
|
||||||
let newEvents: string[] = [];
|
let newEvents: string[] = [];
|
||||||
if (websocketEvents.length === 0) {
|
if (websocketEvents.length === 0) {
|
||||||
newEvents = EventsArray;
|
newEvents = [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
];
|
||||||
} else {
|
} else {
|
||||||
newEvents = websocketEvents;
|
newEvents = websocketEvents;
|
||||||
}
|
}
|
||||||
@ -205,7 +256,33 @@ export class InstanceController {
|
|||||||
try {
|
try {
|
||||||
let newEvents: string[] = [];
|
let newEvents: string[] = [];
|
||||||
if (rabbitmqEvents.length === 0) {
|
if (rabbitmqEvents.length === 0) {
|
||||||
newEvents = EventsArray;
|
newEvents = [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
];
|
||||||
} else {
|
} else {
|
||||||
newEvents = rabbitmqEvents;
|
newEvents = rabbitmqEvents;
|
||||||
}
|
}
|
||||||
@ -228,7 +305,33 @@ export class InstanceController {
|
|||||||
try {
|
try {
|
||||||
let newEvents: string[] = [];
|
let newEvents: string[] = [];
|
||||||
if (sqsEvents.length === 0) {
|
if (sqsEvents.length === 0) {
|
||||||
newEvents = EventsArray;
|
newEvents = [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
];
|
||||||
} else {
|
} else {
|
||||||
newEvents = sqsEvents;
|
newEvents = sqsEvents;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { isURL } from 'class-validator';
|
import { isURL } from 'class-validator';
|
||||||
|
|
||||||
import { BadRequestException } from '../../exceptions';
|
import { BadRequestException } from '../../exceptions';
|
||||||
import { Events } from '../../validate/validate.schema';
|
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
import { WebhookDto } from '../dto/webhook.dto';
|
import { WebhookDto } from '../dto/webhook.dto';
|
||||||
import { WAMonitoringService } from '../services/monitor.service';
|
import { WAMonitoringService } from '../services/monitor.service';
|
||||||
@ -21,7 +20,33 @@ export class WebhookController {
|
|||||||
data.url = '';
|
data.url = '';
|
||||||
data.events = [];
|
data.events = [];
|
||||||
} else if (data.events.length === 0) {
|
} else if (data.events.length === 0) {
|
||||||
data.events = Events;
|
data.events = [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.webhookService.create(instance, data);
|
return this.webhookService.create(instance, data);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { configService, Rabbitmq } from '../../../../config/env.config';
|
import { configService, Rabbitmq } from '../../../../config/env.config';
|
||||||
import { BadRequestException } from '../../../../exceptions';
|
import { BadRequestException } from '../../../../exceptions';
|
||||||
import { Events } from '../../../../validate/validate.schema';
|
|
||||||
import { InstanceDto } from '../../../dto/instance.dto';
|
import { InstanceDto } from '../../../dto/instance.dto';
|
||||||
import { RabbitmqDto } from '../dto/rabbitmq.dto';
|
import { RabbitmqDto } from '../dto/rabbitmq.dto';
|
||||||
import { RabbitmqService } from '../services/rabbitmq.service';
|
import { RabbitmqService } from '../services/rabbitmq.service';
|
||||||
@ -16,7 +15,33 @@ export class RabbitmqController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.events.length === 0) {
|
if (data.events.length === 0) {
|
||||||
data.events = Events;
|
data.events = [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.rabbitmqService.create(instance, data);
|
return this.rabbitmqService.create(instance, data);
|
||||||
|
@ -12,6 +12,7 @@ export class RabbitmqRouter extends RouterBroker {
|
|||||||
super();
|
super();
|
||||||
this.router
|
this.router
|
||||||
.post(this.routerPath('set'), ...guards, async (req, res) => {
|
.post(this.routerPath('set'), ...guards, async (req, res) => {
|
||||||
|
console.log('RabbitmqRouter -> constructor -> req', req.body);
|
||||||
const response = await this.dataValidate<RabbitmqDto>({
|
const response = await this.dataValidate<RabbitmqDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: rabbitmqSchema,
|
schema: rabbitmqSchema,
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import { JSONSchema7 } from 'json-schema';
|
import { JSONSchema7 } from 'json-schema';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
import { Events } from '../../../../validate/validate.schema';
|
|
||||||
|
|
||||||
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
||||||
const properties = {};
|
const properties = {};
|
||||||
propertyNames.forEach(
|
propertyNames.forEach(
|
||||||
@ -32,7 +30,33 @@ export const rabbitmqSchema: JSONSchema7 = {
|
|||||||
minItems: 0,
|
minItems: 0,
|
||||||
items: {
|
items: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: Events,
|
enum: [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { configService, Sqs } from '../../../../config/env.config';
|
import { configService, Sqs } from '../../../../config/env.config';
|
||||||
import { BadRequestException } from '../../../../exceptions';
|
import { BadRequestException } from '../../../../exceptions';
|
||||||
import { Events } from '../../../../validate/validate.schema';
|
|
||||||
import { InstanceDto } from '../../../dto/instance.dto';
|
import { InstanceDto } from '../../../dto/instance.dto';
|
||||||
import { SqsDto } from '../dto/sqs.dto';
|
import { SqsDto } from '../dto/sqs.dto';
|
||||||
import { SqsService } from '../services/sqs.service';
|
import { SqsService } from '../services/sqs.service';
|
||||||
@ -16,7 +15,33 @@ export class SqsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.events.length === 0) {
|
if (data.events.length === 0) {
|
||||||
data.events = Events;
|
data.events = [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.sqsService.create(instance, data);
|
return this.sqsService.create(instance, data);
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import { JSONSchema7 } from 'json-schema';
|
import { JSONSchema7 } from 'json-schema';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
import { Events } from '../../../../validate/validate.schema';
|
|
||||||
|
|
||||||
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
||||||
const properties = {};
|
const properties = {};
|
||||||
propertyNames.forEach(
|
propertyNames.forEach(
|
||||||
@ -32,7 +30,33 @@ export const sqsSchema: JSONSchema7 = {
|
|||||||
minItems: 0,
|
minItems: 0,
|
||||||
items: {
|
items: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: Events,
|
enum: [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -27,6 +27,7 @@ export class TypebotDto {
|
|||||||
listeningFromMe?: boolean;
|
listeningFromMe?: boolean;
|
||||||
stopBotFromMe?: boolean;
|
stopBotFromMe?: boolean;
|
||||||
keepOpen?: boolean;
|
keepOpen?: boolean;
|
||||||
|
debounceTime?: number;
|
||||||
triggerType?: TriggerType;
|
triggerType?: TriggerType;
|
||||||
triggerOperator?: TriggerOperator;
|
triggerOperator?: TriggerOperator;
|
||||||
triggerValue?: string;
|
triggerValue?: string;
|
||||||
@ -40,4 +41,5 @@ export class TypebotSettingDto {
|
|||||||
listeningFromMe?: boolean;
|
listeningFromMe?: boolean;
|
||||||
stopBotFromMe?: boolean;
|
stopBotFromMe?: boolean;
|
||||||
keepOpen?: boolean;
|
keepOpen?: boolean;
|
||||||
|
debounceTime?: number;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Message, TypebotSession } from '@prisma/client';
|
import { Message, Typebot as TypebotModel, TypebotSession } from '@prisma/client';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
import { ConfigService, Typebot } from '../../../../config/env.config';
|
import { ConfigService, Typebot } from '../../../../config/env.config';
|
||||||
@ -16,6 +16,8 @@ export class TypebotService {
|
|||||||
private readonly prismaRepository: PrismaRepository,
|
private readonly prismaRepository: PrismaRepository,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
private userMessageDebounce: { [key: string]: { message: string; timeoutId: NodeJS.Timeout } } = {};
|
||||||
|
|
||||||
private readonly logger = new Logger(TypebotService.name);
|
private readonly logger = new Logger(TypebotService.name);
|
||||||
|
|
||||||
public async create(instance: InstanceDto, data: TypebotDto) {
|
public async create(instance: InstanceDto, data: TypebotDto) {
|
||||||
@ -34,7 +36,8 @@ export class TypebotService {
|
|||||||
!data.unknownMessage ||
|
!data.unknownMessage ||
|
||||||
!data.listeningFromMe ||
|
!data.listeningFromMe ||
|
||||||
!data.stopBotFromMe ||
|
!data.stopBotFromMe ||
|
||||||
!data.keepOpen
|
!data.keepOpen ||
|
||||||
|
!data.debounceTime
|
||||||
) {
|
) {
|
||||||
const defaultSettingCheck = await this.prismaRepository.typebotSetting.findFirst({
|
const defaultSettingCheck = await this.prismaRepository.typebotSetting.findFirst({
|
||||||
where: {
|
where: {
|
||||||
@ -53,6 +56,7 @@ export class TypebotService {
|
|||||||
if (!data.listeningFromMe) data.listeningFromMe = defaultSettingCheck.listeningFromMe;
|
if (!data.listeningFromMe) data.listeningFromMe = defaultSettingCheck.listeningFromMe;
|
||||||
if (!data.stopBotFromMe) data.stopBotFromMe = defaultSettingCheck.stopBotFromMe;
|
if (!data.stopBotFromMe) data.stopBotFromMe = defaultSettingCheck.stopBotFromMe;
|
||||||
if (!data.keepOpen) data.keepOpen = defaultSettingCheck.keepOpen;
|
if (!data.keepOpen) data.keepOpen = defaultSettingCheck.keepOpen;
|
||||||
|
if (!data.debounceTime) data.debounceTime = defaultSettingCheck.debounceTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkTriggerAll = await this.prismaRepository.typebot.findFirst({
|
const checkTriggerAll = await this.prismaRepository.typebot.findFirst({
|
||||||
@ -106,6 +110,8 @@ export class TypebotService {
|
|||||||
unknownMessage: data.unknownMessage,
|
unknownMessage: data.unknownMessage,
|
||||||
listeningFromMe: data.listeningFromMe,
|
listeningFromMe: data.listeningFromMe,
|
||||||
stopBotFromMe: data.stopBotFromMe,
|
stopBotFromMe: data.stopBotFromMe,
|
||||||
|
keepOpen: data.keepOpen,
|
||||||
|
debounceTime: data.debounceTime,
|
||||||
instanceId: instanceId,
|
instanceId: instanceId,
|
||||||
triggerType: data.triggerType,
|
triggerType: data.triggerType,
|
||||||
triggerOperator: data.triggerOperator,
|
triggerOperator: data.triggerOperator,
|
||||||
@ -238,6 +244,8 @@ export class TypebotService {
|
|||||||
unknownMessage: data.unknownMessage,
|
unknownMessage: data.unknownMessage,
|
||||||
listeningFromMe: data.listeningFromMe,
|
listeningFromMe: data.listeningFromMe,
|
||||||
stopBotFromMe: data.stopBotFromMe,
|
stopBotFromMe: data.stopBotFromMe,
|
||||||
|
keepOpen: data.keepOpen,
|
||||||
|
debounceTime: data.debounceTime,
|
||||||
triggerType: data.triggerType,
|
triggerType: data.triggerType,
|
||||||
triggerOperator: data.triggerOperator,
|
triggerOperator: data.triggerOperator,
|
||||||
triggerValue: data.triggerValue,
|
triggerValue: data.triggerValue,
|
||||||
@ -349,6 +357,7 @@ export class TypebotService {
|
|||||||
listeningFromMe: data.listeningFromMe,
|
listeningFromMe: data.listeningFromMe,
|
||||||
stopBotFromMe: data.stopBotFromMe,
|
stopBotFromMe: data.stopBotFromMe,
|
||||||
keepOpen: data.keepOpen,
|
keepOpen: data.keepOpen,
|
||||||
|
debounceTime: data.debounceTime,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -360,6 +369,7 @@ export class TypebotService {
|
|||||||
listeningFromMe: updateSettings.listeningFromMe,
|
listeningFromMe: updateSettings.listeningFromMe,
|
||||||
stopBotFromMe: updateSettings.stopBotFromMe,
|
stopBotFromMe: updateSettings.stopBotFromMe,
|
||||||
keepOpen: updateSettings.keepOpen,
|
keepOpen: updateSettings.keepOpen,
|
||||||
|
debounceTime: updateSettings.debounceTime,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,6 +382,7 @@ export class TypebotService {
|
|||||||
listeningFromMe: data.listeningFromMe,
|
listeningFromMe: data.listeningFromMe,
|
||||||
stopBotFromMe: data.stopBotFromMe,
|
stopBotFromMe: data.stopBotFromMe,
|
||||||
keepOpen: data.keepOpen,
|
keepOpen: data.keepOpen,
|
||||||
|
debounceTime: data.debounceTime,
|
||||||
instanceId: instanceId,
|
instanceId: instanceId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -384,6 +395,7 @@ export class TypebotService {
|
|||||||
listeningFromMe: newSetttings.listeningFromMe,
|
listeningFromMe: newSetttings.listeningFromMe,
|
||||||
stopBotFromMe: newSetttings.stopBotFromMe,
|
stopBotFromMe: newSetttings.stopBotFromMe,
|
||||||
keepOpen: newSetttings.keepOpen,
|
keepOpen: newSetttings.keepOpen,
|
||||||
|
debounceTime: newSetttings.debounceTime,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error);
|
this.logger.error(error);
|
||||||
@ -1119,9 +1131,30 @@ export class TypebotService {
|
|||||||
return typebot;
|
return typebot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private processDebounce(content: string, remoteJid: string, debounceTime: number, callback: any) {
|
||||||
|
if (this.userMessageDebounce[remoteJid]) {
|
||||||
|
this.userMessageDebounce[remoteJid].message += ` ${content}`;
|
||||||
|
this.logger.log('message debounced: ' + this.userMessageDebounce[remoteJid].message);
|
||||||
|
clearTimeout(this.userMessageDebounce[remoteJid].timeoutId);
|
||||||
|
} else {
|
||||||
|
this.userMessageDebounce[remoteJid] = {
|
||||||
|
message: content,
|
||||||
|
timeoutId: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
this.userMessageDebounce[remoteJid].timeoutId = setTimeout(() => {
|
||||||
|
const myQuestion = this.userMessageDebounce[remoteJid].message;
|
||||||
|
this.logger.log('Debounce complete. Processing message: ' + myQuestion);
|
||||||
|
|
||||||
|
delete this.userMessageDebounce[remoteJid];
|
||||||
|
callback(myQuestion);
|
||||||
|
}, debounceTime * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
public async sendTypebot(instance: InstanceDto, remoteJid: string, msg: Message) {
|
public async sendTypebot(instance: InstanceDto, remoteJid: string, msg: Message) {
|
||||||
try {
|
try {
|
||||||
let session = await this.prismaRepository.typebotSession.findFirst({
|
const session = await this.prismaRepository.typebotSession.findFirst({
|
||||||
where: {
|
where: {
|
||||||
remoteJid: remoteJid,
|
remoteJid: remoteJid,
|
||||||
},
|
},
|
||||||
@ -1154,6 +1187,7 @@ export class TypebotService {
|
|||||||
let listeningFromMe = findTypebot?.listeningFromMe;
|
let listeningFromMe = findTypebot?.listeningFromMe;
|
||||||
let stopBotFromMe = findTypebot?.stopBotFromMe;
|
let stopBotFromMe = findTypebot?.stopBotFromMe;
|
||||||
let keepOpen = findTypebot?.keepOpen;
|
let keepOpen = findTypebot?.keepOpen;
|
||||||
|
let debounceTime = findTypebot?.debounceTime;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!expire ||
|
!expire ||
|
||||||
@ -1183,6 +1217,8 @@ export class TypebotService {
|
|||||||
if (!stopBotFromMe) stopBotFromMe = settings.stopBotFromMe;
|
if (!stopBotFromMe) stopBotFromMe = settings.stopBotFromMe;
|
||||||
|
|
||||||
if (!keepOpen) keepOpen = settings.keepOpen;
|
if (!keepOpen) keepOpen = settings.keepOpen;
|
||||||
|
|
||||||
|
if (!debounceTime) debounceTime = settings.debounceTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
const key = msg.key as {
|
const key = msg.key as {
|
||||||
@ -1206,141 +1242,107 @@ export class TypebotService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session && !session.awaitUser) return;
|
if (debounceTime && debounceTime > 0) {
|
||||||
|
this.processDebounce(content, remoteJid, debounceTime, async (debouncedContent) => {
|
||||||
if (session && expire && expire > 0) {
|
await this.processTypebot(
|
||||||
const now = Date.now();
|
|
||||||
|
|
||||||
const sessionUpdatedAt = new Date(session.updatedAt).getTime();
|
|
||||||
|
|
||||||
const diff = now - sessionUpdatedAt;
|
|
||||||
|
|
||||||
const diffInMinutes = Math.floor(diff / 1000 / 60);
|
|
||||||
|
|
||||||
if (diffInMinutes > expire) {
|
|
||||||
await this.prismaRepository.typebotSession.deleteMany({
|
|
||||||
where: {
|
|
||||||
typebotId: findTypebot.id,
|
|
||||||
remoteJid: remoteJid,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const data = await this.createNewSession(instance, {
|
|
||||||
enabled: findTypebot.enabled,
|
|
||||||
url: url,
|
|
||||||
typebot: typebot,
|
|
||||||
expire: expire,
|
|
||||||
keywordFinish: keywordFinish,
|
|
||||||
delayMessage: delayMessage,
|
|
||||||
unknownMessage: unknownMessage,
|
|
||||||
listeningFromMe: listeningFromMe,
|
|
||||||
remoteJid: remoteJid,
|
|
||||||
pushName: msg.pushName,
|
|
||||||
typebotId: findTypebot.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (data.session) {
|
|
||||||
session = data.session;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.sendWAMessage(
|
|
||||||
instance,
|
instance,
|
||||||
session,
|
|
||||||
{
|
|
||||||
expire: expire,
|
|
||||||
keywordFinish: keywordFinish,
|
|
||||||
delayMessage: delayMessage,
|
|
||||||
unknownMessage: unknownMessage,
|
|
||||||
listeningFromMe: listeningFromMe,
|
|
||||||
stopBotFromMe: stopBotFromMe,
|
|
||||||
keepOpen: keepOpen,
|
|
||||||
},
|
|
||||||
remoteJid,
|
remoteJid,
|
||||||
data.messages,
|
msg,
|
||||||
data.input,
|
session,
|
||||||
data.clientSideActions,
|
findTypebot,
|
||||||
|
url,
|
||||||
|
expire,
|
||||||
|
typebot,
|
||||||
|
keywordFinish,
|
||||||
|
delayMessage,
|
||||||
|
unknownMessage,
|
||||||
|
listeningFromMe,
|
||||||
|
stopBotFromMe,
|
||||||
|
keepOpen,
|
||||||
|
debouncedContent,
|
||||||
);
|
);
|
||||||
|
});
|
||||||
if (data.messages.length === 0) {
|
} else {
|
||||||
const content = this.getConversationMessage(msg.message);
|
await this.processTypebot(
|
||||||
|
instance,
|
||||||
if (!content) {
|
remoteJid,
|
||||||
if (unknownMessage) {
|
msg,
|
||||||
this.waMonitor.waInstances[instance.instanceName].textMessage(
|
session,
|
||||||
{
|
findTypebot,
|
||||||
number: remoteJid.split('@')[0],
|
url,
|
||||||
delay: delayMessage || 1000,
|
expire,
|
||||||
text: unknownMessage,
|
typebot,
|
||||||
},
|
keywordFinish,
|
||||||
true,
|
delayMessage,
|
||||||
);
|
unknownMessage,
|
||||||
}
|
listeningFromMe,
|
||||||
return;
|
stopBotFromMe,
|
||||||
}
|
keepOpen,
|
||||||
|
content,
|
||||||
if (keywordFinish && content.toLowerCase() === keywordFinish.toLowerCase()) {
|
);
|
||||||
await this.prismaRepository.typebotSession.deleteMany({
|
|
||||||
where: {
|
|
||||||
typebotId: findTypebot.id,
|
|
||||||
remoteJid: remoteJid,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const version = this.configService.get<Typebot>('TYPEBOT').API_VERSION;
|
|
||||||
let urlTypebot: string;
|
|
||||||
let reqData: {};
|
|
||||||
if (version === 'latest') {
|
|
||||||
urlTypebot = `${url}/api/v1/sessions/${data.sessionId}/continueChat`;
|
|
||||||
reqData = {
|
|
||||||
message: content,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
urlTypebot = `${url}/api/v1/sendMessage`;
|
|
||||||
reqData = {
|
|
||||||
message: content,
|
|
||||||
sessionId: data.sessionId,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const request = await axios.post(urlTypebot, reqData);
|
|
||||||
|
|
||||||
await this.sendWAMessage(
|
|
||||||
instance,
|
|
||||||
session,
|
|
||||||
{
|
|
||||||
expire: expire,
|
|
||||||
keywordFinish: keywordFinish,
|
|
||||||
delayMessage: delayMessage,
|
|
||||||
unknownMessage: unknownMessage,
|
|
||||||
listeningFromMe: listeningFromMe,
|
|
||||||
stopBotFromMe: stopBotFromMe,
|
|
||||||
keepOpen: keepOpen,
|
|
||||||
},
|
|
||||||
remoteJid,
|
|
||||||
request.data.messages,
|
|
||||||
request.data.input,
|
|
||||||
request.data.clientSideActions,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session && session.status !== 'opened') {
|
// await this.processTypebot(
|
||||||
return;
|
// instance,
|
||||||
}
|
// remoteJid,
|
||||||
|
// msg,
|
||||||
|
// session,
|
||||||
|
// findTypebot,
|
||||||
|
// url,
|
||||||
|
// expire,
|
||||||
|
// typebot,
|
||||||
|
// keywordFinish,
|
||||||
|
// delayMessage,
|
||||||
|
// unknownMessage,
|
||||||
|
// listeningFromMe,
|
||||||
|
// stopBotFromMe,
|
||||||
|
// keepOpen,
|
||||||
|
// content,
|
||||||
|
// );
|
||||||
|
|
||||||
|
if (session && !session.awaitUser) return;
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async processTypebot(
|
||||||
|
instance: InstanceDto,
|
||||||
|
remoteJid: string,
|
||||||
|
msg: Message,
|
||||||
|
session: TypebotSession,
|
||||||
|
findTypebot: TypebotModel,
|
||||||
|
url: string,
|
||||||
|
expire: number,
|
||||||
|
typebot: string,
|
||||||
|
keywordFinish: string,
|
||||||
|
delayMessage: number,
|
||||||
|
unknownMessage: string,
|
||||||
|
listeningFromMe: boolean,
|
||||||
|
stopBotFromMe: boolean,
|
||||||
|
keepOpen: boolean,
|
||||||
|
content: string,
|
||||||
|
) {
|
||||||
|
if (session && expire && expire > 0) {
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
const sessionUpdatedAt = new Date(session.updatedAt).getTime();
|
||||||
|
|
||||||
|
const diff = now - sessionUpdatedAt;
|
||||||
|
|
||||||
|
const diffInMinutes = Math.floor(diff / 1000 / 60);
|
||||||
|
|
||||||
|
if (diffInMinutes > expire) {
|
||||||
|
await this.prismaRepository.typebotSession.deleteMany({
|
||||||
|
where: {
|
||||||
|
typebotId: findTypebot.id,
|
||||||
|
remoteJid: remoteJid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (!session) {
|
|
||||||
const data = await this.createNewSession(instance, {
|
const data = await this.createNewSession(instance, {
|
||||||
enabled: findTypebot?.enabled,
|
enabled: findTypebot.enabled,
|
||||||
url: url,
|
url: url,
|
||||||
typebot: typebot,
|
typebot: typebot,
|
||||||
expire: expire,
|
expire: expire,
|
||||||
@ -1370,12 +1372,14 @@ export class TypebotService {
|
|||||||
keepOpen: keepOpen,
|
keepOpen: keepOpen,
|
||||||
},
|
},
|
||||||
remoteJid,
|
remoteJid,
|
||||||
data?.messages,
|
data.messages,
|
||||||
data?.input,
|
data.input,
|
||||||
data?.clientSideActions,
|
data.clientSideActions,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (data.messages.length === 0) {
|
if (data.messages.length === 0) {
|
||||||
|
const content = this.getConversationMessage(msg.message);
|
||||||
|
|
||||||
if (!content) {
|
if (!content) {
|
||||||
if (unknownMessage) {
|
if (unknownMessage) {
|
||||||
this.waMonitor.waInstances[instance.instanceName].textMessage(
|
this.waMonitor.waInstances[instance.instanceName].textMessage(
|
||||||
@ -1397,11 +1401,9 @@ export class TypebotService {
|
|||||||
remoteJid: remoteJid,
|
remoteJid: remoteJid,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let request: any;
|
|
||||||
try {
|
try {
|
||||||
const version = this.configService.get<Typebot>('TYPEBOT').API_VERSION;
|
const version = this.configService.get<Typebot>('TYPEBOT').API_VERSION;
|
||||||
let urlTypebot: string;
|
let urlTypebot: string;
|
||||||
@ -1418,7 +1420,8 @@ export class TypebotService {
|
|||||||
sessionId: data.sessionId,
|
sessionId: data.sessionId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
request = await axios.post(urlTypebot, reqData);
|
|
||||||
|
const request = await axios.post(urlTypebot, reqData);
|
||||||
|
|
||||||
await this.sendWAMessage(
|
await this.sendWAMessage(
|
||||||
instance,
|
instance,
|
||||||
@ -1442,60 +1445,34 @@ export class TypebotService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await this.prismaRepository.typebotSession.update({
|
if (session && session.status !== 'opened') {
|
||||||
where: {
|
return;
|
||||||
id: session.id,
|
}
|
||||||
},
|
|
||||||
data: {
|
if (!session) {
|
||||||
status: 'opened',
|
const data = await this.createNewSession(instance, {
|
||||||
awaitUser: false,
|
enabled: findTypebot?.enabled,
|
||||||
},
|
url: url,
|
||||||
|
typebot: typebot,
|
||||||
|
expire: expire,
|
||||||
|
keywordFinish: keywordFinish,
|
||||||
|
delayMessage: delayMessage,
|
||||||
|
unknownMessage: unknownMessage,
|
||||||
|
listeningFromMe: listeningFromMe,
|
||||||
|
remoteJid: remoteJid,
|
||||||
|
pushName: msg.pushName,
|
||||||
|
typebotId: findTypebot.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!content) {
|
if (data.session) {
|
||||||
if (unknownMessage) {
|
session = data.session;
|
||||||
this.waMonitor.waInstances[instance.instanceName].textMessage(
|
|
||||||
{
|
|
||||||
number: remoteJid.split('@')[0],
|
|
||||||
delay: delayMessage || 1000,
|
|
||||||
text: unknownMessage,
|
|
||||||
},
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keywordFinish && content.toLowerCase() === keywordFinish.toLowerCase()) {
|
|
||||||
await this.prismaRepository.typebotSession.deleteMany({
|
|
||||||
where: {
|
|
||||||
typebotId: findTypebot.id,
|
|
||||||
remoteJid: remoteJid,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const version = this.configService.get<Typebot>('TYPEBOT').API_VERSION;
|
|
||||||
let urlTypebot: string;
|
|
||||||
let reqData: {};
|
|
||||||
if (version === 'latest') {
|
|
||||||
urlTypebot = `${url}/api/v1/sessions/${session.sessionId.split('-')[1]}/continueChat`;
|
|
||||||
reqData = {
|
|
||||||
message: content,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
urlTypebot = `${url}/api/v1/sendMessage`;
|
|
||||||
reqData = {
|
|
||||||
message: content,
|
|
||||||
sessionId: session.sessionId.split('-')[1],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const request = await axios.post(urlTypebot, reqData);
|
|
||||||
|
|
||||||
await this.sendWAMessage(
|
await this.sendWAMessage(
|
||||||
instance,
|
instance,
|
||||||
session,
|
session,
|
||||||
@ -1509,15 +1486,150 @@ export class TypebotService {
|
|||||||
keepOpen: keepOpen,
|
keepOpen: keepOpen,
|
||||||
},
|
},
|
||||||
remoteJid,
|
remoteJid,
|
||||||
request?.data?.messages,
|
data?.messages,
|
||||||
request?.data?.input,
|
data?.input,
|
||||||
request?.data?.clientSideActions,
|
data?.clientSideActions,
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
if (data.messages.length === 0) {
|
||||||
} catch (error) {
|
if (!content) {
|
||||||
this.logger.error(error);
|
if (unknownMessage) {
|
||||||
|
this.waMonitor.waInstances[instance.instanceName].textMessage(
|
||||||
|
{
|
||||||
|
number: remoteJid.split('@')[0],
|
||||||
|
delay: delayMessage || 1000,
|
||||||
|
text: unknownMessage,
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keywordFinish && content.toLowerCase() === keywordFinish.toLowerCase()) {
|
||||||
|
await this.prismaRepository.typebotSession.deleteMany({
|
||||||
|
where: {
|
||||||
|
typebotId: findTypebot.id,
|
||||||
|
remoteJid: remoteJid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let request: any;
|
||||||
|
try {
|
||||||
|
const version = this.configService.get<Typebot>('TYPEBOT').API_VERSION;
|
||||||
|
let urlTypebot: string;
|
||||||
|
let reqData: {};
|
||||||
|
if (version === 'latest') {
|
||||||
|
urlTypebot = `${url}/api/v1/sessions/${data.sessionId}/continueChat`;
|
||||||
|
reqData = {
|
||||||
|
message: content,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
urlTypebot = `${url}/api/v1/sendMessage`;
|
||||||
|
reqData = {
|
||||||
|
message: content,
|
||||||
|
sessionId: data.sessionId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
request = await axios.post(urlTypebot, reqData);
|
||||||
|
|
||||||
|
await this.sendWAMessage(
|
||||||
|
instance,
|
||||||
|
session,
|
||||||
|
{
|
||||||
|
expire: expire,
|
||||||
|
keywordFinish: keywordFinish,
|
||||||
|
delayMessage: delayMessage,
|
||||||
|
unknownMessage: unknownMessage,
|
||||||
|
listeningFromMe: listeningFromMe,
|
||||||
|
stopBotFromMe: stopBotFromMe,
|
||||||
|
keepOpen: keepOpen,
|
||||||
|
},
|
||||||
|
remoteJid,
|
||||||
|
request.data.messages,
|
||||||
|
request.data.input,
|
||||||
|
request.data.clientSideActions,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.prismaRepository.typebotSession.update({
|
||||||
|
where: {
|
||||||
|
id: session.id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
status: 'opened',
|
||||||
|
awaitUser: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!content) {
|
||||||
|
if (unknownMessage) {
|
||||||
|
this.waMonitor.waInstances[instance.instanceName].textMessage(
|
||||||
|
{
|
||||||
|
number: remoteJid.split('@')[0],
|
||||||
|
delay: delayMessage || 1000,
|
||||||
|
text: unknownMessage,
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keywordFinish && content.toLowerCase() === keywordFinish.toLowerCase()) {
|
||||||
|
await this.prismaRepository.typebotSession.deleteMany({
|
||||||
|
where: {
|
||||||
|
typebotId: findTypebot.id,
|
||||||
|
remoteJid: remoteJid,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const version = this.configService.get<Typebot>('TYPEBOT').API_VERSION;
|
||||||
|
let urlTypebot: string;
|
||||||
|
let reqData: {};
|
||||||
|
if (version === 'latest') {
|
||||||
|
urlTypebot = `${url}/api/v1/sessions/${session.sessionId.split('-')[1]}/continueChat`;
|
||||||
|
reqData = {
|
||||||
|
message: content,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
urlTypebot = `${url}/api/v1/sendMessage`;
|
||||||
|
reqData = {
|
||||||
|
message: content,
|
||||||
|
sessionId: session.sessionId.split('-')[1],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const request = await axios.post(urlTypebot, reqData);
|
||||||
|
|
||||||
|
await this.sendWAMessage(
|
||||||
|
instance,
|
||||||
|
session,
|
||||||
|
{
|
||||||
|
expire: expire,
|
||||||
|
keywordFinish: keywordFinish,
|
||||||
|
delayMessage: delayMessage,
|
||||||
|
unknownMessage: unknownMessage,
|
||||||
|
listeningFromMe: listeningFromMe,
|
||||||
|
stopBotFromMe: stopBotFromMe,
|
||||||
|
keepOpen: keepOpen,
|
||||||
|
},
|
||||||
|
remoteJid,
|
||||||
|
request?.data?.messages,
|
||||||
|
request?.data?.input,
|
||||||
|
request?.data?.clientSideActions,
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,7 @@ export const typebotSettingSchema: JSONSchema7 = {
|
|||||||
listeningFromMe: { type: 'boolean' },
|
listeningFromMe: { type: 'boolean' },
|
||||||
stopBotFromMe: { type: 'boolean' },
|
stopBotFromMe: { type: 'boolean' },
|
||||||
keepOpen: { type: 'boolean' },
|
keepOpen: { type: 'boolean' },
|
||||||
|
debounceTime: { type: 'integer' },
|
||||||
},
|
},
|
||||||
required: ['expire', 'keywordFinish', 'delayMessage', 'unknownMessage', 'listeningFromMe', 'stopBotFromMe'],
|
required: ['expire', 'keywordFinish', 'delayMessage', 'unknownMessage', 'listeningFromMe', 'stopBotFromMe'],
|
||||||
...isNotEmpty('expire', 'keywordFinish', 'delayMessage', 'unknownMessage', 'listeningFromMe', 'stopBotFromMe'),
|
...isNotEmpty('expire', 'keywordFinish', 'delayMessage', 'unknownMessage', 'listeningFromMe', 'stopBotFromMe'),
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Events } from '../../../../validate/validate.schema';
|
|
||||||
import { InstanceDto } from '../../../dto/instance.dto';
|
import { InstanceDto } from '../../../dto/instance.dto';
|
||||||
import { WebsocketDto } from '../dto/websocket.dto';
|
import { WebsocketDto } from '../dto/websocket.dto';
|
||||||
import { WebsocketService } from '../services/websocket.service';
|
import { WebsocketService } from '../services/websocket.service';
|
||||||
@ -12,7 +11,33 @@ export class WebsocketController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.events.length === 0) {
|
if (data.events.length === 0) {
|
||||||
data.events = Events;
|
data.events = [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.websocketService.create(instance, data);
|
return this.websocketService.create(instance, data);
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import { JSONSchema7 } from 'json-schema';
|
import { JSONSchema7 } from 'json-schema';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
import { Events } from '../../../../validate/validate.schema';
|
|
||||||
|
|
||||||
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
||||||
const properties = {};
|
const properties = {};
|
||||||
propertyNames.forEach(
|
propertyNames.forEach(
|
||||||
@ -32,7 +30,33 @@ export const websocketSchema: JSONSchema7 = {
|
|||||||
minItems: 0,
|
minItems: 0,
|
||||||
items: {
|
items: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: Events,
|
enum: [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
12
src/main.ts
12
src/main.ts
@ -13,7 +13,7 @@ import { ProviderFiles } from './api/provider/sessions';
|
|||||||
import { PrismaRepository } from './api/repository/repository.service';
|
import { PrismaRepository } from './api/repository/repository.service';
|
||||||
import { HttpStatus, router } from './api/routes/index.router';
|
import { HttpStatus, router } from './api/routes/index.router';
|
||||||
import { waMonitor } from './api/server.module';
|
import { waMonitor } from './api/server.module';
|
||||||
import { Auth, configService, Cors, HttpServer, Rabbitmq, Sqs, Webhook } from './config/env.config';
|
import { Auth, configService, Cors, HttpServer, ProviderSession, Rabbitmq, Sqs, Webhook } from './config/env.config';
|
||||||
import { onUnexpectedError } from './config/error.config';
|
import { onUnexpectedError } from './config/error.config';
|
||||||
import { Logger } from './config/logger.config';
|
import { Logger } from './config/logger.config';
|
||||||
import { ROOT_DIR } from './config/path.config';
|
import { ROOT_DIR } from './config/path.config';
|
||||||
@ -27,9 +27,13 @@ async function bootstrap() {
|
|||||||
const logger = new Logger('SERVER');
|
const logger = new Logger('SERVER');
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
const providerFiles = new ProviderFiles(configService);
|
let providerFiles: ProviderFiles = null;
|
||||||
await providerFiles.onModuleInit();
|
if (configService.get<ProviderSession>('PROVIDER').ENABLED) {
|
||||||
logger.info('Provider:Files - ON');
|
providerFiles = new ProviderFiles(configService);
|
||||||
|
await providerFiles.onModuleInit();
|
||||||
|
logger.info('Provider:Files - ON');
|
||||||
|
}
|
||||||
|
|
||||||
const prismaRepository = new PrismaRepository(configService);
|
const prismaRepository = new PrismaRepository(configService);
|
||||||
await prismaRepository.onModuleInit();
|
await prismaRepository.onModuleInit();
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ import { JSONSchema7 } from 'json-schema';
|
|||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
import { Integration } from '../api/types/wa.types';
|
import { Integration } from '../api/types/wa.types';
|
||||||
import { Events } from './validate.schema';
|
|
||||||
|
|
||||||
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
||||||
const properties = {};
|
const properties = {};
|
||||||
@ -59,7 +58,33 @@ export const instanceSchema: JSONSchema7 = {
|
|||||||
minItems: 0,
|
minItems: 0,
|
||||||
items: {
|
items: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: Events,
|
enum: [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// RabbitMQ
|
// RabbitMQ
|
||||||
@ -69,7 +94,33 @@ export const instanceSchema: JSONSchema7 = {
|
|||||||
minItems: 0,
|
minItems: 0,
|
||||||
items: {
|
items: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: Events,
|
enum: [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// SQS
|
// SQS
|
||||||
@ -79,7 +130,33 @@ export const instanceSchema: JSONSchema7 = {
|
|||||||
minItems: 0,
|
minItems: 0,
|
||||||
items: {
|
items: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: Events,
|
enum: [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Chatwoot
|
// Chatwoot
|
||||||
|
@ -15,31 +15,3 @@ export * from './proxy.schema';
|
|||||||
export * from './settings.schema';
|
export * from './settings.schema';
|
||||||
export * from './webhook.schema';
|
export * from './webhook.schema';
|
||||||
export * from './websocket.schema';
|
export * from './websocket.schema';
|
||||||
|
|
||||||
export const Events = [
|
|
||||||
'APPLICATION_STARTUP',
|
|
||||||
'QRCODE_UPDATED',
|
|
||||||
'MESSAGES_SET',
|
|
||||||
'MESSAGES_UPSERT',
|
|
||||||
'MESSAGES_EDITED',
|
|
||||||
'MESSAGES_UPDATE',
|
|
||||||
'MESSAGES_DELETE',
|
|
||||||
'SEND_MESSAGE',
|
|
||||||
'CONTACTS_SET',
|
|
||||||
'CONTACTS_UPSERT',
|
|
||||||
'CONTACTS_UPDATE',
|
|
||||||
'PRESENCE_UPDATE',
|
|
||||||
'CHATS_SET',
|
|
||||||
'CHATS_UPSERT',
|
|
||||||
'CHATS_UPDATE',
|
|
||||||
'CHATS_DELETE',
|
|
||||||
'GROUPS_UPSERT',
|
|
||||||
'GROUP_UPDATE',
|
|
||||||
'GROUP_PARTICIPANTS_UPDATE',
|
|
||||||
'CONNECTION_UPDATE',
|
|
||||||
'LABELS_EDIT',
|
|
||||||
'LABELS_ASSOCIATION',
|
|
||||||
'CALL',
|
|
||||||
'TYPEBOT_START',
|
|
||||||
'TYPEBOT_CHANGE_STATUS',
|
|
||||||
];
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import { JSONSchema7 } from 'json-schema';
|
import { JSONSchema7 } from 'json-schema';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
import { Events } from './validate.schema';
|
|
||||||
|
|
||||||
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
||||||
const properties = {};
|
const properties = {};
|
||||||
propertyNames.forEach(
|
propertyNames.forEach(
|
||||||
@ -35,7 +33,33 @@ export const webhookSchema: JSONSchema7 = {
|
|||||||
minItems: 0,
|
minItems: 0,
|
||||||
items: {
|
items: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: Events,
|
enum: [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import { JSONSchema7 } from 'json-schema';
|
import { JSONSchema7 } from 'json-schema';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
import { Events } from './validate.schema';
|
|
||||||
|
|
||||||
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
||||||
const properties = {};
|
const properties = {};
|
||||||
propertyNames.forEach(
|
propertyNames.forEach(
|
||||||
@ -32,7 +30,33 @@ export const websocketSchema: JSONSchema7 = {
|
|||||||
minItems: 0,
|
minItems: 0,
|
||||||
items: {
|
items: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: Events,
|
enum: [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'MESSAGES_EDITED',
|
||||||
|
'MESSAGES_UPDATE',
|
||||||
|
'MESSAGES_DELETE',
|
||||||
|
'SEND_MESSAGE',
|
||||||
|
'CONTACTS_SET',
|
||||||
|
'CONTACTS_UPSERT',
|
||||||
|
'CONTACTS_UPDATE',
|
||||||
|
'PRESENCE_UPDATE',
|
||||||
|
'CHATS_SET',
|
||||||
|
'CHATS_UPSERT',
|
||||||
|
'CHATS_UPDATE',
|
||||||
|
'CHATS_DELETE',
|
||||||
|
'GROUPS_UPSERT',
|
||||||
|
'GROUP_UPDATE',
|
||||||
|
'GROUP_PARTICIPANTS_UPDATE',
|
||||||
|
'CONNECTION_UPDATE',
|
||||||
|
'LABELS_EDIT',
|
||||||
|
'LABELS_ASSOCIATION',
|
||||||
|
'CALL',
|
||||||
|
'TYPEBOT_START',
|
||||||
|
'TYPEBOT_CHANGE_STATUS',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user