fix: adjusts for new manager

This commit is contained in:
Davidson Gomes 2024-07-29 15:09:40 -03:00
parent 089810fb55
commit 2a7f9698d2
7 changed files with 39 additions and 20 deletions

View File

@ -0,0 +1,20 @@
/*
Warnings:
- The values [open] on the enum `TypebotSessionStatus` will be removed. If these variants are still used in the database, this will fail.
- Changed the type of `status` on the `TypebotSession` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
*/
-- AlterEnum
BEGIN;
CREATE TYPE "TypebotSessionStatus_new" AS ENUM ('opened', 'closed', 'paused');
ALTER TABLE "TypebotSession" ALTER COLUMN "status" TYPE "TypebotSessionStatus_new" USING ("status"::text::"TypebotSessionStatus_new");
ALTER TABLE "OpenaiSession" ALTER COLUMN "status" TYPE "TypebotSessionStatus_new" USING ("status"::text::"TypebotSessionStatus_new");
ALTER TYPE "TypebotSessionStatus" RENAME TO "TypebotSessionStatus_old";
ALTER TYPE "TypebotSessionStatus_new" RENAME TO "TypebotSessionStatus";
DROP TYPE "TypebotSessionStatus_old";
COMMIT;
-- AlterTable
ALTER TABLE "TypebotSession" DROP COLUMN "status",
ADD COLUMN "status" "TypebotSessionStatus" NOT NULL;

View File

@ -36,6 +36,7 @@ enum TypebotSessionStatus {
enum TriggerType { enum TriggerType {
all all
keyword keyword
none
} }
enum TriggerOperator { enum TriggerOperator {

View File

@ -28,7 +28,7 @@ enum DeviceMessage {
} }
enum TypebotSessionStatus { enum TypebotSessionStatus {
open opened
closed closed
paused paused
} }
@ -292,7 +292,7 @@ model TypebotSession {
remoteJid String @db.VarChar(100) remoteJid String @db.VarChar(100)
pushName String? @db.VarChar(100) pushName String? @db.VarChar(100)
sessionId String @db.VarChar(100) sessionId String @db.VarChar(100)
status String @db.VarChar(100) status TypebotSessionStatus
prefilledVariables Json? @db.JsonB prefilledVariables Json? @db.JsonB
awaitUser Boolean @default(false) @db.Boolean awaitUser Boolean @default(false) @db.Boolean
createdAt DateTime? @default(now()) @db.Timestamp createdAt DateTime? @default(now()) @db.Timestamp

View File

@ -371,7 +371,7 @@ export class OpenaiService {
throw new Error('Openai Bot already exists'); throw new Error('Openai Bot already exists');
} }
if (data.triggerType !== 'all') { if (data.triggerType === 'keyword') {
if (!data.triggerOperator || !data.triggerValue) { if (!data.triggerOperator || !data.triggerValue) {
throw new Error('Trigger operator and value are required'); throw new Error('Trigger operator and value are required');
} }
@ -449,7 +449,6 @@ export class OpenaiService {
}); });
if (!openaiBots.length) { if (!openaiBots.length) {
this.logger.error('Openai bot not found');
return null; return null;
} }
@ -618,7 +617,7 @@ export class OpenaiService {
stopBotFromMe: settings.stopBotFromMe, stopBotFromMe: settings.stopBotFromMe,
keepOpen: settings.keepOpen, keepOpen: settings.keepOpen,
ignoreJids: settings.ignoreJids, ignoreJids: settings.ignoreJids,
openaiIdFallback: settings.Fallback, openaiIdFallback: settings.openaiIdFallback,
fallback: settings.Fallback, fallback: settings.Fallback,
}; };
} catch (error) { } catch (error) {
@ -1152,7 +1151,7 @@ export class OpenaiService {
data: { data: {
remoteJid: data.remoteJid, remoteJid: data.remoteJid,
sessionId: threadId, sessionId: threadId,
status: 'open', status: 'opened',
awaitUser: false, awaitUser: false,
openaiBotId: data.openaiBotId, openaiBotId: data.openaiBotId,
instanceId: instance.instanceId, instanceId: instance.instanceId,
@ -1217,7 +1216,7 @@ export class OpenaiService {
id: session.id, id: session.id,
}, },
data: { data: {
status: 'open', status: 'opened',
awaitUser: true, awaitUser: true,
}, },
}); });
@ -1255,7 +1254,7 @@ export class OpenaiService {
settings: OpenaiSetting, settings: OpenaiSetting,
content: string, content: string,
) { ) {
if (session && session.status !== 'open') { if (session && session.status !== 'opened') {
return; return;
} }
@ -1291,7 +1290,7 @@ export class OpenaiService {
id: session.id, id: session.id,
}, },
data: { data: {
status: 'open', status: 'opened',
awaitUser: false, awaitUser: false,
}, },
}); });
@ -1369,7 +1368,7 @@ export class OpenaiService {
id: session.id, id: session.id,
}, },
data: { data: {
status: 'open', status: 'opened',
awaitUser: true, awaitUser: true,
}, },
}); });
@ -1397,7 +1396,7 @@ export class OpenaiService {
data: { data: {
remoteJid: data.remoteJid, remoteJid: data.remoteJid,
sessionId: id, sessionId: id,
status: 'open', status: 'opened',
awaitUser: false, awaitUser: false,
openaiBotId: data.openaiBotId, openaiBotId: data.openaiBotId,
instanceId: instance.instanceId, instanceId: instance.instanceId,
@ -1497,7 +1496,7 @@ export class OpenaiService {
id: session.id, id: session.id,
}, },
data: { data: {
status: 'open', status: 'opened',
awaitUser: true, awaitUser: true,
}, },
}); });
@ -1515,7 +1514,7 @@ export class OpenaiService {
settings: OpenaiSetting, settings: OpenaiSetting,
content: string, content: string,
) { ) {
if (session && session.status !== 'open') { if (session && session.status !== 'opened') {
return; return;
} }
@ -1551,7 +1550,7 @@ export class OpenaiService {
id: session.id, id: session.id,
}, },
data: { data: {
status: 'open', status: 'opened',
awaitUser: false, awaitUser: false,
}, },
}); });
@ -1659,7 +1658,7 @@ export class OpenaiService {
id: session.id, id: session.id,
}, },
data: { data: {
status: 'open', status: 'opened',
awaitUser: true, awaitUser: true,
}, },
}); });

