mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-22 03:56:54 -06:00

- Introduced Evoai and EvoaiSetting models in both MySQL and PostgreSQL schemas. - Implemented EvoaiController and EvoaiService for managing EvoAI bots. - Created EvoaiRouter for handling API requests related to EvoAI. - Added DTOs and validation schemas for EvoAI integration. - Updated server module and chatbot controller to include EvoAI functionality. - Configured environment settings for EvoAI integration.
116 lines
3.0 KiB
TypeScript
116 lines
3.0 KiB
TypeScript
import { JSONSchema7 } from 'json-schema';
|
|
import { v4 } from 'uuid';
|
|
|
|
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
|
const properties = {};
|
|
propertyNames.forEach(
|
|
(property) =>
|
|
(properties[property] = {
|
|
minLength: 1,
|
|
description: `The "${property}" cannot be empty`,
|
|
}),
|
|
);
|
|
return {
|
|
if: {
|
|
propertyNames: {
|
|
enum: [...propertyNames],
|
|
},
|
|
},
|
|
then: { properties },
|
|
};
|
|
};
|
|
|
|
export const evoaiSchema: JSONSchema7 = {
|
|
$id: v4(),
|
|
type: 'object',
|
|
properties: {
|
|
enabled: { type: 'boolean' },
|
|
description: { type: 'string' },
|
|
agentUrl: { type: 'string' },
|
|
apiKey: { type: 'string' },
|
|
triggerType: { type: 'string', enum: ['all', 'keyword', 'none', 'advanced'] },
|
|
triggerOperator: { type: 'string', enum: ['equals', 'contains', 'startsWith', 'endsWith', 'regex'] },
|
|
triggerValue: { type: 'string' },
|
|
expire: { type: 'integer' },
|
|
keywordFinish: { type: 'string' },
|
|
delayMessage: { type: 'integer' },
|
|
unknownMessage: { type: 'string' },
|
|
listeningFromMe: { type: 'boolean' },
|
|
stopBotFromMe: { type: 'boolean' },
|
|
keepOpen: { type: 'boolean' },
|
|
debounceTime: { type: 'integer' },
|
|
ignoreJids: { type: 'array', items: { type: 'string' } },
|
|
splitMessages: { type: 'boolean' },
|
|
timePerChar: { type: 'integer' },
|
|
},
|
|
required: ['enabled', 'agentUrl', 'triggerType'],
|
|
...isNotEmpty('enabled', 'agentUrl', 'triggerType'),
|
|
};
|
|
|
|
export const evoaiStatusSchema: JSONSchema7 = {
|
|
$id: v4(),
|
|
type: 'object',
|
|
properties: {
|
|
remoteJid: { type: 'string' },
|
|
status: { type: 'string', enum: ['opened', 'closed', 'paused', 'delete'] },
|
|
},
|
|
required: ['remoteJid', 'status'],
|
|
...isNotEmpty('remoteJid', 'status'),
|
|
};
|
|
|
|
export const evoaiSettingSchema: JSONSchema7 = {
|
|
$id: v4(),
|
|
type: 'object',
|
|
properties: {
|
|
expire: { type: 'integer' },
|
|
keywordFinish: { type: 'string' },
|
|
delayMessage: { type: 'integer' },
|
|
unknownMessage: { type: 'string' },
|
|
listeningFromMe: { type: 'boolean' },
|
|
stopBotFromMe: { type: 'boolean' },
|
|
keepOpen: { type: 'boolean' },
|
|
debounceTime: { type: 'integer' },
|
|
ignoreJids: { type: 'array', items: { type: 'string' } },
|
|
evoaiIdFallback: { type: 'string' },
|
|
splitMessages: { type: 'boolean' },
|
|
timePerChar: { type: 'integer' },
|
|
},
|
|
required: [
|
|
'expire',
|
|
'keywordFinish',
|
|
'delayMessage',
|
|
'unknownMessage',
|
|
'listeningFromMe',
|
|
'stopBotFromMe',
|
|
'keepOpen',
|
|
'debounceTime',
|
|
'ignoreJids',
|
|
'splitMessages',
|
|
'timePerChar',
|
|
],
|
|
...isNotEmpty(
|
|
'expire',
|
|
'keywordFinish',
|
|
'delayMessage',
|
|
'unknownMessage',
|
|
'listeningFromMe',
|
|
'stopBotFromMe',
|
|
'keepOpen',
|
|
'debounceTime',
|
|
'ignoreJids',
|
|
'splitMessages',
|
|
'timePerChar',
|
|
),
|
|
};
|
|
|
|
export const evoaiIgnoreJidSchema: JSONSchema7 = {
|
|
$id: v4(),
|
|
type: 'object',
|
|
properties: {
|
|
remoteJid: { type: 'string' },
|
|
action: { type: 'string', enum: ['add', 'remove'] },
|
|
},
|
|
required: ['remoteJid', 'action'],
|
|
...isNotEmpty('remoteJid', 'action'),
|
|
};
|