mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 09:51:24 -06:00

This commit introduces a new openai integration in the project, along with necessary changes in the database schema. The package.json file has been updated to include the openai package, and the prisma/postgresql-schema.prisma file has been modified to include OpenaiCreds, OpenaiAssistant, OpenaiAssistantThread, and OpenaiChatCompletion models. These models will handle the integration with OpenAI's API for various tasks. Some of the key changes include: - Addition of OpenaiCreds model to manage API credentials. - Addition of OpenaiAssistant model to handle OpenAI assistant instances. - Addition of OpenaiAssistantThread model to manage OpenAI assistant threads. - Addition of OpenaiChatCompletion model to handle OpenAI chat completions. These changes will enable seamless integration with OpenAI's API and allow for better management of assistant instances, threads, and chat completions.
423 lines
18 KiB
Plaintext
423 lines
18 KiB
Plaintext
// This is your Prisma schema file,
|
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
|
|
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
|
|
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_CONNECTION_URI")
|
|
}
|
|
|
|
enum InstanceConnectionStatus {
|
|
open
|
|
close
|
|
connecting
|
|
}
|
|
|
|
enum DeviceMessage {
|
|
ios
|
|
android
|
|
web
|
|
unknown
|
|
desktop
|
|
}
|
|
|
|
enum TypebotSessionStatus {
|
|
open
|
|
closed
|
|
paused
|
|
}
|
|
|
|
enum TriggerType {
|
|
all
|
|
keyword
|
|
}
|
|
|
|
enum TriggerOperator {
|
|
contains
|
|
equals
|
|
startsWith
|
|
endsWith
|
|
regex
|
|
}
|
|
|
|
model Instance {
|
|
id String @id @default(cuid())
|
|
name String @unique @db.VarChar(255)
|
|
connectionStatus InstanceConnectionStatus @default(open)
|
|
ownerJid String? @db.VarChar(100)
|
|
profileName String? @db.VarChar(100)
|
|
profilePicUrl String? @db.VarChar(500)
|
|
integration String? @db.VarChar(100)
|
|
number String? @db.VarChar(100)
|
|
businessId String? @db.VarChar(100)
|
|
token String? @unique @db.VarChar(255)
|
|
clientName String? @db.VarChar(100)
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime? @updatedAt @db.Timestamp
|
|
Chat Chat[]
|
|
Contact Contact[]
|
|
Message Message[]
|
|
Webhook Webhook?
|
|
Chatwoot Chatwoot?
|
|
Label Label[]
|
|
Proxy Proxy?
|
|
Setting Setting?
|
|
Rabbitmq Rabbitmq?
|
|
Sqs Sqs?
|
|
Websocket Websocket?
|
|
Typebot Typebot[]
|
|
Session Session?
|
|
MessageUpdate MessageUpdate[]
|
|
TypebotSession TypebotSession[]
|
|
TypebotSetting TypebotSetting?
|
|
Media Media[]
|
|
OpenaiCreds OpenaiCreds?
|
|
OpenaiAssistant OpenaiAssistant[]
|
|
OpenaiAssistantThread OpenaiAssistantThread[]
|
|
OpenaiChatCompletion OpenaiChatCompletion[]
|
|
OpenaiChatCompletionSession OpenaiChatCompletionSession[]
|
|
}
|
|
|
|
model Session {
|
|
id String @id @default(cuid())
|
|
sessionId String @unique
|
|
creds String? @db.Text
|
|
createdAt DateTime @default(now()) @db.Timestamp
|
|
Instance Instance @relation(fields: [sessionId], references: [id], onDelete: Cascade)
|
|
}
|
|
|
|
model Chat {
|
|
id String @id @default(cuid())
|
|
remoteJid String @db.VarChar(100)
|
|
labels Json? @db.JsonB
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime? @updatedAt @db.Timestamp
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String
|
|
}
|
|
|
|
model Contact {
|
|
id String @id @default(cuid())
|
|
remoteJid String @db.VarChar(100)
|
|
pushName String? @db.VarChar(100)
|
|
profilePicUrl String? @db.VarChar(500)
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime? @updatedAt @db.Timestamp
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String
|
|
}
|
|
|
|
model Message {
|
|
id String @id @default(cuid())
|
|
key Json @db.JsonB
|
|
pushName String? @db.VarChar(100)
|
|
participant String? @db.VarChar(100)
|
|
messageType String @db.VarChar(100)
|
|
message Json @db.JsonB
|
|
contextInfo Json? @db.JsonB
|
|
source DeviceMessage
|
|
messageTimestamp Int @db.Integer
|
|
chatwootMessageId Int? @db.Integer
|
|
chatwootInboxId Int? @db.Integer
|
|
chatwootConversationId Int? @db.Integer
|
|
chatwootContactInboxSourceId String? @db.VarChar(100)
|
|
chatwootIsRead Boolean? @db.Boolean
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String
|
|
typebotSessionId String?
|
|
MessageUpdate MessageUpdate[]
|
|
TypebotSession TypebotSession? @relation(fields: [typebotSessionId], references: [id])
|
|
Media Media?
|
|
OpenaiAssistantThread OpenaiAssistantThread? @relation(fields: [openaiAssistantThreadId], references: [id])
|
|
openaiAssistantThreadId String?
|
|
OpenaiChatCompletionSession OpenaiChatCompletionSession? @relation(fields: [openaiChatCompletionSessionId], references: [id])
|
|
openaiChatCompletionSessionId String?
|
|
}
|
|
|
|
model MessageUpdate {
|
|
id String @id @default(cuid())
|
|
keyId String @db.VarChar(100)
|
|
remoteJid String @db.VarChar(100)
|
|
fromMe Boolean @db.Boolean
|
|
participant String? @db.VarChar(100)
|
|
pollUpdates Json? @db.JsonB
|
|
status String @db.VarChar(30)
|
|
Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade)
|
|
messageId String
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String
|
|
}
|
|
|
|
model Webhook {
|
|
id String @id @default(cuid())
|
|
url String @db.VarChar(500)
|
|
enabled Boolean? @default(true) @db.Boolean
|
|
events Json? @db.JsonB
|
|
webhookByEvents Boolean? @default(false) @db.Boolean
|
|
webhookBase64 Boolean? @default(false) @db.Boolean
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String @unique
|
|
}
|
|
|
|
model Chatwoot {
|
|
id String @id @default(cuid())
|
|
enabled Boolean? @default(true) @db.Boolean
|
|
accountId String? @db.VarChar(100)
|
|
token String? @db.VarChar(100)
|
|
url String? @db.VarChar(500)
|
|
nameInbox String? @db.VarChar(100)
|
|
signMsg Boolean? @default(false) @db.Boolean
|
|
signDelimiter String? @db.VarChar(100)
|
|
number String? @db.VarChar(100)
|
|
reopenConversation Boolean? @default(false) @db.Boolean
|
|
conversationPending Boolean? @default(false) @db.Boolean
|
|
mergeBrazilContacts Boolean? @default(false) @db.Boolean
|
|
importContacts Boolean? @default(false) @db.Boolean
|
|
importMessages Boolean? @default(false) @db.Boolean
|
|
daysLimitImportMessages Int? @db.Integer
|
|
organization String? @db.VarChar(100)
|
|
logo String? @db.VarChar(500)
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String @unique
|
|
}
|
|
|
|
model Label {
|
|
id String @id @default(cuid())
|
|
labelId String? @unique @db.VarChar(100)
|
|
name String @db.VarChar(100)
|
|
color String @db.VarChar(100)
|
|
predefinedId String? @db.VarChar(100)
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String
|
|
}
|
|
|
|
model Proxy {
|
|
id String @id @default(cuid())
|
|
enabled Boolean @default(false) @db.Boolean
|
|
host String @db.VarChar(100)
|
|
port String @db.VarChar(100)
|
|
protocol String @db.VarChar(100)
|
|
username String @db.VarChar(100)
|
|
password String @db.VarChar(100)
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String @unique
|
|
}
|
|
|
|
model Setting {
|
|
id String @id @default(cuid())
|
|
rejectCall Boolean @default(false) @db.Boolean
|
|
msgCall String? @db.VarChar(100)
|
|
groupsIgnore Boolean @default(false) @db.Boolean
|
|
alwaysOnline Boolean @default(false) @db.Boolean
|
|
readMessages Boolean @default(false) @db.Boolean
|
|
readStatus Boolean @default(false) @db.Boolean
|
|
syncFullHistory Boolean @default(false) @db.Boolean
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String @unique
|
|
}
|
|
|
|
model Rabbitmq {
|
|
id String @id @default(cuid())
|
|
enabled Boolean @default(false) @db.Boolean
|
|
events Json @db.JsonB
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String @unique
|
|
}
|
|
|
|
model Sqs {
|
|
id String @id @default(cuid())
|
|
enabled Boolean @default(false) @db.Boolean
|
|
events Json @db.JsonB
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String @unique
|
|
}
|
|
|
|
model Websocket {
|
|
id String @id @default(cuid())
|
|
enabled Boolean @default(false) @db.Boolean
|
|
events Json @db.JsonB
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String @unique
|
|
}
|
|
|
|
model Typebot {
|
|
id String @id @default(cuid())
|
|
enabled Boolean @default(true) @db.Boolean
|
|
url String @db.VarChar(500)
|
|
typebot String @db.VarChar(100)
|
|
expire Int? @default(0) @db.Integer
|
|
keywordFinish String? @db.VarChar(100)
|
|
delayMessage Int? @db.Integer
|
|
unknownMessage String? @db.VarChar(100)
|
|
listeningFromMe Boolean? @default(false) @db.Boolean
|
|
stopBotFromMe Boolean? @default(false) @db.Boolean
|
|
keepOpen Boolean? @default(false) @db.Boolean
|
|
debounceTime Int? @db.Integer
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime? @updatedAt @db.Timestamp
|
|
ignoreJids Json?
|
|
triggerType TriggerType?
|
|
triggerOperator TriggerOperator?
|
|
triggerValue String?
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String
|
|
sessions TypebotSession[]
|
|
TypebotSetting TypebotSetting[]
|
|
}
|
|
|
|
model TypebotSession {
|
|
id String @id @default(cuid())
|
|
remoteJid String @db.VarChar(100)
|
|
pushName String? @db.VarChar(100)
|
|
sessionId String @db.VarChar(100)
|
|
status String @db.VarChar(100)
|
|
prefilledVariables Json? @db.JsonB
|
|
awaitUser Boolean @default(false) @db.Boolean
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
Typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade)
|
|
typebotId String
|
|
Message Message[]
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String
|
|
}
|
|
|
|
model TypebotSetting {
|
|
id String @id @default(cuid())
|
|
expire Int? @default(0) @db.Integer
|
|
keywordFinish String? @db.VarChar(100)
|
|
delayMessage Int? @db.Integer
|
|
unknownMessage String? @db.VarChar(100)
|
|
listeningFromMe Boolean? @default(false) @db.Boolean
|
|
stopBotFromMe Boolean? @default(false) @db.Boolean
|
|
keepOpen Boolean? @default(false) @db.Boolean
|
|
debounceTime Int? @db.Integer
|
|
typebotIdFallback String? @db.VarChar(100)
|
|
ignoreJids Json?
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
Fallback Typebot? @relation(fields: [typebotIdFallback], references: [id])
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String @unique
|
|
}
|
|
|
|
model Media {
|
|
id String @id @default(cuid())
|
|
fileName String @unique @db.VarChar(500)
|
|
type String @db.VarChar(100)
|
|
mimetype String @db.VarChar(100)
|
|
createdAt DateTime? @default(now()) @db.Date
|
|
Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade)
|
|
messageId String @unique
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String
|
|
}
|
|
|
|
model OpenaiCreds {
|
|
id String @id @default(cuid())
|
|
apiKey String @unique @db.VarChar(255)
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String @unique
|
|
}
|
|
|
|
model OpenaiAssistant {
|
|
id String @id @default(cuid())
|
|
assistantId String @unique @db.VarChar(255)
|
|
expire Int? @default(0) @db.Integer
|
|
keywordFinish String? @db.VarChar(100)
|
|
delayMessage Int? @db.Integer
|
|
unknownMessage String? @db.VarChar(100)
|
|
listeningFromMe Boolean? @default(false) @db.Boolean
|
|
stopBotFromMe Boolean? @default(false) @db.Boolean
|
|
keepOpen Boolean? @default(false) @db.Boolean
|
|
debounceTime Int? @db.Integer
|
|
ignoreJids Json?
|
|
triggerType TriggerType?
|
|
triggerOperator TriggerOperator?
|
|
triggerValue String?
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String
|
|
OpenaiAssistantThread OpenaiAssistantThread[]
|
|
}
|
|
|
|
model OpenaiAssistantThread {
|
|
id String @id @default(cuid())
|
|
threadId String @db.VarChar(255)
|
|
remoteJid String @db.VarChar(100)
|
|
status TypebotSessionStatus
|
|
awaitUser Boolean @default(false) @db.Boolean
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
OpenaiAssistant OpenaiAssistant @relation(fields: [openaiAssistantId], references: [id], onDelete: Cascade)
|
|
openaiAssistantId String
|
|
Message Message[]
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String
|
|
}
|
|
|
|
model OpenaiChatCompletion {
|
|
id String @id @default(cuid())
|
|
model String @db.VarChar(100)
|
|
systemMessages Json? @db.JsonB
|
|
assistantMessages Json? @db.JsonB
|
|
userMessages Json? @db.JsonB
|
|
maxTokens Int? @db.Integer
|
|
expire Int? @default(0) @db.Integer
|
|
keywordFinish String? @db.VarChar(100)
|
|
delayMessage Int? @db.Integer
|
|
unknownMessage String? @db.VarChar(100)
|
|
listeningFromMe Boolean? @default(false) @db.Boolean
|
|
stopBotFromMe Boolean? @default(false) @db.Boolean
|
|
keepOpen Boolean? @default(false) @db.Boolean
|
|
debounceTime Int? @db.Integer
|
|
ignoreJids Json?
|
|
triggerType TriggerType?
|
|
triggerOperator TriggerOperator?
|
|
triggerValue String?
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String
|
|
OpenaiChatCompletionSession OpenaiChatCompletionSession[]
|
|
}
|
|
|
|
model OpenaiChatCompletionSession {
|
|
id String @id @default(cuid())
|
|
remoteJid String @db.VarChar(100)
|
|
sessionId String @db.VarChar(100)
|
|
status TypebotSessionStatus
|
|
createdAt DateTime? @default(now()) @db.Timestamp
|
|
updatedAt DateTime @updatedAt @db.Timestamp
|
|
OpenaiChatCompletion OpenaiChatCompletion @relation(fields: [openaiChatCompletionId], references: [id], onDelete: Cascade)
|
|
openaiChatCompletionId String
|
|
Message Message[]
|
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
|
instanceId String
|
|
}
|