View File

@ -33,8 +33,8 @@ export const openaiSchema: JSONSchema7 = {
assistantMessages: { type: 'array', items: { type: 'string' } }, assistantMessages: { type: 'array', items: { type: 'string' } },
userMessages: { type: 'array', items: { type: 'string' } }, userMessages: { type: 'array', items: { type: 'string' } },
maxTokens: { type: 'integer' }, maxTokens: { type: 'integer' },
triggerType: { type: 'string', enum: ['all', 'keyword'] }, triggerType: { type: 'string', enum: ['all', 'keyword', 'none'] },
triggerOperator: { type: 'string', enum: ['equals', 'contains', 'startsWith', 'endsWith', 'regex', 'none'] }, triggerOperator: { type: 'string', enum: ['equals', 'contains', 'startsWith', 'endsWith', 'regex'] },
triggerValue: { type: 'string' }, triggerValue: { type: 'string' },
expire: { type: 'integer' }, expire: { type: 'integer' },
keywordFinish: { type: 'string' }, keywordFinish: { type: 'string' },

View File

@ -229,7 +229,7 @@ export class TypebotService {
throw new Error('Typebot already exists'); throw new Error('Typebot already exists');
} }
if (data.triggerType !== 'all') { if (data.triggerType === 'keyword') {
if (!data.triggerOperator || !data.triggerValue) { if (!data.triggerOperator || !data.triggerValue) {
throw new Error('Trigger operator and value are required'); throw new Error('Trigger operator and value are required');
} }
@ -300,7 +300,6 @@ export class TypebotService {
}); });
if (!typebots.length) { if (!typebots.length) {
this.logger.error('Typebot not found');
return null; return null;
} }

View File

@ -27,7 +27,7 @@ export const typebotSchema: JSONSchema7 = {
enabled: { type: 'boolean' }, enabled: { type: 'boolean' },
url: { type: 'string' }, url: { type: 'string' },
typebot: { type: 'string' }, typebot: { type: 'string' },
triggerType: { type: 'string', enum: ['all', 'keyword'] }, triggerType: { type: 'string', enum: ['all', 'keyword', 'none'] },
triggerOperator: { type: 'string', enum: ['equals', 'contains', 'startsWith', 'endsWith', 'regex'] }, triggerOperator: { type: 'string', enum: ['equals', 'contains', 'startsWith', 'endsWith', 'regex'] },
triggerValue: { type: 'string' }, triggerValue: { type: 'string' },
expire: { type: 'integer' }, expire: { type: 'integer' },