Add internal org chat (phase 1) with DM, groups, and org settings.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-29 10:34:01 +03:30
co-authored by Cursor
parent 589c763ef8
commit a1655432fc
21 changed files with 1912 additions and 8 deletions
@@ -0,0 +1,45 @@
-- CreateTable
CREATE TABLE "ConversationSettings" (
"organizationId" TEXT NOT NULL,
"chatHost" TEXT NOT NULL,
"apiKeyCipher" TEXT NOT NULL,
"apiKeyIv" TEXT NOT NULL,
"apiKeyTag" TEXT NOT NULL,
"uploadUrl" TEXT NOT NULL DEFAULT '',
"downloadUrl" TEXT NOT NULL DEFAULT '',
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "ConversationSettings_pkey" PRIMARY KEY ("organizationId")
);
-- CreateTable
CREATE TABLE "ConversationRoom" (
"id" TEXT NOT NULL,
"organizationId" TEXT NOT NULL,
"externalRoomId" TEXT NOT NULL,
"kind" TEXT NOT NULL,
"name" TEXT,
"dmUserMinId" TEXT,
"dmUserMaxId" TEXT,
"createdByUserId" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "ConversationRoom_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "ConversationRoom_organizationId_externalRoomId_key" ON "ConversationRoom"("organizationId", "externalRoomId");
-- CreateIndex
CREATE UNIQUE INDEX "ConversationRoom_organizationId_dmUserMinId_dmUserMaxId_key" ON "ConversationRoom"("organizationId", "dmUserMinId", "dmUserMaxId");
-- CreateIndex
CREATE INDEX "ConversationRoom_organizationId_kind_idx" ON "ConversationRoom"("organizationId", "kind");
-- AddForeignKey
ALTER TABLE "ConversationSettings" ADD CONSTRAINT "ConversationSettings_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ConversationRoom" ADD CONSTRAINT "ConversationRoom_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+35
View File
@@ -207,6 +207,8 @@ model Organization {
leadStages LeadStage[]
leadEvents LeadEvent[]
leadImportJobs LeadImportJob[]
conversationSettings ConversationSettings?
conversationRooms ConversationRoom[]
}
model User {
@@ -2060,3 +2062,36 @@ model LeadImportJob {
@@index([organizationId, status, createdAt])
@@index([status, createdAt])
}
/// تنظیمات اتصال به سرویس گفتگوی خارجی (هر محیط CRM)
model ConversationSettings {
organizationId String @id
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
chatHost String
apiKeyCipher String
apiKeyIv String
apiKeyTag String
uploadUrl String @default("")
downloadUrl String @default("")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
/// نگاشت roomهای سرویس چت (DM dedup و گروه‌های ساخته‌شده از CRM)
model ConversationRoom {
id String @id @default(cuid())
organizationId String
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
externalRoomId String
kind String
name String?
dmUserMinId String?
dmUserMaxId String?
createdByUserId String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([organizationId, externalRoomId])
@@unique([organizationId, dmUserMinId, dmUserMaxId])
@@index([organizationId, kind])
}