-
Notifications
You must be signed in to change notification settings - Fork 514
[Apps] Adding support app alpha and dogfooding #1368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
madster456
wants to merge
37
commits into
dev
Choose a base branch
from
apps/support
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
8391a7f
init tutorial docs
madster456 2748980
init support app
madster456 13fa65f
Dogfood/ui - Updated UI to cleaner solution. SLA config implemented, …
madster456 524fa81
remove claude-knowledge dumb stuff
madster456 712a230
Merge remote-tracking branch 'origin/dev' into apps/support
madster456 c14c09a
Merge branch 'dev' into apps/support
madster456 7396b4d
replaced runAsync with runAsyncWithAlert, removed raw error display c…
madster456 5b7b886
listConversationSummaries now accepts limit/offset, fetches limit +1,…
madster456 3ba2ab3
Added explicit conversationEntryPointBySource mapping and now pass so…
madster456 080c4ec
Test only covered conversation_status_check and conversationMessage_s…
madster456 f98ebb0
the PATCH reply schema had no max, while feedback has max(5000). Upda…
madster456 c5a6c95
searchPattern was using raw user input and four LIKE caluses had no E…
madster456 e11b239
Replace support server redirect with client redirect
madster456 8eba792
Update claude-knowledge
madster456 9f71471
Update code notes for messageFromRow intentionally populating subject…
madster456 e608f40
both onBlur handlers in support-settings/page-client were using void …
madster456 2efa59f
Preserve support conversations when users or teams are deleted.
madster456 e768468
changed SupportChatMessage so it only returns null when the body is e…
madster456 71640b1
Merge branch 'dev' into apps/support
madster456 8bea90b
Merge branch 'dev' into apps/support
madster456 548bc00
Merge branch 'dev' into apps/support
madster456 30db8dd
update pnpm
madster456 ae06167
Remove support from config
madster456 19dc89d
simplify migrations, remove FK
madster456 263d844
Update crud to remove support on deletes, remove support settings pag…
madster456 90ba9df
Move conversation routes to internal/dogfood/support/conversations
madster456 601dfd1
Merge origin/dev into apps/support
madster456 30663e5
fix pnpm-lock
madster456 274369b
update docs for app icon
madster456 c5c7584
fix migration
madster456 c413847
Merge branch 'dev' into apps/support
madster456 6b86fb6
align conversations migration with prisma schema
madster456 27b1e1c
Merge branch 'dev' into apps/support
madster456 883aa07
merge dev into
madster456 1565174
Merge branch 'dev' into apps/support
madster456 6d65c95
Merge branch 'dev' into apps/support
madster456 22e4348
run codegen and update
madster456 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
apps/backend/prisma/migrations/20260420000000_add_conversations/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| CREATE TABLE "Conversation" ( | ||
| "id" UUID NOT NULL DEFAULT gen_random_uuid(), | ||
| "tenancyId" UUID NOT NULL, | ||
| "projectUserId" UUID, | ||
| "teamId" UUID, | ||
| "subject" TEXT NOT NULL, | ||
| "status" TEXT NOT NULL, | ||
| "priority" TEXT NOT NULL, | ||
| "source" TEXT NOT NULL, | ||
| "assignedToUserId" TEXT, | ||
| "assignedToDisplayName" TEXT, | ||
| "tags" JSONB, | ||
| "firstResponseDueAt" TIMESTAMP(3), | ||
| "firstResponseAt" TIMESTAMP(3), | ||
| "nextResponseDueAt" TIMESTAMP(3), | ||
| "lastCustomerReplyAt" TIMESTAMP(3), | ||
| "lastAgentReplyAt" TIMESTAMP(3), | ||
| "metadata" JSONB, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "lastMessageAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "lastInboundAt" TIMESTAMP(3), | ||
| "lastOutboundAt" TIMESTAMP(3), | ||
| "closedAt" TIMESTAMP(3), | ||
|
|
||
| CONSTRAINT "Conversation_pkey" PRIMARY KEY ("tenancyId","id"), | ||
| CONSTRAINT "Conversation_status_check" CHECK ("status" IN ('open', 'pending', 'closed')), | ||
| CONSTRAINT "Conversation_priority_check" CHECK ("priority" IN ('low', 'normal', 'high', 'urgent')), | ||
| CONSTRAINT "Conversation_source_check" CHECK ("source" IN ('manual', 'chat', 'email', 'api')), | ||
| CONSTRAINT "Conversation_tenancyId_fkey" FOREIGN KEY ("tenancyId") REFERENCES "Tenancy"("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
| CONSTRAINT "Conversation_projectUser_fkey" FOREIGN KEY ("tenancyId", "projectUserId") REFERENCES "ProjectUser"("tenancyId", "projectUserId") ON DELETE CASCADE ON UPDATE CASCADE, | ||
| CONSTRAINT "Conversation_team_fkey" FOREIGN KEY ("tenancyId", "teamId") REFERENCES "Team"("tenancyId", "teamId") ON DELETE CASCADE ON UPDATE CASCADE | ||
| ); | ||
|
|
||
| CREATE TABLE "ConversationEntryPoint" ( | ||
| "id" UUID NOT NULL DEFAULT gen_random_uuid(), | ||
| "tenancyId" UUID NOT NULL, | ||
| "conversationId" UUID NOT NULL, | ||
| "channelType" TEXT NOT NULL, | ||
| "adapterKey" TEXT NOT NULL, | ||
| "externalChannelId" TEXT, | ||
| "isEntryPoint" BOOLEAN NOT NULL DEFAULT FALSE, | ||
| "metadata" JSONB, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
|
||
| CONSTRAINT "ConversationEntryPoint_pkey" PRIMARY KEY ("tenancyId","id"), | ||
| CONSTRAINT "ConversationEntryPoint_type_check" CHECK ("channelType" IN ('manual', 'chat', 'email', 'api')), | ||
| CONSTRAINT "ConversationEntryPoint_tenancyId_fkey" FOREIGN KEY ("tenancyId") REFERENCES "Tenancy"("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
| CONSTRAINT "ConversationEntryPoint_conversation_fkey" FOREIGN KEY ("tenancyId", "conversationId") REFERENCES "Conversation"("tenancyId", "id") ON DELETE CASCADE ON UPDATE CASCADE | ||
| ); | ||
|
|
||
| CREATE TABLE "ConversationMessage" ( | ||
| "id" UUID NOT NULL DEFAULT gen_random_uuid(), | ||
| "tenancyId" UUID NOT NULL, | ||
| "conversationId" UUID NOT NULL, | ||
| "channelId" UUID, | ||
| "messageType" TEXT NOT NULL, | ||
| "senderType" TEXT NOT NULL, | ||
| "senderId" TEXT, | ||
| "senderDisplayName" TEXT, | ||
| "senderPrimaryEmail" TEXT, | ||
| "body" TEXT, | ||
| "attachments" JSONB, | ||
| "metadata" JSONB, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
|
||
| CONSTRAINT "ConversationMessage_pkey" PRIMARY KEY ("tenancyId","id"), | ||
| CONSTRAINT "ConversationMessage_messageType_check" CHECK ("messageType" IN ('message', 'internal-note', 'status-change')), | ||
| CONSTRAINT "ConversationMessage_senderType_check" CHECK ("senderType" IN ('user', 'agent', 'system')), | ||
| CONSTRAINT "ConversationMessage_tenancyId_fkey" FOREIGN KEY ("tenancyId") REFERENCES "Tenancy"("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
| CONSTRAINT "ConversationMessage_conversation_fkey" FOREIGN KEY ("tenancyId", "conversationId") REFERENCES "Conversation"("tenancyId", "id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
| CONSTRAINT "ConversationMessage_channel_fkey" FOREIGN KEY ("tenancyId", "channelId") REFERENCES "ConversationEntryPoint"("tenancyId", "id") ON DELETE NO ACTION ON UPDATE CASCADE | ||
| ); | ||
|
|
||
| CREATE INDEX "Conversation_user_lastMessageAt_idx" ON "Conversation"("tenancyId", "projectUserId", "lastMessageAt" DESC); | ||
| CREATE INDEX "Conversation_status_lastMessageAt_idx" ON "Conversation"("tenancyId", "status", "lastMessageAt" DESC); | ||
| CREATE INDEX "Conversation_team_lastMessageAt_idx" ON "Conversation"("tenancyId", "teamId", "lastMessageAt" DESC); | ||
| CREATE INDEX "ConversationEntryPoint_conversation_createdAt_idx" ON "ConversationEntryPoint"("tenancyId", "conversationId", "createdAt"); | ||
| CREATE INDEX "ConversationEntryPoint_type_adapter_idx" ON "ConversationEntryPoint"("tenancyId", "channelType", "adapterKey"); | ||
| CREATE INDEX "ConversationMessage_conversation_createdAt_idx" ON "ConversationMessage"("tenancyId", "conversationId", "createdAt"); | ||
| CREATE INDEX "ConversationMessage_channel_createdAt_idx" ON "ConversationMessage"("tenancyId", "channelId", "createdAt"); |
196 changes: 196 additions & 0 deletions
196
...d/prisma/migrations/20260420000000_add_conversations/tests/creates-conversation-tables.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| import { randomUUID } from "crypto"; | ||
| import type { Sql } from "postgres"; | ||
| import { expect } from "vitest"; | ||
|
|
||
| export const preMigration = async (sql: Sql) => { | ||
| const projectId = `test-${randomUUID()}`; | ||
| const tenancyId = randomUUID(); | ||
| const projectUserId = randomUUID(); | ||
|
|
||
| await sql` | ||
| INSERT INTO "Project" ("id", "createdAt", "updatedAt", "displayName", "description", "isProductionMode") | ||
| VALUES (${projectId}, NOW(), NOW(), 'Conversation Migration Test', '', false) | ||
| `; | ||
| await sql` | ||
| INSERT INTO "Tenancy" ("id", "createdAt", "updatedAt", "projectId", "branchId", "hasNoOrganization") | ||
| VALUES (${tenancyId}::uuid, NOW(), NOW(), ${projectId}, 'main', 'TRUE'::"BooleanTrue") | ||
| `; | ||
| await sql` | ||
| INSERT INTO "ProjectUser" ("projectUserId", "tenancyId", "mirroredProjectId", "mirroredBranchId", "createdAt", "updatedAt", "lastActiveAt") | ||
| VALUES (${projectUserId}::uuid, ${tenancyId}::uuid, ${projectId}, 'main', NOW(), NOW(), NOW()) | ||
| `; | ||
|
|
||
| return { tenancyId, projectUserId }; | ||
| }; | ||
|
|
||
| export const postMigration = async (sql: Sql, ctx: Awaited<ReturnType<typeof preMigration>>) => { | ||
| const tables = await sql<{ table_name: string }[]>` | ||
| SELECT table_name | ||
| FROM information_schema.tables | ||
| WHERE table_schema = 'public' | ||
| AND table_name IN ('Conversation', 'ConversationEntryPoint', 'ConversationMessage') | ||
| ORDER BY table_name | ||
| `; | ||
| expect(Array.from(tables)).toMatchInlineSnapshot(` | ||
| [ | ||
| { | ||
| "table_name": "Conversation", | ||
| }, | ||
| { | ||
| "table_name": "ConversationEntryPoint", | ||
| }, | ||
| { | ||
| "table_name": "ConversationMessage", | ||
| }, | ||
| ] | ||
| `); | ||
|
|
||
| const conversationId = randomUUID(); | ||
| const channelId = randomUUID(); | ||
| const messageId = randomUUID(); | ||
|
|
||
| await sql` | ||
| INSERT INTO "Conversation" ( | ||
| "id", | ||
| "tenancyId", | ||
| "projectUserId", | ||
| "subject", | ||
| "status", | ||
| "priority", | ||
| "source", | ||
| "assignedToUserId", | ||
| "assignedToDisplayName", | ||
| "tags", | ||
| "createdAt", | ||
| "updatedAt", | ||
| "lastMessageAt" | ||
| ) | ||
| VALUES ( | ||
| ${conversationId}::uuid, | ||
| ${ctx.tenancyId}::uuid, | ||
| ${ctx.projectUserId}::uuid, | ||
| 'Need support with onboarding', | ||
| 'open', | ||
| 'high', | ||
| 'chat', | ||
| 'support-admin-1', | ||
| 'Support Admin', | ||
| ${JSON.stringify(["vip", "auth"])}::jsonb, | ||
| NOW(), | ||
| NOW(), | ||
| NOW() | ||
| ) | ||
| `; | ||
|
|
||
| await sql` | ||
| INSERT INTO "ConversationEntryPoint" ( | ||
| "id", | ||
| "tenancyId", | ||
| "conversationId", | ||
| "channelType", | ||
| "adapterKey", | ||
| "isEntryPoint", | ||
| "createdAt", | ||
| "updatedAt" | ||
| ) | ||
| VALUES ( | ||
| ${channelId}::uuid, | ||
| ${ctx.tenancyId}::uuid, | ||
| ${conversationId}::uuid, | ||
| 'chat', | ||
| 'support-chat', | ||
| true, | ||
| NOW(), | ||
| NOW() | ||
| ) | ||
| `; | ||
|
|
||
| await sql` | ||
| INSERT INTO "ConversationMessage" ( | ||
| "id", | ||
| "tenancyId", | ||
| "conversationId", | ||
| "channelId", | ||
| "messageType", | ||
| "senderType", | ||
| "senderId", | ||
| "body", | ||
| "attachments", | ||
| "createdAt" | ||
| ) | ||
| VALUES ( | ||
| ${messageId}::uuid, | ||
| ${ctx.tenancyId}::uuid, | ||
| ${conversationId}::uuid, | ||
| ${channelId}::uuid, | ||
| 'message', | ||
| 'user', | ||
| ${ctx.projectUserId}, | ||
| 'The sign-in flow loops forever.', | ||
| '[]'::jsonb, | ||
| NOW() | ||
| ) | ||
| `; | ||
|
|
||
| const insertedConversation = await sql` | ||
| SELECT "status", "priority", "source" | ||
| FROM "Conversation" | ||
| WHERE "tenancyId" = ${ctx.tenancyId}::uuid | ||
| AND "id" = ${conversationId}::uuid | ||
| `; | ||
| expect(Array.from(insertedConversation)).toMatchInlineSnapshot(` | ||
| [ | ||
| { | ||
| "priority": "high", | ||
| "source": "chat", | ||
| "status": "open", | ||
| }, | ||
| ] | ||
| `); | ||
|
|
||
| await expect(sql` | ||
| INSERT INTO "Conversation" ( | ||
| "id", | ||
| "tenancyId", | ||
| "projectUserId", | ||
| "subject", | ||
| "status", | ||
| "priority", | ||
| "source", | ||
| "createdAt", | ||
| "updatedAt", | ||
| "lastMessageAt" | ||
| ) | ||
| VALUES ( | ||
| ${randomUUID()}::uuid, | ||
| ${ctx.tenancyId}::uuid, | ||
| ${ctx.projectUserId}::uuid, | ||
| 'Broken conversation row', | ||
| 'invalid', | ||
| 'high', | ||
| 'chat', | ||
| NOW(), | ||
| NOW(), | ||
| NOW() | ||
| ) | ||
| `).rejects.toThrow(/Conversation_status_check/); | ||
|
|
||
| await expect(sql` | ||
| INSERT INTO "ConversationMessage" ( | ||
| "id", | ||
| "tenancyId", | ||
| "conversationId", | ||
| "messageType", | ||
| "senderType", | ||
| "createdAt" | ||
| ) | ||
| VALUES ( | ||
| ${randomUUID()}::uuid, | ||
| ${ctx.tenancyId}::uuid, | ||
| ${conversationId}::uuid, | ||
| 'message', | ||
| 'invalid', | ||
| NOW() | ||
| ) | ||
| `).rejects.toThrow(/ConversationMessage_senderType_check/); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.