mirror of
				https://github.com/abhinavxd/libredesk.git
				synced 2025-11-04 05:53:30 +00:00 
			
		
		
		
	Compare commits
	
		
			217 Commits
		
	
	
		
			fix/imap-i
			...
			help-artic
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					6f62a77783 | ||
| 
						 | 
					af1373272e | ||
| 
						 | 
					61e343de5b | ||
| 
						 | 
					c721d19b81 | ||
| 
						 | 
					2ff5a945e2 | ||
| 
						 | 
					77111835cc | ||
| 
						 | 
					5284b2ee15 | ||
| 
						 | 
					b1f8231f7d | ||
| 
						 | 
					45a77b1422 | ||
| 
						 | 
					9a77c8953c | ||
| 
						 | 
					18d4a8fe3b | ||
| 
						 | 
					a2234e908f | ||
| 
						 | 
					d7fe6153bb | ||
| 
						 | 
					f786c4d962 | ||
| 
						 | 
					cff5a6dfc2 | ||
| 
						 | 
					d0df6f9322 | ||
| 
						 | 
					30902310dc | ||
| 
						 | 
					8bf0255b61 | ||
| 
						 | 
					f337f79f96 | ||
| 
						 | 
					68c2708464 | ||
| 
						 | 
					e0dc0285a4 | ||
| 
						 | 
					4f9fc029c0 | ||
| 
						 | 
					6cfa93838a | ||
| 
						 | 
					f72f158cf0 | ||
| 
						 | 
					1962abdc16 | ||
| 
						 | 
					b971619ea6 | ||
| 
						 | 
					69accaebef | ||
| 
						 | 
					081a5c615a | ||
| 
						 | 
					27de73536e | ||
| 
						 | 
					df108a3363 | ||
| 
						 | 
					c35ab42b47 | ||
| 
						 | 
					f05014f412 | ||
| 
						 | 
					e2bba04669 | ||
| 
						 | 
					4beab72a11 | ||
| 
						 | 
					26b3b30fca | ||
| 
						 | 
					11fd57adb0 | ||
| 
						 | 
					266c3dab72 | ||
| 
						 | 
					bf2c1fff6f | ||
| 
						 | 
					d4f644c531 | ||
| 
						 | 
					646bbc7efe | ||
| 
						 | 
					3c3709557e | ||
| 
						 | 
					74732bfe91 | ||
| 
						 | 
					8ee81c2d64 | ||
| 
						 | 
					2930af0c4f | ||
| 
						 | 
					389c4e3dd3 | ||
| 
						 | 
					9a119e6dc3 | ||
| 
						 | 
					ee178d383d | ||
| 
						 | 
					fc4db676d9 | ||
| 
						 | 
					70cb3d0f80 | ||
| 
						 | 
					c9920c3377 | ||
| 
						 | 
					6d62c3a4ba | ||
| 
						 | 
					d9b5fb8f0f | ||
| 
						 | 
					3de320f1fb | ||
| 
						 | 
					be977dcff2 | ||
| 
						 | 
					5e19f13e18 | ||
| 
						 | 
					ccc5940dd9 | ||
| 
						 | 
					282dc83439 | ||
| 
						 | 
					61a70f6b52 | ||
| 
						 | 
					5b6a58fba0 | ||
| 
						 | 
					4203b82e90 | ||
| 
						 | 
					ba07e224c2 | ||
| 
						 | 
					3fff65150f | ||
| 
						 | 
					c4fcf6bd91 | ||
| 
						 | 
					5ea1b9e84c | ||
| 
						 | 
					5b522888bc | ||
| 
						 | 
					dc2250ce50 | ||
| 
						 | 
					839a06f0d2 | ||
| 
						 | 
					d2e5d85e3a | ||
| 
						 | 
					0737d22374 | ||
| 
						 | 
					d6af9d10ea | ||
| 
						 | 
					6381fc23c2 | ||
| 
						 | 
					6bb5728665 | ||
| 
						 | 
					2322ec33b0 | ||
| 
						 | 
					9132e11458 | ||
| 
						 | 
					e70f92d377 | ||
| 
						 | 
					591108f094 | ||
| 
						 | 
					1b2a5e4f36 | ||
| 
						 | 
					f613cc237b | ||
| 
						 | 
					c37258fccb | ||
| 
						 | 
					1879d9d22b | ||
| 
						 | 
					b369e2f56a | ||
| 
						 | 
					ef56f1a74e | ||
| 
						 | 
					d274adb19b | ||
| 
						 | 
					d31fcb00b6 | ||
| 
						 | 
					88d719ec4f | ||
| 
						 | 
					147180a536 | ||
| 
						 | 
					faa195f0a6 | ||
| 
						 | 
					4b0422d904 | ||
| 
						 | 
					9303997cea | ||
| 
						 | 
					aba07b3096 | ||
| 
						 | 
					27aac88f53 | ||
| 
						 | 
					cb6b0e420b | ||
| 
						 | 
					e004afd7d1 | ||
| 
						 | 
					6a77d346dc | ||
| 
						 | 
					60c89cb617 | ||
| 
						 | 
					b7d4b187e8 | ||
| 
						 | 
					2bf45f32de | ||
| 
						 | 
					981372ab86 | ||
| 
						 | 
					803196985d | ||
| 
						 | 
					ebf6a980e8 | ||
| 
						 | 
					813ef91964 | ||
| 
						 | 
					3b9fb7a08d | ||
| 
						 | 
					7fb86f140c | ||
| 
						 | 
					aa8d326fa1 | ||
| 
						 | 
					ca9a0a5892 | ||
| 
						 | 
					73e2950174 | ||
| 
						 | 
					e7b8e5c4bb | ||
| 
						 | 
					582c906440 | ||
| 
						 | 
					f3881ee0aa | ||
| 
						 | 
					b557c2ca4b | ||
| 
						 | 
					30884d3536 | ||
| 
						 | 
					bce0d1d12f | ||
| 
						 | 
					67a4f6a162 | ||
| 
						 | 
					ec28ac8f3a | ||
| 
						 | 
					bc71fcfdc1 | ||
| 
						 | 
					bc0bee8f6a | ||
| 
						 | 
					499fc0dad1 | ||
| 
						 | 
					03b932c1c0 | ||
| 
						 | 
					012de059e7 | ||
| 
						 | 
					6357faf6c8 | ||
| 
						 | 
					f7a12cffd3 | ||
| 
						 | 
					6487bf9a0a | ||
| 
						 | 
					53d5715429 | ||
| 
						 | 
					b561e79440 | ||
| 
						 | 
					e567acbe59 | ||
| 
						 | 
					57d0e90b5f | ||
| 
						 | 
					5a0e3a8072 | ||
| 
						 | 
					d95a5f40cf | ||
| 
						 | 
					6981a0790d | ||
| 
						 | 
					55bc9bfc91 | ||
| 
						 | 
					67db2e5ff2 | ||
| 
						 | 
					64304c2384 | ||
| 
						 | 
					c5fe6aaadd | ||
| 
						 | 
					fea7eef658 | ||
| 
						 | 
					475e400810 | ||
| 
						 | 
					641ae0540e | ||
| 
						 | 
					dc6fede081 | ||
| 
						 | 
					28dcd6cb2f | ||
| 
						 | 
					ade833fb7b | ||
| 
						 | 
					5bcb0a2ad9 | ||
| 
						 | 
					ad2f685fec | ||
| 
						 | 
					26c7df538c | ||
| 
						 | 
					625a08d0aa | ||
| 
						 | 
					bf1510b9c3 | ||
| 
						 | 
					bae896d38d | ||
| 
						 | 
					37b7c05b30 | ||
| 
						 | 
					eb05368f18 | ||
| 
						 | 
					7ef510894b | ||
| 
						 | 
					69268a3a84 | ||
| 
						 | 
					fcd3462d25 | ||
| 
						 | 
					fbf502451a | ||
| 
						 | 
					dc909ceb4f | ||
| 
						 | 
					cc1432b3e4 | ||
| 
						 | 
					d532a99771 | ||
| 
						 | 
					50baa3f38e | ||
| 
						 | 
					63a8f04408 | ||
| 
						 | 
					ea0b7d6d52 | ||
| 
						 | 
					5d6897a960 | ||
| 
						 | 
					c4a95672fe | ||
| 
						 | 
					2efd07b405 | ||
| 
						 | 
					0b9cf38826 | ||
| 
						 | 
					b44c314299 | ||
| 
						 | 
					2e1188e443 | ||
| 
						 | 
					afeec39b59 | ||
| 
						 | 
					fb2a08ec1a | ||
| 
						 | 
					7f2df0082c | ||
| 
						 | 
					6c523ac447 | ||
| 
						 | 
					02fc57c35a | ||
| 
						 | 
					cd0a357695 | ||
| 
						 | 
					2dc751e602 | ||
| 
						 | 
					8bc0cce993 | ||
| 
						 | 
					f6e2fc1956 | ||
| 
						 | 
					5fe5ac5882 | ||
| 
						 | 
					975577555d | ||
| 
						 | 
					f43acb77a1 | ||
| 
						 | 
					331c84fa56 | ||
| 
						 | 
					9314efb9d9 | ||
| 
						 | 
					5c8481af97 | ||
| 
						 | 
					d9bc4d1c0d | ||
| 
						 | 
					087c8ad491 | ||
| 
						 | 
					65cac843cb | ||
| 
						 | 
					23b0481f24 | ||
| 
						 | 
					9a651702ce | ||
| 
						 | 
					a0203f882e | ||
| 
						 | 
					75425ca0dd | ||
| 
						 | 
					c2849fa63d | ||
| 
						 | 
					b20c7845ac | ||
| 
						 | 
					38a5b25b1f | ||
| 
						 | 
					9dce155ebc | ||
| 
						 | 
					314341b40d | ||
| 
						 | 
					1f6e3322aa | ||
| 
						 | 
					102ba99b3c | ||
| 
						 | 
					8285575f1c | ||
| 
						 | 
					01d3b590a9 | ||
| 
						 | 
					210e0de1ae | ||
| 
						 | 
					1f8fdf2ef6 | ||
| 
						 | 
					696e4780ac | ||
| 
						 | 
					3998798e54 | ||
| 
						 | 
					70b5da29e1 | ||
| 
						 | 
					88ef5d26db | ||
| 
						 | 
					54bad59392 | ||
| 
						 | 
					506bb91e20 | ||
| 
						 | 
					d1478e1971 | ||
| 
						 | 
					5583b472f7 | ||
| 
						 | 
					b715483260 | ||
| 
						 | 
					8ce0464603 | ||
| 
						 | 
					a84ed1ed32 | ||
| 
						 | 
					7426a09478 | ||
| 
						 | 
					8ad2f078ac | ||
| 
						 | 
					9226063db3 | ||
| 
						 | 
					a9fd4fe2b6 | ||
| 
						 | 
					7e8c9962c3 | ||
| 
						 | 
					cf20142e40 | ||
| 
						 | 
					8654a04dcf | ||
| 
						 | 
					4c766d8ccb | ||
| 
						 | 
					cb1ec7eb8e | ||
| 
						 | 
					a89c3dbe04 | 
							
								
								
									
										16
									
								
								.github/ISSUE_TEMPLATE/confirmed-bug.md
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								.github/ISSUE_TEMPLATE/confirmed-bug.md
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					---
 | 
				
			||||||
 | 
					name: Confirmed Bug Report
 | 
				
			||||||
 | 
					about: Report a confirmed bug in Libredesk
 | 
				
			||||||
 | 
					title: "[Bug] <brief summary>"
 | 
				
			||||||
 | 
					labels: bug
 | 
				
			||||||
 | 
					assignees: ""
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Version:**
 | 
				
			||||||
 | 
					- libredesk: [eg: v0.7.0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Description of the bug and steps to reproduce:**
 | 
				
			||||||
 | 
					A clear and concise description of what the bug is.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Logs / Screenshots:**
 | 
				
			||||||
 | 
					Attach any relevant logs or screenshots to help diagnose the issue.
 | 
				
			||||||
							
								
								
									
										16
									
								
								.github/ISSUE_TEMPLATE/possible-bug.md
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								.github/ISSUE_TEMPLATE/possible-bug.md
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					---
 | 
				
			||||||
 | 
					name: Possible Bug Report
 | 
				
			||||||
 | 
					about: Something in Libredesk might be broken but needs confirmation
 | 
				
			||||||
 | 
					title: "[Possible Bug] <brief summary>"
 | 
				
			||||||
 | 
					labels: bug, needs-investigation
 | 
				
			||||||
 | 
					assignees: ""
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Version:**
 | 
				
			||||||
 | 
					 - libredesk: [eg: v0.7.0]
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					**Description of the bug and steps to reproduce:**
 | 
				
			||||||
 | 
					A clear and concise description of what the bug is.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Logs / Screenshots:**
 | 
				
			||||||
 | 
					Attach any relevant logs or screenshots to help diagnose the issue.
 | 
				
			||||||
							
								
								
									
										2
									
								
								.github/workflows/crowdin.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/crowdin.yml
									
									
									
									
										vendored
									
									
								
							@@ -12,6 +12,8 @@ on:
 | 
				
			|||||||
jobs:
 | 
					jobs:
 | 
				
			||||||
  crowdin:
 | 
					  crowdin:
 | 
				
			||||||
    runs-on: ubuntu-latest
 | 
					    runs-on: ubuntu-latest
 | 
				
			||||||
 | 
					    # Only run on the original repository, not forks
 | 
				
			||||||
 | 
					    if: github.event.repository.fork == false
 | 
				
			||||||
    steps:
 | 
					    steps:
 | 
				
			||||||
      - name: Checkout
 | 
					      - name: Checkout
 | 
				
			||||||
        uses: actions/checkout@v4
 | 
					        uses: actions/checkout@v4
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,6 +53,11 @@ jobs:
 | 
				
			|||||||
      - name: Configure app
 | 
					      - name: Configure app
 | 
				
			||||||
        run: |
 | 
					        run: |
 | 
				
			||||||
          cp config.sample.toml config.toml
 | 
					          cp config.sample.toml config.toml
 | 
				
			||||||
 | 
					          sed -i 's/host = "db"/host = "127.0.0.1"/' config.toml
 | 
				
			||||||
 | 
					          sed -i 's/address = "redis:6379"/address = "localhost:6379"/' config.toml
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      - name: Run unit tests for frontend
 | 
				
			||||||
 | 
					        run: cd frontend && pnpm test:run
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Install db schema and run tests
 | 
					      - name: Install db schema and run tests
 | 
				
			||||||
        env:
 | 
					        env:
 | 
				
			||||||
							
								
								
									
										45
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								Makefile
									
									
									
									
									
								
							@@ -28,32 +28,61 @@ install-deps: $(STUFFBIN)
 | 
				
			|||||||
	@echo "→ Installing frontend dependencies..."
 | 
						@echo "→ Installing frontend dependencies..."
 | 
				
			||||||
	@cd ${FRONTEND_DIR} && pnpm install
 | 
						@cd ${FRONTEND_DIR} && pnpm install
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Build the frontend for production.
 | 
					# Build the frontend for production (both apps).
 | 
				
			||||||
.PHONY: frontend-build
 | 
					.PHONY: frontend-build
 | 
				
			||||||
frontend-build: install-deps
 | 
					frontend-build: install-deps
 | 
				
			||||||
	@echo "→ Building frontend for production..."
 | 
						@echo "→ Building frontend for production - main app & widget..."
 | 
				
			||||||
	@export VITE_APP_VERSION="${VERSION}" && cd ${FRONTEND_DIR} && pnpm build
 | 
						@export VITE_APP_VERSION="${VERSION}" && cd ${FRONTEND_DIR} && pnpm build:main
 | 
				
			||||||
 | 
						@export VITE_APP_VERSION="${VERSION}" && cd ${FRONTEND_DIR} && pnpm build:widget
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Build only the main frontend app.
 | 
				
			||||||
 | 
					.PHONY: frontend-build-main
 | 
				
			||||||
 | 
					frontend-build-main: install-deps
 | 
				
			||||||
 | 
						@echo "→ Building main frontend app for production..."
 | 
				
			||||||
 | 
						@export VITE_APP_VERSION="${VERSION}" && cd ${FRONTEND_DIR} && pnpm build:main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Build only the widget frontend app.
 | 
				
			||||||
 | 
					.PHONY: frontend-build-widget
 | 
				
			||||||
 | 
					frontend-build-widget: install-deps
 | 
				
			||||||
 | 
						@echo "→ Building widget frontend app for production..."
 | 
				
			||||||
 | 
						@export VITE_APP_VERSION="${VERSION}" && cd ${FRONTEND_DIR} && pnpm build:widget
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Run the Go backend server in development mode.
 | 
					# Run the Go backend server in development mode.
 | 
				
			||||||
.PHONY: run-backend
 | 
					.PHONY: run-backend
 | 
				
			||||||
run-backend:
 | 
					run-backend:
 | 
				
			||||||
	@echo "→ Running backend..."
 | 
						@echo "→ Running backend..."
 | 
				
			||||||
	CGO_ENABLED=0 go run -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}' -X 'main.frontendDir=frontend/dist'" cmd/*.go
 | 
						CGO_ENABLED=0 go run -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}' -X 'github.com/abhinavxd/libredesk/internal/version.Version=${VERSION}' -X 'main.frontendDir=frontend/dist'" cmd/*.go
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Run the JS frontend server in development mode.
 | 
					# Run the JS frontend server in development mode (main app only).
 | 
				
			||||||
.PHONY: run-frontend
 | 
					.PHONY: run-frontend
 | 
				
			||||||
run-frontend:
 | 
					run-frontend:
 | 
				
			||||||
	@echo "→ Installing frontend dependencies (if not already installed)..."
 | 
						@echo "→ Installing frontend dependencies (if not already installed)..."
 | 
				
			||||||
	@cd ${FRONTEND_DIR} && pnpm install
 | 
						@cd ${FRONTEND_DIR} && pnpm install
 | 
				
			||||||
	@echo "→ Running frontend..."
 | 
						@echo "→ Running main frontend app..."
 | 
				
			||||||
	@export VITE_APP_VERSION="${VERSION}" && cd ${FRONTEND_DIR} && pnpm dev
 | 
						@export VITE_APP_VERSION="${VERSION}" && cd ${FRONTEND_DIR} && pnpm dev:main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Run the main frontend app in development mode.
 | 
				
			||||||
 | 
					.PHONY: run-frontend-main
 | 
				
			||||||
 | 
					run-frontend-main:
 | 
				
			||||||
 | 
						@echo "→ Installing frontend dependencies (if not already installed)..."
 | 
				
			||||||
 | 
						@cd ${FRONTEND_DIR} && pnpm install
 | 
				
			||||||
 | 
						@echo "→ Running main frontend app..."
 | 
				
			||||||
 | 
						@export VITE_APP_VERSION="${VERSION}" && cd ${FRONTEND_DIR} && pnpm dev:main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Run the widget frontend app in development mode.
 | 
				
			||||||
 | 
					.PHONY: run-frontend-widget
 | 
				
			||||||
 | 
					run-frontend-widget:
 | 
				
			||||||
 | 
						@echo "→ Installing frontend dependencies (if not already installed)..."
 | 
				
			||||||
 | 
						@cd ${FRONTEND_DIR} && pnpm install
 | 
				
			||||||
 | 
						@echo "→ Running widget frontend app..."
 | 
				
			||||||
 | 
						@export VITE_APP_VERSION="${VERSION}" && cd ${FRONTEND_DIR} && pnpm dev:widget
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Build the backend binary.
 | 
					# Build the backend binary.
 | 
				
			||||||
.PHONY: build-backend
 | 
					.PHONY: build-backend
 | 
				
			||||||
build-backend: $(STUFFBIN)
 | 
					build-backend: $(STUFFBIN)
 | 
				
			||||||
	@echo "→ Building backend..."
 | 
						@echo "→ Building backend..."
 | 
				
			||||||
	@CGO_ENABLED=0 go build -a \
 | 
						@CGO_ENABLED=0 go build -a \
 | 
				
			||||||
		-ldflags="-X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}' -s -w" \
 | 
							-ldflags="-X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}' -X 'github.com/abhinavxd/libredesk/internal/version.Version=${VERSION}' -s -w" \
 | 
				
			||||||
		-o ${BIN} cmd/*.go
 | 
							-o ${BIN} cmd/*.go
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Main build target: builds both frontend and backend, then stuffs static assets into the binary.
 | 
					# Main build target: builds both frontend and backend, then stuffs static assets into the binary.
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										30
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								README.md
									
									
									
									
									
								
							@@ -5,18 +5,17 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Open source, self-hosted customer support desk. Single binary app.
 | 
					Open source, self-hosted customer support desk. Single binary app.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Visit [libredesk.io](https://libredesk.io) for more info. Check out the [**Live demo**](https://demo.libredesk.io/).
 | 
					Visit [libredesk.io](https://libredesk.io) for more info. Check out the [**Live demo**](https://demo.libredesk.io/).
 | 
				
			||||||
 | 
					
 | 
				
			||||||

 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
> **CAUTION:** This project is currently in **alpha**. Features and APIs may change and are not yet fully tested.
 | 
					> **CAUTION:** This project is currently in **alpha**. Features and APIs may change and are not yet fully tested.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Features
 | 
					## Features
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- **Multi Inbox**  
 | 
					- **Multi Shared Inbox**  
 | 
				
			||||||
  Libredesk supports multiple inboxes, letting you manage conversations across teams effortlessly.
 | 
					  Libredesk supports multiple shared inboxes, letting you manage conversations across teams effortlessly.
 | 
				
			||||||
- **Granular Permissions**  
 | 
					- **Granular Permissions**  
 | 
				
			||||||
  Create custom roles with granular permissions for teams and individual agents.
 | 
					  Create custom roles with granular permissions for teams and individual agents.
 | 
				
			||||||
- **Smart Automation**  
 | 
					- **Smart Automation**  
 | 
				
			||||||
@@ -31,14 +30,16 @@ Visit [libredesk.io](https://libredesk.io) for more info. Check out the [**Live
 | 
				
			|||||||
  Distribute workload with auto assignment rules. Auto-assign conversations based on agent capacity or custom criteria.
 | 
					  Distribute workload with auto assignment rules. Auto-assign conversations based on agent capacity or custom criteria.
 | 
				
			||||||
- **SLA Management**  
 | 
					- **SLA Management**  
 | 
				
			||||||
  Set and track response time targets. Get notified when conversations are at risk of breaching SLA commitments.
 | 
					  Set and track response time targets. Get notified when conversations are at risk of breaching SLA commitments.
 | 
				
			||||||
- **Business Intelligence**  
 | 
					- **Custom attributes**  
 | 
				
			||||||
  Connect your favorite BI tools like Metabase and create custom dashboards and reports with your support data—without lock-ins.
 | 
					  Create custom attributes for contacts or conversations such as the subscription plan or the date of their first purchase. 
 | 
				
			||||||
- **AI-Assisted Response Rewrite**  
 | 
					- **AI-Assist**  
 | 
				
			||||||
  Instantly rewrite responses with AI to make them more friendly, professional, or polished.
 | 
					  Instantly rewrite responses with AI to make them more friendly, professional, or polished.
 | 
				
			||||||
- **Activity logs**  
 | 
					- **Activity logs**  
 | 
				
			||||||
  Track all actions performed by agents and admins—updates and key events across the system—for auditing and accountability.
 | 
					  Track all actions performed by agents and admins—updates and key events across the system—for auditing and accountability.
 | 
				
			||||||
 | 
					- **Webhooks**  
 | 
				
			||||||
 | 
					  Integrate with external systems using real-time HTTP notifications for conversation and message events.
 | 
				
			||||||
- **Command Bar**  
 | 
					- **Command Bar**  
 | 
				
			||||||
  Opens with a simple shortcut (CTRL+k) and lets you quickly perform actions on conversations.
 | 
					  Opens with a simple shortcut (CTRL+K) and lets you quickly perform actions on conversations.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
And more checkout - [libredesk.io](https://libredesk.io)
 | 
					And more checkout - [libredesk.io](https://libredesk.io)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -57,8 +58,6 @@ curl -LO https://github.com/abhinavxd/libredesk/raw/main/config.sample.toml
 | 
				
			|||||||
# Copy the config.sample.toml to config.toml and edit it as needed.
 | 
					# Copy the config.sample.toml to config.toml and edit it as needed.
 | 
				
			||||||
cp config.sample.toml config.toml
 | 
					cp config.sample.toml config.toml
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Edit config.toml and find commented lines containing "docker compose". Replace the values in the lines below those comments with service names instead of IP addresses.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Run the services in the background.
 | 
					# Run the services in the background.
 | 
				
			||||||
docker compose up -d
 | 
					docker compose up -d
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -66,7 +65,7 @@ docker compose up -d
 | 
				
			|||||||
docker exec -it libredesk_app ./libredesk --set-system-user-password
 | 
					docker exec -it libredesk_app ./libredesk --set-system-user-password
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Go to `http://localhost:9000` and login with username `System` and the password you set using the --set-system-user-password command.
 | 
					Go to `http://localhost:9000` and login with username `System` and the password you set using the `--set-system-user-password` command.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
See [installation docs](https://libredesk.io/docs/installation/)
 | 
					See [installation docs](https://libredesk.io/docs/installation/)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -86,6 +85,11 @@ __________________
 | 
				
			|||||||
## Developers
 | 
					## Developers
 | 
				
			||||||
If you are interested in contributing, refer to the [developer setup](https://libredesk.io/docs/developer-setup/). The backend is written in Go and the frontend is Vue js 3 with Shadcn for UI components.
 | 
					If you are interested in contributing, refer to the [developer setup](https://libredesk.io/docs/developer-setup/). The backend is written in Go and the frontend is Vue js 3 with Shadcn for UI components.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Development Status
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Libredesk is under active development.  
 | 
				
			||||||
 | 
					Track roadmap and progress on the GitHub Project Board:   [https://github.com/users/abhinavxd/projects/1](https://github.com/users/abhinavxd/projects/1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Translators
 | 
					## Translators
 | 
				
			||||||
You can help translate Libredesk into your language on [Crowdin](https://crowdin.com/project/libredesk).  
 | 
					You can help translate Libredesk into your language on [Crowdin](https://crowdin.com/project/libredesk).  
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										15
									
								
								cmd/ai.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								cmd/ai.go
									
									
									
									
									
								
							@@ -5,6 +5,11 @@ import (
 | 
				
			|||||||
	"github.com/zerodha/fastglue"
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type aiCompletionReq struct {
 | 
				
			||||||
 | 
						PromptKey string `json:"prompt_key"`
 | 
				
			||||||
 | 
						Content   string `json:"content"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type providerUpdateReq struct {
 | 
					type providerUpdateReq struct {
 | 
				
			||||||
	Provider string `json:"provider"`
 | 
						Provider string `json:"provider"`
 | 
				
			||||||
	APIKey   string `json:"api_key"`
 | 
						APIKey   string `json:"api_key"`
 | 
				
			||||||
@@ -14,10 +19,14 @@ type providerUpdateReq struct {
 | 
				
			|||||||
func handleAICompletion(r *fastglue.Request) error {
 | 
					func handleAICompletion(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		app = r.Context.(*App)
 | 
							app = r.Context.(*App)
 | 
				
			||||||
		promptKey = string(r.RequestCtx.PostArgs().Peek("prompt_key"))
 | 
							req = aiCompletionReq{}
 | 
				
			||||||
		content   = string(r.RequestCtx.PostArgs().Peek("content"))
 | 
					 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	resp, err := app.ai.Completion(promptKey, content)
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := app.ai.Completion(req.PromptKey, req.Content)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										193
									
								
								cmd/ai_assistants.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										193
									
								
								cmd/ai_assistants.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,193 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/envelope"
 | 
				
			||||||
 | 
						umodels "github.com/abhinavxd/libredesk/internal/user/models"
 | 
				
			||||||
 | 
						"github.com/valyala/fasthttp"
 | 
				
			||||||
 | 
						"github.com/volatiletech/null/v9"
 | 
				
			||||||
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type aiAssisantRequest struct {
 | 
				
			||||||
 | 
						FirstName          string `json:"first_name"`
 | 
				
			||||||
 | 
						LastName           string `json:"last_name"`
 | 
				
			||||||
 | 
						Email              string `json:"email"`
 | 
				
			||||||
 | 
						AvatarURL          string `json:"avatar_url"`
 | 
				
			||||||
 | 
						ProductName        string `json:"product_name"`
 | 
				
			||||||
 | 
						ProductDescription string `json:"product_description"`
 | 
				
			||||||
 | 
						AnswerLength       string `json:"answer_length"`
 | 
				
			||||||
 | 
						AnswerTone         string `json:"answer_tone"`
 | 
				
			||||||
 | 
						HandOff            bool   `json:"hand_off"`
 | 
				
			||||||
 | 
						HandOffTeam        int    `json:"hand_off_team"`
 | 
				
			||||||
 | 
						Enabled            bool   `json:"enabled"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleGetAIAssistants returns all AI assistants from the database.
 | 
				
			||||||
 | 
					func handleGetAIAssistants(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var app = r.Context.(*App)
 | 
				
			||||||
 | 
						assistants, err := app.user.GetAIAssistants()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(assistants)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleGetAIAssistant returns a single AI assistant by ID.
 | 
				
			||||||
 | 
					func handleGetAIAssistant(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						assistant, err := app.user.GetAIAssistant(id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(assistant)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleCreateAIAssistant creates a new AI assistant in the database.
 | 
				
			||||||
 | 
					func handleCreateAIAssistant(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app = r.Context.(*App)
 | 
				
			||||||
 | 
							req = aiAssisantRequest{}
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := validateAIAssistantRequest(req, app); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Prepare meta data
 | 
				
			||||||
 | 
						meta := umodels.AIAssistantMeta{
 | 
				
			||||||
 | 
							ProductName:        req.ProductName,
 | 
				
			||||||
 | 
							ProductDescription: req.ProductDescription,
 | 
				
			||||||
 | 
							AnswerLength:       req.AnswerLength,
 | 
				
			||||||
 | 
							AnswerTone:         req.AnswerTone,
 | 
				
			||||||
 | 
							HandOff:            req.HandOff,
 | 
				
			||||||
 | 
							HandOffTeam:        req.HandOffTeam,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						metaBytes, err := json.Marshal(meta)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.errorMarshalling", "name", "{globals.terms.meta}"), err.Error(), envelope.GeneralError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Create AI assistant in the database
 | 
				
			||||||
 | 
						assistant := &umodels.User{
 | 
				
			||||||
 | 
							FirstName: req.FirstName,
 | 
				
			||||||
 | 
							LastName:  req.LastName,
 | 
				
			||||||
 | 
							Email:     null.NewString(req.Email, req.Email != ""),
 | 
				
			||||||
 | 
							AvatarURL: null.NewString(req.AvatarURL, req.AvatarURL != ""),
 | 
				
			||||||
 | 
							Type:      umodels.UserTypeAIAssistant,
 | 
				
			||||||
 | 
							Enabled:   true,
 | 
				
			||||||
 | 
							Meta:      metaBytes,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := app.user.CreateAIAssistant(assistant); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(assistant)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleUpdateAIAssistant updates an existing AI assistant in the database.
 | 
				
			||||||
 | 
					func handleUpdateAIAssistant(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							req   = aiAssisantRequest{}
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := validateAIAssistantRequest(req, app); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Prepare meta data
 | 
				
			||||||
 | 
						meta := umodels.AIAssistantMeta{
 | 
				
			||||||
 | 
							ProductName:        req.ProductName,
 | 
				
			||||||
 | 
							ProductDescription: req.ProductDescription,
 | 
				
			||||||
 | 
							AnswerLength:       req.AnswerLength,
 | 
				
			||||||
 | 
							AnswerTone:         req.AnswerTone,
 | 
				
			||||||
 | 
							HandOff:            req.HandOff,
 | 
				
			||||||
 | 
							HandOffTeam:        req.HandOffTeam,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						metaBytes, err := json.Marshal(meta)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, "Error encoding meta data", err.Error(), envelope.GeneralError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Update AI assistant in the database
 | 
				
			||||||
 | 
						assistant := umodels.User{
 | 
				
			||||||
 | 
							FirstName: req.FirstName,
 | 
				
			||||||
 | 
							LastName:  req.LastName,
 | 
				
			||||||
 | 
							Email:     null.NewString(req.Email, req.Email != ""),
 | 
				
			||||||
 | 
							AvatarURL: null.NewString(req.AvatarURL, req.AvatarURL != ""),
 | 
				
			||||||
 | 
							Enabled:   req.Enabled,
 | 
				
			||||||
 | 
							Meta:      metaBytes,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := app.user.UpdateAIAssistant(id, assistant); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Return the updated assistant
 | 
				
			||||||
 | 
						updatedAssistant, err := app.user.GetAIAssistant(id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(updatedAssistant)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleDeleteAIAssistant soft deletes an AI assistant from the database.
 | 
				
			||||||
 | 
					func handleDeleteAIAssistant(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app = r.Context.(*App)
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						id, err := strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						if err != nil || id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := app.user.SoftDeleteAIAssistant(id); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// validateAIAssistantRequest validates the fields of an aiAssisantRequest.
 | 
				
			||||||
 | 
					func validateAIAssistantRequest(req aiAssisantRequest, app *App) error {
 | 
				
			||||||
 | 
						if req.FirstName == "" {
 | 
				
			||||||
 | 
							return envelope.NewError("validation_error", app.i18n.Ts("globals.messages.empty", "name", "`first_name`"), nil)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if req.ProductName == "" {
 | 
				
			||||||
 | 
							return envelope.NewError("validation_error", app.i18n.Ts("globals.messages.empty", "name", "`product_name`"), nil)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if req.ProductDescription == "" {
 | 
				
			||||||
 | 
							return envelope.NewError("validation_error", app.i18n.Ts("globals.messages.empty", "name", "`product_description`"), nil)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if req.AnswerLength == "" {
 | 
				
			||||||
 | 
							return envelope.NewError("validation_error", app.i18n.Ts("globals.messages.empty", "name", "`answer_length`"), nil)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if req.AnswerTone == "" {
 | 
				
			||||||
 | 
							return envelope.NewError("validation_error", app.i18n.Ts("globals.messages.empty", "name", "`answer_tone`"), nil)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -9,6 +9,10 @@ import (
 | 
				
			|||||||
	"github.com/zerodha/fastglue"
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type updateAutomationRuleExecutionModeReq struct {
 | 
				
			||||||
 | 
						Mode string `json:"mode"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleGetAutomationRules gets all automation rules
 | 
					// handleGetAutomationRules gets all automation rules
 | 
				
			||||||
func handleGetAutomationRules(r *fastglue.Request) error {
 | 
					func handleGetAutomationRules(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
@@ -41,10 +45,11 @@ func handleToggleAutomationRule(r *fastglue.Request) error {
 | 
				
			|||||||
		app   = r.Context.(*App)
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
		id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	if err := app.automation.ToggleRule(id); err != nil {
 | 
						toggledRule, err := app.automation.ToggleRule(id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(toggledRule)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleUpdateAutomationRule updates an automation rule
 | 
					// handleUpdateAutomationRule updates an automation rule
 | 
				
			||||||
@@ -62,10 +67,11 @@ func handleUpdateAutomationRule(r *fastglue.Request) error {
 | 
				
			|||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err = app.automation.UpdateRule(id, rule); err != nil {
 | 
						updatedRule, err := app.automation.UpdateRule(id, rule)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(updatedRule)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleCreateAutomationRule creates a new automation rule
 | 
					// handleCreateAutomationRule creates a new automation rule
 | 
				
			||||||
@@ -77,10 +83,11 @@ func handleCreateAutomationRule(r *fastglue.Request) error {
 | 
				
			|||||||
	if err := r.Decode(&rule, "json"); err != nil {
 | 
						if err := r.Decode(&rule, "json"); err != nil {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := app.automation.CreateRule(rule); err != nil {
 | 
						createdRule, err := app.automation.CreateRule(rule)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(createdRule)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleDeleteAutomationRule deletes an automation rule
 | 
					// handleDeleteAutomationRule deletes an automation rule
 | 
				
			||||||
@@ -119,13 +126,19 @@ func handleUpdateAutomationRuleWeights(r *fastglue.Request) error {
 | 
				
			|||||||
func handleUpdateAutomationRuleExecutionMode(r *fastglue.Request) error {
 | 
					func handleUpdateAutomationRuleExecutionMode(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		app = r.Context.(*App)
 | 
							app = r.Context.(*App)
 | 
				
			||||||
		mode = string(r.RequestCtx.PostArgs().Peek("mode"))
 | 
							req = updateAutomationRuleExecutionModeReq{}
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	if mode != amodels.ExecutionModeAll && mode != amodels.ExecutionModeFirstMatch {
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if req.Mode != amodels.ExecutionModeAll && req.Mode != amodels.ExecutionModeFirstMatch {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.T("automation.invalidRuleExecutionMode"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.T("automation.invalidRuleExecutionMode"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Only new conversation rules can be updated as they are the only ones that have execution mode.
 | 
						// Only new conversation rules can be updated as they are the only ones that have execution mode.
 | 
				
			||||||
	if err := app.automation.UpdateRuleExecutionMode(amodels.RuleTypeNewConversation, mode); err != nil {
 | 
						if err := app.automation.UpdateRuleExecutionMode(amodels.RuleTypeNewConversation, req.Mode); err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -55,11 +55,12 @@ func handleCreateBusinessHours(r *fastglue.Request) error {
 | 
				
			|||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := app.businessHours.Create(businessHours.Name, businessHours.Description, businessHours.IsAlwaysOpen, businessHours.Hours, businessHours.Holidays); err != nil {
 | 
						createdBusinessHours, err := app.businessHours.Create(businessHours.Name, businessHours.Description, businessHours.IsAlwaysOpen, businessHours.Hours, businessHours.Holidays)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(createdBusinessHours)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleDeleteBusinessHour deletes the business hour with the given id.
 | 
					// handleDeleteBusinessHour deletes the business hour with the given id.
 | 
				
			||||||
@@ -93,8 +94,9 @@ func handleUpdateBusinessHours(r *fastglue.Request) error {
 | 
				
			|||||||
	if businessHours.Name == "" {
 | 
						if businessHours.Name == "" {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`name`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`name`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := app.businessHours.Update(id, businessHours.Name, businessHours.Description, businessHours.IsAlwaysOpen, businessHours.Hours, businessHours.Holidays); err != nil {
 | 
						updatedBusinessHours, err := app.businessHours.Update(id, businessHours.Name, businessHours.Description, businessHours.IsAlwaysOpen, businessHours.Hours, businessHours.Holidays)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(updatedBusinessHours)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1088
									
								
								cmd/chat.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1088
									
								
								cmd/chat.go
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -14,6 +14,14 @@ import (
 | 
				
			|||||||
	"github.com/zerodha/fastglue"
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type createContactNoteReq struct {
 | 
				
			||||||
 | 
						Note string `json:"note"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type blockContactReq struct {
 | 
				
			||||||
 | 
						Enabled bool `json:"enabled"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleGetContacts returns a list of contacts from the database.
 | 
					// handleGetContacts returns a list of contacts from the database.
 | 
				
			||||||
func handleGetContacts(r *fastglue.Request) error {
 | 
					func handleGetContacts(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
@@ -185,12 +193,17 @@ func handleCreateContactNote(r *fastglue.Request) error {
 | 
				
			|||||||
		app          = r.Context.(*App)
 | 
							app          = r.Context.(*App)
 | 
				
			||||||
		contactID, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
							contactID, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
		auser        = r.RequestCtx.UserValue("user").(amodels.User)
 | 
							auser        = r.RequestCtx.UserValue("user").(amodels.User)
 | 
				
			||||||
		note         = string(r.RequestCtx.PostArgs().Peek("note"))
 | 
							req          = createContactNoteReq{}
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	if len(note) == 0 {
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(req.Note) == 0 {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "note"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "note"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := app.user.CreateNote(contactID, auser.ID, note); err != nil {
 | 
						if err := app.user.CreateNote(contactID, auser.ID, req.Note); err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
@@ -238,12 +251,18 @@ func handleBlockContact(r *fastglue.Request) error {
 | 
				
			|||||||
	var (
 | 
						var (
 | 
				
			||||||
		app          = r.Context.(*App)
 | 
							app          = r.Context.(*App)
 | 
				
			||||||
		contactID, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
							contactID, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
		enabled      = r.RequestCtx.PostArgs().GetBool("enabled")
 | 
							req          = blockContactReq{}
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if contactID <= 0 {
 | 
						if contactID <= 0 {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := app.user.ToggleEnabled(contactID, models.UserTypeContact, enabled); err != nil {
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := app.user.ToggleEnabled(contactID, models.UserTypeContact, req.Enabled); err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,7 @@
 | 
				
			|||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/json"
 | 
					 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	amodels "github.com/abhinavxd/libredesk/internal/auth/models"
 | 
						amodels "github.com/abhinavxd/libredesk/internal/auth/models"
 | 
				
			||||||
@@ -11,13 +9,48 @@ import (
 | 
				
			|||||||
	"github.com/abhinavxd/libredesk/internal/automation/models"
 | 
						"github.com/abhinavxd/libredesk/internal/automation/models"
 | 
				
			||||||
	cmodels "github.com/abhinavxd/libredesk/internal/conversation/models"
 | 
						cmodels "github.com/abhinavxd/libredesk/internal/conversation/models"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/envelope"
 | 
						"github.com/abhinavxd/libredesk/internal/envelope"
 | 
				
			||||||
 | 
						medModels "github.com/abhinavxd/libredesk/internal/media/models"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/stringutil"
 | 
						"github.com/abhinavxd/libredesk/internal/stringutil"
 | 
				
			||||||
	umodels "github.com/abhinavxd/libredesk/internal/user/models"
 | 
						umodels "github.com/abhinavxd/libredesk/internal/user/models"
 | 
				
			||||||
 | 
						wmodels "github.com/abhinavxd/libredesk/internal/webhook/models"
 | 
				
			||||||
	"github.com/valyala/fasthttp"
 | 
						"github.com/valyala/fasthttp"
 | 
				
			||||||
	"github.com/volatiletech/null/v9"
 | 
						"github.com/volatiletech/null/v9"
 | 
				
			||||||
	"github.com/zerodha/fastglue"
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type assigneeChangeReq struct {
 | 
				
			||||||
 | 
						AssigneeID int `json:"assignee_id"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type teamAssigneeChangeReq struct {
 | 
				
			||||||
 | 
						AssigneeID int `json:"assignee_id"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type priorityUpdateReq struct {
 | 
				
			||||||
 | 
						Priority string `json:"priority"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type statusUpdateReq struct {
 | 
				
			||||||
 | 
						Status       string `json:"status"`
 | 
				
			||||||
 | 
						SnoozedUntil string `json:"snoozed_until,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type tagsUpdateReq struct {
 | 
				
			||||||
 | 
						Tags []string `json:"tags"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type createConversationRequest struct {
 | 
				
			||||||
 | 
						InboxID         int    `json:"inbox_id"`
 | 
				
			||||||
 | 
						AssignedAgentID int    `json:"agent_id"`
 | 
				
			||||||
 | 
						AssignedTeamID  int    `json:"team_id"`
 | 
				
			||||||
 | 
						Email           string `json:"contact_email"`
 | 
				
			||||||
 | 
						FirstName       string `json:"first_name"`
 | 
				
			||||||
 | 
						LastName        string `json:"last_name"`
 | 
				
			||||||
 | 
						Subject         string `json:"subject"`
 | 
				
			||||||
 | 
						Content         string `json:"content"`
 | 
				
			||||||
 | 
						Attachments     []int  `json:"attachments"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleGetAllConversations retrieves all conversations.
 | 
					// handleGetAllConversations retrieves all conversations.
 | 
				
			||||||
func handleGetAllConversations(r *fastglue.Request) error {
 | 
					func handleGetAllConversations(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
@@ -294,10 +327,12 @@ func handleUpdateUserAssignee(r *fastglue.Request) error {
 | 
				
			|||||||
		app   = r.Context.(*App)
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
		uuid  = r.RequestCtx.UserValue("uuid").(string)
 | 
							uuid  = r.RequestCtx.UserValue("uuid").(string)
 | 
				
			||||||
		auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
							auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
				
			||||||
		assigneeID = r.RequestCtx.PostArgs().GetUintOrZero("assignee_id")
 | 
							req   = assigneeChangeReq{}
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	if assigneeID == 0 {
 | 
					
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`assignee_id`"), nil, envelope.InputError)
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							app.lo.Error("error decoding assignee change request", "error", err)
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	user, err := app.user.GetAgent(auser.ID, "")
 | 
						user, err := app.user.GetAgent(auser.ID, "")
 | 
				
			||||||
@@ -305,17 +340,19 @@ func handleUpdateUserAssignee(r *fastglue.Request) error {
 | 
				
			|||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_, err = enforceConversationAccess(app, uuid, user)
 | 
						conversation, err := enforceConversationAccess(app, uuid, user)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := app.conversation.UpdateConversationUserAssignee(uuid, assigneeID, user); err != nil {
 | 
						// Already assigned?
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
						if conversation.AssignedUserID.Int == req.AssigneeID {
 | 
				
			||||||
 | 
							return r.SendEnvelope(true)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Evaluate automation rules.
 | 
						if err := app.conversation.UpdateConversationUserAssignee(uuid, req.AssigneeID, user); err != nil {
 | 
				
			||||||
	app.automation.EvaluateConversationUpdateRules(uuid, models.EventConversationUserAssigned)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -326,12 +363,16 @@ func handleUpdateTeamAssignee(r *fastglue.Request) error {
 | 
				
			|||||||
		app   = r.Context.(*App)
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
		uuid  = r.RequestCtx.UserValue("uuid").(string)
 | 
							uuid  = r.RequestCtx.UserValue("uuid").(string)
 | 
				
			||||||
		auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
							auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
				
			||||||
 | 
							req   = teamAssigneeChangeReq{}
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	assigneeID, err := r.RequestCtx.PostArgs().GetUint("assignee_id")
 | 
					
 | 
				
			||||||
	if err != nil {
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`assignee_id`"), nil, envelope.InputError)
 | 
							app.lo.Error("error decoding team assignee change request", "error", err)
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assigneeID := req.AssigneeID
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	user, err := app.user.GetAgent(auser.ID, "")
 | 
						user, err := app.user.GetAgent(auser.ID, "")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
@@ -342,17 +383,19 @@ func handleUpdateTeamAssignee(r *fastglue.Request) error {
 | 
				
			|||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_, err = enforceConversationAccess(app, uuid, user)
 | 
						conversation, err := enforceConversationAccess(app, uuid, user)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Already assigned?
 | 
				
			||||||
 | 
						if conversation.AssignedTeamID.Int == assigneeID {
 | 
				
			||||||
 | 
							return r.SendEnvelope(true)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if err := app.conversation.UpdateConversationTeamAssignee(uuid, assigneeID, user); err != nil {
 | 
						if err := app.conversation.UpdateConversationTeamAssignee(uuid, assigneeID, user); err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Evaluate automation rules on team assignment.
 | 
					 | 
				
			||||||
	app.automation.EvaluateConversationUpdateRules(uuid, models.EventConversationTeamAssigned)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -362,8 +405,15 @@ func handleUpdateConversationPriority(r *fastglue.Request) error {
 | 
				
			|||||||
		app   = r.Context.(*App)
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
		uuid  = r.RequestCtx.UserValue("uuid").(string)
 | 
							uuid  = r.RequestCtx.UserValue("uuid").(string)
 | 
				
			||||||
		auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
							auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
				
			||||||
		priority = string(r.RequestCtx.PostArgs().Peek("priority"))
 | 
							req   = priorityUpdateReq{}
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							app.lo.Error("error decoding priority update request", "error", err)
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						priority := req.Priority
 | 
				
			||||||
	if priority == "" {
 | 
						if priority == "" {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`priority`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`priority`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -380,9 +430,6 @@ func handleUpdateConversationPriority(r *fastglue.Request) error {
 | 
				
			|||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Evaluate automation rules.
 | 
					 | 
				
			||||||
	app.automation.EvaluateConversationUpdateRules(uuid, models.EventConversationPriorityChange)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -390,12 +437,19 @@ func handleUpdateConversationPriority(r *fastglue.Request) error {
 | 
				
			|||||||
func handleUpdateConversationStatus(r *fastglue.Request) error {
 | 
					func handleUpdateConversationStatus(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		app   = r.Context.(*App)
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
		status       = string(r.RequestCtx.PostArgs().Peek("status"))
 | 
					 | 
				
			||||||
		snoozedUntil = string(r.RequestCtx.PostArgs().Peek("snoozed_until"))
 | 
					 | 
				
			||||||
		uuid  = r.RequestCtx.UserValue("uuid").(string)
 | 
							uuid  = r.RequestCtx.UserValue("uuid").(string)
 | 
				
			||||||
		auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
							auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
				
			||||||
 | 
							req   = statusUpdateReq{}
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							app.lo.Error("error decoding status update request", "error", err)
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						status := req.Status
 | 
				
			||||||
 | 
						snoozedUntil := req.SnoozedUntil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Validate inputs
 | 
						// Validate inputs
 | 
				
			||||||
	if status == "" {
 | 
						if status == "" {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`status`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`status`"), nil, envelope.InputError)
 | 
				
			||||||
@@ -415,37 +469,16 @@ func handleUpdateConversationStatus(r *fastglue.Request) error {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	conversation, err := enforceConversationAccess(app, uuid, user)
 | 
						_, err = enforceConversationAccess(app, uuid, user)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Make sure a user is assigned before resolving conversation.
 | 
					 | 
				
			||||||
	if status == cmodels.StatusResolved && conversation.AssignedUserID.Int == 0 {
 | 
					 | 
				
			||||||
		return sendErrorEnvelope(r, envelope.NewError(envelope.InputError, app.i18n.T("conversation.resolveWithoutAssignee"), nil))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Update conversation status.
 | 
						// Update conversation status.
 | 
				
			||||||
	if err := app.conversation.UpdateConversationStatus(uuid, 0 /**status_id**/, status, snoozedUntil, user); err != nil {
 | 
						if err := app.conversation.UpdateConversationStatus(uuid, 0 /**status_id**/, status, snoozedUntil, user); err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Evaluate automation rules.
 | 
					 | 
				
			||||||
	app.automation.EvaluateConversationUpdateRules(uuid, models.EventConversationStatusChange)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// If status is `Resolved`, send CSAT survey if enabled on inbox.
 | 
					 | 
				
			||||||
	if status == cmodels.StatusResolved {
 | 
					 | 
				
			||||||
		// Check if CSAT is enabled on the inbox and send CSAT survey message.
 | 
					 | 
				
			||||||
		inbox, err := app.inbox.GetDBRecord(conversation.InboxID)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return sendErrorEnvelope(r, err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if inbox.CSATEnabled {
 | 
					 | 
				
			||||||
			if err := app.conversation.SendCSATReply(user.ID, *conversation); err != nil {
 | 
					 | 
				
			||||||
				return sendErrorEnvelope(r, err)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -453,17 +486,18 @@ func handleUpdateConversationStatus(r *fastglue.Request) error {
 | 
				
			|||||||
func handleUpdateConversationtags(r *fastglue.Request) error {
 | 
					func handleUpdateConversationtags(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		app   = r.Context.(*App)
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
		tagNames = []string{}
 | 
					 | 
				
			||||||
		tagJSON  = r.RequestCtx.PostArgs().Peek("tags")
 | 
					 | 
				
			||||||
		auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
							auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
				
			||||||
		uuid  = r.RequestCtx.UserValue("uuid").(string)
 | 
							uuid  = r.RequestCtx.UserValue("uuid").(string)
 | 
				
			||||||
 | 
							req   = tagsUpdateReq{}
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := json.Unmarshal(tagJSON, &tagNames); err != nil {
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
		app.lo.Error("error unmarshalling tags JSON", "error", err)
 | 
							app.lo.Error("error decoding tags update request", "error", err)
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tagNames := req.Tags
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	user, err := app.user.GetAgent(auser.ID, "")
 | 
						user, err := app.user.GetAgent(auser.ID, "")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
@@ -531,36 +565,14 @@ func handleUpdateContactCustomAttributes(r *fastglue.Request) error {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := app.user.UpdateCustomAttributes(conversation.ContactID, attributes); err != nil {
 | 
						if err := app.user.SaveCustomAttributes(conversation.ContactID, attributes, false); err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// Broadcast update.
 | 
				
			||||||
 | 
						app.conversation.BroadcastConversationUpdate(conversation.UUID, "contact.custom_attributes", attributes)
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleDashboardCounts retrieves general dashboard counts for all users.
 | 
					 | 
				
			||||||
func handleDashboardCounts(r *fastglue.Request) error {
 | 
					 | 
				
			||||||
	var (
 | 
					 | 
				
			||||||
		app = r.Context.(*App)
 | 
					 | 
				
			||||||
	)
 | 
					 | 
				
			||||||
	counts, err := app.conversation.GetDashboardCounts(0, 0)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return r.SendEnvelope(counts)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// handleDashboardCharts retrieves general dashboard chart data.
 | 
					 | 
				
			||||||
func handleDashboardCharts(r *fastglue.Request) error {
 | 
					 | 
				
			||||||
	var (
 | 
					 | 
				
			||||||
		app = r.Context.(*App)
 | 
					 | 
				
			||||||
	)
 | 
					 | 
				
			||||||
	charts, err := app.conversation.GetDashboardChart(0, 0)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return r.SendEnvelope(charts)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// enforceConversationAccess fetches the conversation and checks if the user has access to it.
 | 
					// enforceConversationAccess fetches the conversation and checks if the user has access to it.
 | 
				
			||||||
func enforceConversationAccess(app *App, uuid string, user umodels.User) (*cmodels.Conversation, error) {
 | 
					func enforceConversationAccess(app *App, uuid string, user umodels.User) (*cmodels.Conversation, error) {
 | 
				
			||||||
	conversation, err := app.conversation.GetConversation(0, uuid)
 | 
						conversation, err := app.conversation.GetConversation(0, uuid)
 | 
				
			||||||
@@ -592,7 +604,7 @@ func handleRemoveUserAssignee(r *fastglue.Request) error {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err = app.conversation.RemoveConversationAssignee(uuid, "user"); err != nil {
 | 
						if err = app.conversation.RemoveConversationAssignee(uuid, "user", user); err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
@@ -613,7 +625,7 @@ func handleRemoveTeamAssignee(r *fastglue.Request) error {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err = app.conversation.RemoveConversationAssignee(uuid, "team"); err != nil {
 | 
						if err = app.conversation.RemoveConversationAssignee(uuid, "team", user); err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
@@ -634,34 +646,30 @@ func handleCreateConversation(r *fastglue.Request) error {
 | 
				
			|||||||
	var (
 | 
						var (
 | 
				
			||||||
		app   = r.Context.(*App)
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
		auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
							auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
				
			||||||
		inboxID         = r.RequestCtx.PostArgs().GetUintOrZero("inbox_id")
 | 
							req   = createConversationRequest{}
 | 
				
			||||||
		assignedAgentID = r.RequestCtx.PostArgs().GetUintOrZero("agent_id")
 | 
					 | 
				
			||||||
		assignedTeamID  = r.RequestCtx.PostArgs().GetUintOrZero("team_id")
 | 
					 | 
				
			||||||
		email           = strings.TrimSpace(string(r.RequestCtx.PostArgs().Peek("contact_email")))
 | 
					 | 
				
			||||||
		firstName       = strings.TrimSpace(string(r.RequestCtx.PostArgs().Peek("first_name")))
 | 
					 | 
				
			||||||
		lastName        = strings.TrimSpace(string(r.RequestCtx.PostArgs().Peek("last_name")))
 | 
					 | 
				
			||||||
		subject         = strings.TrimSpace(string(r.RequestCtx.PostArgs().Peek("subject")))
 | 
					 | 
				
			||||||
		content         = strings.TrimSpace(string(r.RequestCtx.PostArgs().Peek("content")))
 | 
					 | 
				
			||||||
		to              = []string{email}
 | 
					 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							app.lo.Error("error decoding create conversation request", "error", err)
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						to := []string{req.Email}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Validate required fields
 | 
						// Validate required fields
 | 
				
			||||||
	if inboxID <= 0 {
 | 
						if req.InboxID <= 0 {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.fieldRequired", "name", "`inbox_id`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.required", "name", "`inbox_id`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if subject == "" {
 | 
						if req.Content == "" {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.fieldRequired", "name", "`subject`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.required", "name", "`content`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if content == "" {
 | 
						if req.Email == "" {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.fieldRequired", "name", "`content`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.required", "name", "`contact_email`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if email == "" {
 | 
						if req.FirstName == "" {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.fieldRequired", "name", "`contact_email`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.required", "name", "`first_name`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if firstName == "" {
 | 
						if !stringutil.ValidEmail(req.Email) {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.fieldRequired", "name", "`first_name`"), nil, envelope.InputError)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if !stringutil.ValidEmail(email) {
 | 
					 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`contact_email`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`contact_email`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -671,7 +679,7 @@ func handleCreateConversation(r *fastglue.Request) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check if inbox exists and is enabled.
 | 
						// Check if inbox exists and is enabled.
 | 
				
			||||||
	inbox, err := app.inbox.GetDBRecord(inboxID)
 | 
						inbox, err := app.inbox.GetDBRecord(req.InboxID)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -681,11 +689,9 @@ func handleCreateConversation(r *fastglue.Request) error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Find or create contact.
 | 
						// Find or create contact.
 | 
				
			||||||
	contact := umodels.User{
 | 
						contact := umodels.User{
 | 
				
			||||||
		Email:           null.StringFrom(email),
 | 
							Email:     null.StringFrom(req.Email),
 | 
				
			||||||
		SourceChannelID: null.StringFrom(email),
 | 
							FirstName: req.FirstName,
 | 
				
			||||||
		FirstName:       firstName,
 | 
							LastName:  req.LastName,
 | 
				
			||||||
		LastName:        lastName,
 | 
					 | 
				
			||||||
		InboxID:         inboxID,
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := app.user.CreateContact(&contact); err != nil {
 | 
						if err := app.user.CreateContact(&contact); err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, envelope.NewError(envelope.GeneralError, app.i18n.Ts("globals.messages.errorCreating", "name", "{globals.terms.contact}"), nil))
 | 
							return sendErrorEnvelope(r, envelope.NewError(envelope.GeneralError, app.i18n.Ts("globals.messages.errorCreating", "name", "{globals.terms.contact}"), nil))
 | 
				
			||||||
@@ -694,11 +700,10 @@ func handleCreateConversation(r *fastglue.Request) error {
 | 
				
			|||||||
	// Create conversation
 | 
						// Create conversation
 | 
				
			||||||
	conversationID, conversationUUID, err := app.conversation.CreateConversation(
 | 
						conversationID, conversationUUID, err := app.conversation.CreateConversation(
 | 
				
			||||||
		contact.ID,
 | 
							contact.ID,
 | 
				
			||||||
		contact.ContactChannelID,
 | 
							req.InboxID,
 | 
				
			||||||
		inboxID,
 | 
					 | 
				
			||||||
		"",         /** last_message **/
 | 
							"",         /** last_message **/
 | 
				
			||||||
		time.Now(), /** last_message_at **/
 | 
							time.Now(), /** last_message_at **/
 | 
				
			||||||
		subject,
 | 
							req.Subject,
 | 
				
			||||||
		true, /** append reference number to subject **/
 | 
							true, /** append reference number to subject **/
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -706,8 +711,19 @@ func handleCreateConversation(r *fastglue.Request) error {
 | 
				
			|||||||
		return sendErrorEnvelope(r, envelope.NewError(envelope.GeneralError, app.i18n.Ts("globals.messages.errorCreating", "name", "{globals.terms.conversation}"), nil))
 | 
							return sendErrorEnvelope(r, envelope.NewError(envelope.GeneralError, app.i18n.Ts("globals.messages.errorCreating", "name", "{globals.terms.conversation}"), nil))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Prepare attachments.
 | 
				
			||||||
 | 
						var media = make([]medModels.Media, 0, len(req.Attachments))
 | 
				
			||||||
 | 
						for _, id := range req.Attachments {
 | 
				
			||||||
 | 
							m, err := app.media.Get(id, "")
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								app.lo.Error("error fetching media", "error", err)
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.errorFetching", "name", "{globals.terms.media}"), nil, envelope.GeneralError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							media = append(media, m)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Send reply to the created conversation.
 | 
						// Send reply to the created conversation.
 | 
				
			||||||
	if err := app.conversation.SendReply(nil /**media**/, inboxID, auser.ID /**sender_id**/, conversationUUID, content, to, nil /**cc**/, nil /**bcc**/, map[string]any{} /**meta**/); err != nil {
 | 
						if _, err := app.conversation.SendReply(media, req.InboxID, auser.ID, contact.ID, conversationUUID, req.Content, to, nil /**cc**/, nil /**bcc**/, map[string]any{} /**meta**/); err != nil {
 | 
				
			||||||
		// Delete the conversation if reply fails.
 | 
							// Delete the conversation if reply fails.
 | 
				
			||||||
		if err := app.conversation.DeleteConversation(conversationUUID); err != nil {
 | 
							if err := app.conversation.DeleteConversation(conversationUUID); err != nil {
 | 
				
			||||||
			app.lo.Error("error deleting conversation", "error", err)
 | 
								app.lo.Error("error deleting conversation", "error", err)
 | 
				
			||||||
@@ -716,14 +732,18 @@ func handleCreateConversation(r *fastglue.Request) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Assign the conversation to the agent or team.
 | 
						// Assign the conversation to the agent or team.
 | 
				
			||||||
	if assignedAgentID > 0 {
 | 
						if req.AssignedAgentID > 0 {
 | 
				
			||||||
		app.conversation.UpdateConversationUserAssignee(conversationUUID, assignedAgentID, user)
 | 
							app.conversation.UpdateConversationUserAssignee(conversationUUID, req.AssignedAgentID, user)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if assignedTeamID > 0 {
 | 
						if req.AssignedTeamID > 0 {
 | 
				
			||||||
		app.conversation.UpdateConversationTeamAssignee(conversationUUID, assignedTeamID, user)
 | 
							app.conversation.UpdateConversationTeamAssignee(conversationUUID, req.AssignedTeamID, user)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Trigger webhook event for conversation created.
 | 
				
			||||||
 | 
						conversation, err := app.conversation.GetConversation(conversationID, "")
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							app.webhook.TriggerEvent(wmodels.EventConversationCreated, conversation)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Send the created conversation back to the client.
 | 
					 | 
				
			||||||
	conversation, _ := app.conversation.GetConversation(conversationID, "")
 | 
					 | 
				
			||||||
	return r.SendEnvelope(conversation)
 | 
						return r.SendEnvelope(conversation)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										42
									
								
								cmd/csat.go
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								cmd/csat.go
									
									
									
									
									
								
							@@ -3,9 +3,16 @@ package main
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/envelope"
 | 
				
			||||||
 | 
						"github.com/valyala/fasthttp"
 | 
				
			||||||
	"github.com/zerodha/fastglue"
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type csatResponse struct {
 | 
				
			||||||
 | 
						Rating   int    `json:"rating"`
 | 
				
			||||||
 | 
						Feedback string `json:"feedback"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleShowCSAT renders the CSAT page for a given csat.
 | 
					// handleShowCSAT renders the CSAT page for a given csat.
 | 
				
			||||||
func handleShowCSAT(r *fastglue.Request) error {
 | 
					func handleShowCSAT(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
@@ -72,7 +79,7 @@ func handleUpdateCSATResponse(r *fastglue.Request) error {
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ratingI < 1 || ratingI > 5 {
 | 
						if ratingI < 0 || ratingI > 5 {
 | 
				
			||||||
		return app.tmpl.RenderWebPage(r.RequestCtx, "error", map[string]interface{}{
 | 
							return app.tmpl.RenderWebPage(r.RequestCtx, "error", map[string]interface{}{
 | 
				
			||||||
			"Data": map[string]interface{}{
 | 
								"Data": map[string]interface{}{
 | 
				
			||||||
				"ErrorMessage": "Invalid `rating`",
 | 
									"ErrorMessage": "Invalid `rating`",
 | 
				
			||||||
@@ -103,3 +110,36 @@ func handleUpdateCSATResponse(r *fastglue.Request) error {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleSubmitCSATResponse handles CSAT response submission from the widget API.
 | 
				
			||||||
 | 
					func handleSubmitCSATResponse(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app  = r.Context.(*App)
 | 
				
			||||||
 | 
							uuid = r.RequestCtx.UserValue("uuid").(string)
 | 
				
			||||||
 | 
							req  = csatResponse{}
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, "Invalid JSON", nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if req.Rating < 0 || req.Rating > 5 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, "Rating must be between 0 and 5 (0 means no rating)", nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// At least one of rating or feedback must be provided
 | 
				
			||||||
 | 
						if req.Rating == 0 && req.Feedback == "" {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, "Either rating or feedback must be provided", nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if uuid == "" {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, "Invalid UUID", nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Update CSAT response
 | 
				
			||||||
 | 
						if err := app.csat.UpdateResponse(uuid, req.Rating, req.Feedback); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,22 +28,6 @@ var (
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleGetCustomAttribute retrieves a custom attribute by its ID.
 | 
					 | 
				
			||||||
func handleGetCustomAttribute(r *fastglue.Request) error {
 | 
					 | 
				
			||||||
	var (
 | 
					 | 
				
			||||||
		app = r.Context.(*App)
 | 
					 | 
				
			||||||
	)
 | 
					 | 
				
			||||||
	id, err := strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
					 | 
				
			||||||
	if err != nil || id <= 0 {
 | 
					 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	attribute, err := app.customAttribute.Get(id)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return r.SendEnvelope(attribute)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleGetCustomAttributes retrieves all custom attributes from the database.
 | 
					// handleGetCustomAttributes retrieves all custom attributes from the database.
 | 
				
			||||||
func handleGetCustomAttributes(r *fastglue.Request) error {
 | 
					func handleGetCustomAttributes(r *fastglue.Request) error {
 | 
				
			||||||
@@ -70,10 +54,11 @@ func handleCreateCustomAttribute(r *fastglue.Request) error {
 | 
				
			|||||||
	if err := validateCustomAttribute(app, attribute); err != nil {
 | 
						if err := validateCustomAttribute(app, attribute); err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := app.customAttribute.Create(attribute); err != nil {
 | 
						createdAttr, err := app.customAttribute.Create(attribute)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(createdAttr)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleUpdateCustomAttribute updates an existing custom attribute in the database.
 | 
					// handleUpdateCustomAttribute updates an existing custom attribute in the database.
 | 
				
			||||||
@@ -92,10 +77,11 @@ func handleUpdateCustomAttribute(r *fastglue.Request) error {
 | 
				
			|||||||
	if err := validateCustomAttribute(app, attribute); err != nil {
 | 
						if err := validateCustomAttribute(app, attribute); err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err = app.customAttribute.Update(id, attribute); err != nil {
 | 
						updatedAttr, err := app.customAttribute.Update(id, attribute)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(updatedAttr)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleDeleteCustomAttribute deletes a custom attribute from the database.
 | 
					// handleDeleteCustomAttribute deletes a custom attribute from the database.
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										198
									
								
								cmd/handlers.go
									
									
									
									
									
								
							
							
						
						
									
										198
									
								
								cmd/handlers.go
									
									
									
									
									
								
							@@ -1,12 +1,16 @@
 | 
				
			|||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
	"mime"
 | 
						"mime"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"path"
 | 
						"path"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/envelope"
 | 
						"github.com/abhinavxd/libredesk/internal/envelope"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/httputil"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/inbox/channel/livechat"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/ws"
 | 
						"github.com/abhinavxd/libredesk/internal/ws"
 | 
				
			||||||
	"github.com/valyala/fasthttp"
 | 
						"github.com/valyala/fasthttp"
 | 
				
			||||||
	"github.com/zerodha/fastglue"
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
@@ -15,7 +19,7 @@ import (
 | 
				
			|||||||
// initHandlers initializes the HTTP routes and handlers for the application.
 | 
					// initHandlers initializes the HTTP routes and handlers for the application.
 | 
				
			||||||
func initHandlers(g *fastglue.Fastglue, hub *ws.Hub) {
 | 
					func initHandlers(g *fastglue.Fastglue, hub *ws.Hub) {
 | 
				
			||||||
	// Authentication.
 | 
						// Authentication.
 | 
				
			||||||
	g.POST("/api/v1/login", handleLogin)
 | 
						g.POST("/api/v1/auth/login", handleLogin)
 | 
				
			||||||
	g.GET("/logout", auth(handleLogout))
 | 
						g.GET("/logout", auth(handleLogout))
 | 
				
			||||||
	g.GET("/api/v1/oidc/{id}/login", handleOIDCLogin)
 | 
						g.GET("/api/v1/oidc/{id}/login", handleOIDCLogin)
 | 
				
			||||||
	g.GET("/api/v1/oidc/{id}/finish", handleOIDCCallback)
 | 
						g.GET("/api/v1/oidc/{id}/finish", handleOIDCCallback)
 | 
				
			||||||
@@ -37,7 +41,6 @@ func initHandlers(g *fastglue.Fastglue, hub *ws.Hub) {
 | 
				
			|||||||
	g.GET("/api/v1/oidc/enabled", handleGetAllEnabledOIDC)
 | 
						g.GET("/api/v1/oidc/enabled", handleGetAllEnabledOIDC)
 | 
				
			||||||
	g.GET("/api/v1/oidc", perm(handleGetAllOIDC, "oidc:manage"))
 | 
						g.GET("/api/v1/oidc", perm(handleGetAllOIDC, "oidc:manage"))
 | 
				
			||||||
	g.POST("/api/v1/oidc", perm(handleCreateOIDC, "oidc:manage"))
 | 
						g.POST("/api/v1/oidc", perm(handleCreateOIDC, "oidc:manage"))
 | 
				
			||||||
	g.POST("/api/v1/oidc/test", perm(handleTestOIDC, "oidc:manage"))
 | 
					 | 
				
			||||||
	g.GET("/api/v1/oidc/{id}", perm(handleGetOIDC, "oidc:manage"))
 | 
						g.GET("/api/v1/oidc/{id}", perm(handleGetOIDC, "oidc:manage"))
 | 
				
			||||||
	g.PUT("/api/v1/oidc/{id}", perm(handleUpdateOIDC, "oidc:manage"))
 | 
						g.PUT("/api/v1/oidc/{id}", perm(handleUpdateOIDC, "oidc:manage"))
 | 
				
			||||||
	g.DELETE("/api/v1/oidc/{id}", perm(handleDeleteOIDC, "oidc:manage"))
 | 
						g.DELETE("/api/v1/oidc/{id}", perm(handleDeleteOIDC, "oidc:manage"))
 | 
				
			||||||
@@ -90,6 +93,20 @@ func initHandlers(g *fastglue.Fastglue, hub *ws.Hub) {
 | 
				
			|||||||
	g.PUT("/api/v1/tags/{id}", perm(handleUpdateTag, "tags:manage"))
 | 
						g.PUT("/api/v1/tags/{id}", perm(handleUpdateTag, "tags:manage"))
 | 
				
			||||||
	g.DELETE("/api/v1/tags/{id}", perm(handleDeleteTag, "tags:manage"))
 | 
						g.DELETE("/api/v1/tags/{id}", perm(handleDeleteTag, "tags:manage"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// AI Assistants.
 | 
				
			||||||
 | 
						g.GET("/api/v1/ai-assistants", perm(handleGetAIAssistants, "ai:manage"))
 | 
				
			||||||
 | 
						g.GET("/api/v1/ai-assistants/{id}", perm(handleGetAIAssistant, "ai:manage"))
 | 
				
			||||||
 | 
						g.POST("/api/v1/ai-assistants", perm(handleCreateAIAssistant, "ai:manage"))
 | 
				
			||||||
 | 
						g.PUT("/api/v1/ai-assistants/{id}", perm(handleUpdateAIAssistant, "ai:manage"))
 | 
				
			||||||
 | 
						g.DELETE("/api/v1/ai-assistants/{id}", perm(handleDeleteAIAssistant, "ai:manage"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// AI Snippets.
 | 
				
			||||||
 | 
						g.GET("/api/v1/ai-snippets", perm(handleGetAISnippets, "ai:manage"))
 | 
				
			||||||
 | 
						g.GET("/api/v1/ai-snippets/{id}", perm(handleGetAISnippet, "ai:manage"))
 | 
				
			||||||
 | 
						g.POST("/api/v1/ai-snippets", perm(handleCreateAISnippet, "ai:manage"))
 | 
				
			||||||
 | 
						g.PUT("/api/v1/ai-snippets/{id}", perm(handleUpdateAISnippet, "ai:manage"))
 | 
				
			||||||
 | 
						g.DELETE("/api/v1/ai-snippets/{id}", perm(handleDeleteAISnippet, "ai:manage"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Macros.
 | 
						// Macros.
 | 
				
			||||||
	g.GET("/api/v1/macros", auth(handleGetMacros))
 | 
						g.GET("/api/v1/macros", auth(handleGetMacros))
 | 
				
			||||||
	g.GET("/api/v1/macros/{id}", perm(handleGetMacro, "macros:manage"))
 | 
						g.GET("/api/v1/macros/{id}", perm(handleGetMacro, "macros:manage"))
 | 
				
			||||||
@@ -111,6 +128,8 @@ func initHandlers(g *fastglue.Fastglue, hub *ws.Hub) {
 | 
				
			|||||||
	g.POST("/api/v1/agents", perm(handleCreateAgent, "users:manage"))
 | 
						g.POST("/api/v1/agents", perm(handleCreateAgent, "users:manage"))
 | 
				
			||||||
	g.PUT("/api/v1/agents/{id}", perm(handleUpdateAgent, "users:manage"))
 | 
						g.PUT("/api/v1/agents/{id}", perm(handleUpdateAgent, "users:manage"))
 | 
				
			||||||
	g.DELETE("/api/v1/agents/{id}", perm(handleDeleteAgent, "users:manage"))
 | 
						g.DELETE("/api/v1/agents/{id}", perm(handleDeleteAgent, "users:manage"))
 | 
				
			||||||
 | 
						g.POST("/api/v1/agents/{id}/api-key", perm(handleGenerateAPIKey, "users:manage"))
 | 
				
			||||||
 | 
						g.DELETE("/api/v1/agents/{id}/api-key", perm(handleRevokeAPIKey, "users:manage"))
 | 
				
			||||||
	g.POST("/api/v1/agents/reset-password", tryAuth(handleResetPassword))
 | 
						g.POST("/api/v1/agents/reset-password", tryAuth(handleResetPassword))
 | 
				
			||||||
	g.POST("/api/v1/agents/set-password", tryAuth(handleSetPassword))
 | 
						g.POST("/api/v1/agents/set-password", tryAuth(handleSetPassword))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -158,9 +177,19 @@ func initHandlers(g *fastglue.Fastglue, hub *ws.Hub) {
 | 
				
			|||||||
	g.PUT("/api/v1/roles/{id}", perm(handleUpdateRole, "roles:manage"))
 | 
						g.PUT("/api/v1/roles/{id}", perm(handleUpdateRole, "roles:manage"))
 | 
				
			||||||
	g.DELETE("/api/v1/roles/{id}", perm(handleDeleteRole, "roles:manage"))
 | 
						g.DELETE("/api/v1/roles/{id}", perm(handleDeleteRole, "roles:manage"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Webhooks.
 | 
				
			||||||
 | 
						g.GET("/api/v1/webhooks", perm(handleGetWebhooks, "webhooks:manage"))
 | 
				
			||||||
 | 
						g.GET("/api/v1/webhooks/{id}", perm(handleGetWebhook, "webhooks:manage"))
 | 
				
			||||||
 | 
						g.POST("/api/v1/webhooks", perm(handleCreateWebhook, "webhooks:manage"))
 | 
				
			||||||
 | 
						g.PUT("/api/v1/webhooks/{id}", perm(handleUpdateWebhook, "webhooks:manage"))
 | 
				
			||||||
 | 
						g.DELETE("/api/v1/webhooks/{id}", perm(handleDeleteWebhook, "webhooks:manage"))
 | 
				
			||||||
 | 
						g.PUT("/api/v1/webhooks/{id}/toggle", perm(handleToggleWebhook, "webhooks:manage"))
 | 
				
			||||||
 | 
						g.POST("/api/v1/webhooks/{id}/test", perm(handleTestWebhook, "webhooks:manage"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Reports.
 | 
						// Reports.
 | 
				
			||||||
	g.GET("/api/v1/reports/overview/counts", perm(handleDashboardCounts, "reports:manage"))
 | 
						g.GET("/api/v1/reports/overview/sla", perm(handleOverviewSLA, "reports:manage"))
 | 
				
			||||||
	g.GET("/api/v1/reports/overview/charts", perm(handleDashboardCharts, "reports:manage"))
 | 
						g.GET("/api/v1/reports/overview/counts", perm(handleOverviewCounts, "reports:manage"))
 | 
				
			||||||
 | 
						g.GET("/api/v1/reports/overview/charts", perm(handleOverviewCharts, "reports:manage"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Templates.
 | 
						// Templates.
 | 
				
			||||||
	g.GET("/api/v1/templates", perm(handleGetTemplates, "templates:manage"))
 | 
						g.GET("/api/v1/templates", perm(handleGetTemplates, "templates:manage"))
 | 
				
			||||||
@@ -191,20 +220,61 @@ func initHandlers(g *fastglue.Fastglue, hub *ws.Hub) {
 | 
				
			|||||||
	// Custom attributes.
 | 
						// Custom attributes.
 | 
				
			||||||
	g.GET("/api/v1/custom-attributes", auth(handleGetCustomAttributes))
 | 
						g.GET("/api/v1/custom-attributes", auth(handleGetCustomAttributes))
 | 
				
			||||||
	g.POST("/api/v1/custom-attributes", perm(handleCreateCustomAttribute, "custom_attributes:manage"))
 | 
						g.POST("/api/v1/custom-attributes", perm(handleCreateCustomAttribute, "custom_attributes:manage"))
 | 
				
			||||||
	g.GET("/api/v1/custom-attributes/{id}", perm(handleGetCustomAttribute, "custom_attributes:manage"))
 | 
					 | 
				
			||||||
	g.PUT("/api/v1/custom-attributes/{id}", perm(handleUpdateCustomAttribute, "custom_attributes:manage"))
 | 
						g.PUT("/api/v1/custom-attributes/{id}", perm(handleUpdateCustomAttribute, "custom_attributes:manage"))
 | 
				
			||||||
	g.DELETE("/api/v1/custom-attributes/{id}", perm(handleDeleteCustomAttribute, "custom_attributes:manage"))
 | 
						g.DELETE("/api/v1/custom-attributes/{id}", perm(handleDeleteCustomAttribute, "custom_attributes:manage"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Actvity logs.
 | 
						// Actvity logs.
 | 
				
			||||||
	g.GET("/api/v1/activity-logs", perm(handleGetActivityLogs, "activity_logs:manage"))
 | 
						g.GET("/api/v1/activity-logs", perm(handleGetActivityLogs, "activity_logs:manage"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Help Centers.
 | 
				
			||||||
 | 
						g.GET("/api/v1/help-centers", auth(handleGetHelpCenters))
 | 
				
			||||||
 | 
						g.GET("/api/v1/help-centers/{id}", auth(handleGetHelpCenter))
 | 
				
			||||||
 | 
						g.GET("/api/v1/help-centers/{id}/tree", auth(handleGetHelpCenterTree))
 | 
				
			||||||
 | 
						g.POST("/api/v1/help-centers", perm(handleCreateHelpCenter, "help_center:manage"))
 | 
				
			||||||
 | 
						g.PUT("/api/v1/help-centers/{id}", perm(handleUpdateHelpCenter, "help_center:manage"))
 | 
				
			||||||
 | 
						g.DELETE("/api/v1/help-centers/{id}", perm(handleDeleteHelpCenter, "help_center:manage"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Collections.
 | 
				
			||||||
 | 
						g.GET("/api/v1/help-centers/{hc_id}/collections", auth(handleGetCollections))
 | 
				
			||||||
 | 
						g.GET("/api/v1/help-centers/{hc_id}/collections/{id}", auth(handleGetCollection))
 | 
				
			||||||
 | 
						g.POST("/api/v1/help-centers/{hc_id}/collections", perm(handleCreateCollection, "help_center:manage"))
 | 
				
			||||||
 | 
						g.PUT("/api/v1/help-centers/{hc_id}/collections/{id}", perm(handleUpdateCollection, "help_center:manage"))
 | 
				
			||||||
 | 
						g.DELETE("/api/v1/help-centers/{hc_id}/collections/{id}", perm(handleDeleteCollection, "help_center:manage"))
 | 
				
			||||||
 | 
						g.PUT("/api/v1/collections/{id}/toggle", perm(handleToggleCollection, "help_center:manage"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Articles.
 | 
				
			||||||
 | 
						g.GET("/api/v1/collections/{col_id}/articles", auth(handleGetArticles))
 | 
				
			||||||
 | 
						g.GET("/api/v1/collections/{col_id}/articles/{id}", auth(handleGetArticle))
 | 
				
			||||||
 | 
						g.POST("/api/v1/collections/{col_id}/articles", perm(handleCreateArticle, "help_center:manage"))
 | 
				
			||||||
 | 
						g.PUT("/api/v1/collections/{col_id}/articles/{id}", perm(handleUpdateArticle, "help_center:manage"))
 | 
				
			||||||
 | 
						g.PUT("/api/v1/articles/{id}", perm(handleUpdateArticleByID, "help_center:manage"))
 | 
				
			||||||
 | 
						g.DELETE("/api/v1/collections/{col_id}/articles/{id}", perm(handleDeleteArticle, "help_center:manage"))
 | 
				
			||||||
 | 
						g.PUT("/api/v1/articles/{id}/status", perm(handleUpdateArticleStatus, "help_center:manage"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// CSAT.
 | 
				
			||||||
 | 
						g.POST("/api/v1/csat/{uuid}/response", handleSubmitCSATResponse)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// WebSocket.
 | 
						// WebSocket.
 | 
				
			||||||
	g.GET("/ws", auth(func(r *fastglue.Request) error {
 | 
						g.GET("/ws", auth(func(r *fastglue.Request) error {
 | 
				
			||||||
		return handleWS(r, hub)
 | 
							return handleWS(r, hub)
 | 
				
			||||||
	}))
 | 
						}))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Live chat widget websocket.
 | 
				
			||||||
 | 
						g.GET("/widget/ws", handleWidgetWS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Widget APIs.
 | 
				
			||||||
 | 
						g.GET("/api/v1/widget/chat/settings/launcher", handleGetChatLauncherSettings)
 | 
				
			||||||
 | 
						g.GET("/api/v1/widget/chat/settings", handleGetChatSettings)
 | 
				
			||||||
 | 
						g.POST("/api/v1/widget/chat/conversations/init", rateLimitWidget(widgetAuth(handleChatInit)))
 | 
				
			||||||
 | 
						g.GET("/api/v1/widget/chat/conversations", rateLimitWidget(widgetAuth(handleGetConversations)))
 | 
				
			||||||
 | 
						g.POST("/api/v1/widget/chat/conversations/{uuid}/update-last-seen", rateLimitWidget(widgetAuth(handleChatUpdateLastSeen)))
 | 
				
			||||||
 | 
						g.GET("/api/v1/widget/chat/conversations/{uuid}", rateLimitWidget(widgetAuth(handleChatGetConversation)))
 | 
				
			||||||
 | 
						g.POST("/api/v1/widget/chat/conversations/{uuid}/message", rateLimitWidget(widgetAuth(handleChatSendMessage)))
 | 
				
			||||||
 | 
						g.POST("/api/v1/widget/media/upload", rateLimitWidget(widgetAuth(handleWidgetMediaUpload)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Frontend pages.
 | 
						// Frontend pages.
 | 
				
			||||||
	g.GET("/", notAuthPage(serveIndexPage))
 | 
						g.GET("/", notAuthPage(serveIndexPage))
 | 
				
			||||||
 | 
						g.GET("/widget", serveWidgetIndexPage)
 | 
				
			||||||
	g.GET("/inboxes/{all:*}", authPage(serveIndexPage))
 | 
						g.GET("/inboxes/{all:*}", authPage(serveIndexPage))
 | 
				
			||||||
	g.GET("/teams/{all:*}", authPage(serveIndexPage))
 | 
						g.GET("/teams/{all:*}", authPage(serveIndexPage))
 | 
				
			||||||
	g.GET("/views/{all:*}", authPage(serveIndexPage))
 | 
						g.GET("/views/{all:*}", authPage(serveIndexPage))
 | 
				
			||||||
@@ -214,8 +284,12 @@ func initHandlers(g *fastglue.Fastglue, hub *ws.Hub) {
 | 
				
			|||||||
	g.GET("/account/{all:*}", authPage(serveIndexPage))
 | 
						g.GET("/account/{all:*}", authPage(serveIndexPage))
 | 
				
			||||||
	g.GET("/reset-password", notAuthPage(serveIndexPage))
 | 
						g.GET("/reset-password", notAuthPage(serveIndexPage))
 | 
				
			||||||
	g.GET("/set-password", notAuthPage(serveIndexPage))
 | 
						g.GET("/set-password", notAuthPage(serveIndexPage))
 | 
				
			||||||
	// FIXME: Don't need three separate routes for the same thing.
 | 
					
 | 
				
			||||||
 | 
						// Assets and static files.
 | 
				
			||||||
 | 
						// FIXME: Reduce the number of routes.
 | 
				
			||||||
 | 
						g.GET("/widget.js", serveWidgetJS)
 | 
				
			||||||
	g.GET("/assets/{all:*}", serveFrontendStaticFiles)
 | 
						g.GET("/assets/{all:*}", serveFrontendStaticFiles)
 | 
				
			||||||
 | 
						g.GET("/widget/assets/{all:*}", serveWidgetStaticFiles)
 | 
				
			||||||
	g.GET("/images/{all:*}", serveFrontendStaticFiles)
 | 
						g.GET("/images/{all:*}", serveFrontendStaticFiles)
 | 
				
			||||||
	g.GET("/static/public/{all:*}", serveStaticFiles)
 | 
						g.GET("/static/public/{all:*}", serveStaticFiles)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -252,6 +326,77 @@ func serveIndexPage(r *fastglue.Request) error {
 | 
				
			|||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// validateWidgetReferer validates the Referer header against trusted domains configured in the live chat inbox settings.
 | 
				
			||||||
 | 
					func validateWidgetReferer(app *App, r *fastglue.Request, inboxID int) error {
 | 
				
			||||||
 | 
						// Get the Referer header from the request
 | 
				
			||||||
 | 
						referer := string(r.RequestCtx.Request.Header.Peek("Referer"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// If no referer header is present, allow direct access.
 | 
				
			||||||
 | 
						if referer == "" {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Get inbox configuration
 | 
				
			||||||
 | 
						inbox, err := app.inbox.GetDBRecord(inboxID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							app.lo.Error("error fetching inbox for referer check", "inbox_id", inboxID, "error", err)
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(http.StatusNotFound, app.i18n.Ts("globals.messages.notFound", "name", "{globals.terms.inbox}"), nil, envelope.NotFoundError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !inbox.Enabled {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(http.StatusBadRequest, app.i18n.Ts("globals.messages.disabled", "name", "{globals.terms.inbox}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Parse the live chat config
 | 
				
			||||||
 | 
						var config livechat.Config
 | 
				
			||||||
 | 
						if err := json.Unmarshal(inbox.Config, &config); err != nil {
 | 
				
			||||||
 | 
							app.lo.Error("error parsing live chat config for referer check", "error", err)
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(http.StatusInternalServerError, app.i18n.Ts("globals.messages.invalid", "name", "{globals.terms.inbox}"), nil, envelope.GeneralError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// If trusted domains list is empty, allow all referers
 | 
				
			||||||
 | 
						if len(config.TrustedDomains) == 0 {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Check if the referer matches any of the trusted domains
 | 
				
			||||||
 | 
						if !httputil.IsOriginTrusted(referer, config.TrustedDomains) {
 | 
				
			||||||
 | 
							app.lo.Warn("widget request from untrusted referer blocked",
 | 
				
			||||||
 | 
								"referer", referer,
 | 
				
			||||||
 | 
								"inbox_id", inboxID,
 | 
				
			||||||
 | 
								"trusted_domains", config.TrustedDomains)
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(http.StatusForbidden, "Widget not allowed from this origin: "+referer, nil, envelope.PermissionError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						app.lo.Debug("widget request from trusted referer allowed", "referer", referer, "inbox_id", inboxID)
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// serveWidgetIndexPage serves the widget index page of the application.
 | 
				
			||||||
 | 
					func serveWidgetIndexPage(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						app := r.Context.(*App)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Extract inbox ID and validate trusted domains if present
 | 
				
			||||||
 | 
						inboxID := r.RequestCtx.QueryArgs().GetUintOrZero("inbox_id")
 | 
				
			||||||
 | 
						if err := validateWidgetReferer(app, r, inboxID); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Prevent caching of the index page.
 | 
				
			||||||
 | 
						r.RequestCtx.Response.Header.Add("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0")
 | 
				
			||||||
 | 
						r.RequestCtx.Response.Header.Add("Pragma", "no-cache")
 | 
				
			||||||
 | 
						r.RequestCtx.Response.Header.Add("Expires", "-1")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Serve the index.html file from the embedded filesystem.
 | 
				
			||||||
 | 
						file, err := app.fs.Get(path.Join(widgetDir, "index.html"))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(http.StatusNotFound, app.i18n.Ts("globals.messages.notFound", "name", "{globals.terms.file}"), nil, envelope.NotFoundError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						r.RequestCtx.Response.Header.Set("Content-Type", "text/html")
 | 
				
			||||||
 | 
						r.RequestCtx.SetBody(file.ReadBytes())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// serveStaticFiles serves static assets from the embedded filesystem.
 | 
					// serveStaticFiles serves static assets from the embedded filesystem.
 | 
				
			||||||
func serveStaticFiles(r *fastglue.Request) error {
 | 
					func serveStaticFiles(r *fastglue.Request) error {
 | 
				
			||||||
	app := r.Context.(*App)
 | 
						app := r.Context.(*App)
 | 
				
			||||||
@@ -300,6 +445,47 @@ func serveFrontendStaticFiles(r *fastglue.Request) error {
 | 
				
			|||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// serveWidgetStaticFiles serves widget static assets from the embedded filesystem.
 | 
				
			||||||
 | 
					func serveWidgetStaticFiles(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						app := r.Context.(*App)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						filePath := string(r.RequestCtx.Path())
 | 
				
			||||||
 | 
						finalPath := filepath.Join(widgetDir, strings.TrimPrefix(filePath, "/widget"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						file, err := app.fs.Get(finalPath)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(http.StatusNotFound, app.i18n.Ts("globals.messages.notFound", "name", "{globals.terms.file}"), nil, envelope.NotFoundError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Set the appropriate Content-Type based on the file extension.
 | 
				
			||||||
 | 
						ext := filepath.Ext(filePath)
 | 
				
			||||||
 | 
						contentType := mime.TypeByExtension(ext)
 | 
				
			||||||
 | 
						if contentType == "" {
 | 
				
			||||||
 | 
							contentType = http.DetectContentType(file.ReadBytes())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						r.RequestCtx.Response.Header.Set("Content-Type", contentType)
 | 
				
			||||||
 | 
						r.RequestCtx.SetBody(file.ReadBytes())
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// serveWidgetJS serves the widget JavaScript file.
 | 
				
			||||||
 | 
					func serveWidgetJS(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						app := r.Context.(*App)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Set appropriate headers for JavaScript
 | 
				
			||||||
 | 
						r.RequestCtx.Response.Header.Set("Content-Type", "application/javascript")
 | 
				
			||||||
 | 
						r.RequestCtx.Response.Header.Set("Cache-Control", "public, max-age=3600") // Cache for 1 hour
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Serve the widget.js file from the embedded filesystem.
 | 
				
			||||||
 | 
						file, err := app.fs.Get("static/widget.js")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(http.StatusNotFound, app.i18n.Ts("globals.messages.notFound", "name", "{globals.terms.file}"), nil, envelope.NotFoundError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						r.RequestCtx.SetBody(file.ReadBytes())
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// sendErrorEnvelope sends a standardized error response to the client.
 | 
					// sendErrorEnvelope sends a standardized error response to the client.
 | 
				
			||||||
func sendErrorEnvelope(r *fastglue.Request, err error) error {
 | 
					func sendErrorEnvelope(r *fastglue.Request, err error) error {
 | 
				
			||||||
	e, ok := err.(envelope.Error)
 | 
						e, ok := err.(envelope.Error)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										548
									
								
								cmd/helpcenter.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										548
									
								
								cmd/helpcenter.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,548 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/envelope"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/helpcenter"
 | 
				
			||||||
 | 
						hcmodels "github.com/abhinavxd/libredesk/internal/helpcenter/models"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/stringutil"
 | 
				
			||||||
 | 
						"github.com/valyala/fasthttp"
 | 
				
			||||||
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Help Centers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleGetHelpCenters returns all help centers from the database.
 | 
				
			||||||
 | 
					func handleGetHelpCenters(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						app := r.Context.(*App)
 | 
				
			||||||
 | 
						helpCenters, err := app.helpcenter.GetAllHelpCenters()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(helpCenters)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleGetHelpCenter returns a specific help center by ID.
 | 
				
			||||||
 | 
					func handleGetHelpCenter(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						helpCenter, err := app.helpcenter.GetHelpCenterByID(id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(helpCenter)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleCreateHelpCenter creates a new help center.
 | 
				
			||||||
 | 
					func handleCreateHelpCenter(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app = r.Context.(*App)
 | 
				
			||||||
 | 
							req = helpcenter.HelpCenterCreateRequest{}
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := validateHelpCenter(r, &req); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						helpCenter, err := app.helpcenter.CreateHelpCenter(req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(helpCenter)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleUpdateHelpCenter updates an existing help center.
 | 
				
			||||||
 | 
					func handleUpdateHelpCenter(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							req   = helpcenter.HelpCenterUpdateRequest{}
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := validateHelpCenter(r, &req); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						helpCenter, err := app.helpcenter.UpdateHelpCenter(id, req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(helpCenter)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleDeleteHelpCenter deletes a help center.
 | 
				
			||||||
 | 
					func handleDeleteHelpCenter(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := app.helpcenter.DeleteHelpCenter(id); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Collections
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleGetCollections returns all collections for a help center.
 | 
				
			||||||
 | 
					func handleGetCollections(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app             = r.Context.(*App)
 | 
				
			||||||
 | 
							helpCenterID, _ = strconv.Atoi(r.RequestCtx.UserValue("hc_id").(string))
 | 
				
			||||||
 | 
							err             error
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if helpCenterID <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`help_center_id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Check for locale filter
 | 
				
			||||||
 | 
						locale := string(r.RequestCtx.QueryArgs().Peek("locale"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var collections []hcmodels.Collection
 | 
				
			||||||
 | 
						if locale != "" {
 | 
				
			||||||
 | 
							collections, err = app.helpcenter.GetCollectionsByHelpCenterAndLocale(helpCenterID, locale)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							collections, err = app.helpcenter.GetCollectionsByHelpCenter(helpCenterID)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(collections)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleGetCollection returns a specific collection by ID.
 | 
				
			||||||
 | 
					func handleGetCollection(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						collection, err := app.helpcenter.GetCollectionByID(id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(collection)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleCreateCollection creates a new collection.
 | 
				
			||||||
 | 
					func handleCreateCollection(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app               = r.Context.(*App)
 | 
				
			||||||
 | 
							req               = helpcenter.CollectionCreateRequest{}
 | 
				
			||||||
 | 
							helpCenterID, err = strconv.Atoi(r.RequestCtx.UserValue("hc_id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if helpCenterID <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`help_center_id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := validateCollection(r, &req); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Generate slug.
 | 
				
			||||||
 | 
						req.Slug = stringutil.GenerateSlug(req.Name, true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						collection, err := app.helpcenter.CreateCollection(helpCenterID, req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(collection)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleUpdateCollection updates an existing collection.
 | 
				
			||||||
 | 
					func handleUpdateCollection(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							req   = helpcenter.CollectionUpdateRequest{}
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := validateCollection(r, &req); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Generate slug
 | 
				
			||||||
 | 
						req.Slug = stringutil.GenerateSlug(req.Name, true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						collection, err := app.helpcenter.UpdateCollection(id, req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(collection)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleDeleteCollection deletes a collection.
 | 
				
			||||||
 | 
					func handleDeleteCollection(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := app.helpcenter.DeleteCollection(id); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleToggleCollection toggles the published status of a collection.
 | 
				
			||||||
 | 
					func handleToggleCollection(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						collection, err := app.helpcenter.ToggleCollectionPublished(id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(collection)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Articles
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleGetArticles returns all articles for a collection.
 | 
				
			||||||
 | 
					func handleGetArticles(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app             = r.Context.(*App)
 | 
				
			||||||
 | 
							collectionID, _ = strconv.Atoi(r.RequestCtx.UserValue("col_id").(string))
 | 
				
			||||||
 | 
							err             error
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if collectionID <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`collection_id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Check for locale filter
 | 
				
			||||||
 | 
						locale := string(r.RequestCtx.QueryArgs().Peek("locale"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var articles []hcmodels.Article
 | 
				
			||||||
 | 
						if locale != "" {
 | 
				
			||||||
 | 
							articles, err = app.helpcenter.GetArticlesByCollectionAndLocale(collectionID, locale)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							articles, err = app.helpcenter.GetArticlesByCollection(collectionID)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(articles)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleGetArticle returns a specific article by ID.
 | 
				
			||||||
 | 
					func handleGetArticle(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						article, err := app.helpcenter.GetArticleByID(id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(article)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleCreateArticle creates a new article.
 | 
				
			||||||
 | 
					func handleCreateArticle(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app             = r.Context.(*App)
 | 
				
			||||||
 | 
							req             = helpcenter.ArticleCreateRequest{}
 | 
				
			||||||
 | 
							collectionID, _ = strconv.Atoi(r.RequestCtx.UserValue("col_id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if collectionID <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`collection_id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := validateArticle(r, &req); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Generate slug
 | 
				
			||||||
 | 
						req.Slug = stringutil.GenerateSlug(req.Title, true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if req.Status == "" {
 | 
				
			||||||
 | 
							req.Status = hcmodels.ArticleStatusDraft
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						article, err := app.helpcenter.CreateArticle(collectionID, req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(article)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleUpdateArticle updates an existing article.
 | 
				
			||||||
 | 
					func handleUpdateArticle(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							req   = helpcenter.ArticleUpdateRequest{}
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := validateArticle(r, &req); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Generate slug
 | 
				
			||||||
 | 
						req.Slug = stringutil.GenerateSlug(req.Title, true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if req.Status == "" {
 | 
				
			||||||
 | 
							req.Status = hcmodels.ArticleStatusDraft
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						article, err := app.helpcenter.UpdateArticle(id, req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(article)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleUpdateArticleByID updates an existing article by its ID (allows collection changes).
 | 
				
			||||||
 | 
					func handleUpdateArticleByID(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							req   = helpcenter.ArticleUpdateRequest{}
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := validateArticle(r, &req); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Generate slug
 | 
				
			||||||
 | 
						req.Slug = stringutil.GenerateSlug(req.Title, true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if req.Status == "" {
 | 
				
			||||||
 | 
							req.Status = hcmodels.ArticleStatusDraft
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						article, err := app.helpcenter.UpdateArticle(id, req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(article)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleDeleteArticle deletes an article.
 | 
				
			||||||
 | 
					func handleDeleteArticle(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := app.helpcenter.DeleteArticle(id); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleUpdateArticleStatus updates the status of an article.
 | 
				
			||||||
 | 
					func handleUpdateArticleStatus(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							req   = helpcenter.UpdateStatusRequest{}
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if req.Status == "" {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`status`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						article, err := app.helpcenter.UpdateArticleStatus(id, req.Status)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(article)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleGetHelpCenterTree returns the complete tree structure for a help center.
 | 
				
			||||||
 | 
					func handleGetHelpCenterTree(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Get locale from query parameter (optional)
 | 
				
			||||||
 | 
						locale := string(r.RequestCtx.QueryArgs().Peek("locale"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tree, err := app.helpcenter.GetHelpCenterTree(id, locale)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(tree)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func validateHelpCenter(r *fastglue.Request, req any) error {
 | 
				
			||||||
 | 
						app := r.Context.(*App)
 | 
				
			||||||
 | 
						switch v := req.(type) {
 | 
				
			||||||
 | 
						case *helpcenter.HelpCenterCreateRequest:
 | 
				
			||||||
 | 
							if v.Name == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if v.Slug == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`slug`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if v.PageTitle == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`page_title`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if v.DefaultLocale == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`default_locale`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						case *helpcenter.HelpCenterUpdateRequest:
 | 
				
			||||||
 | 
							if v.Name == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if v.Slug == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`slug`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if v.PageTitle == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`page_title`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if v.DefaultLocale == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`default_locale`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func validateCollection(r *fastglue.Request, req any) error {
 | 
				
			||||||
 | 
						app := r.Context.(*App)
 | 
				
			||||||
 | 
						switch v := req.(type) {
 | 
				
			||||||
 | 
						case *helpcenter.CollectionCreateRequest:
 | 
				
			||||||
 | 
							if v.Name == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if v.Locale == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`locale`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						case *helpcenter.CollectionUpdateRequest:
 | 
				
			||||||
 | 
							if v.Name == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if v.Locale == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`locale`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func validateArticle(r *fastglue.Request, req any) error {
 | 
				
			||||||
 | 
						app := r.Context.(*App)
 | 
				
			||||||
 | 
						switch v := req.(type) {
 | 
				
			||||||
 | 
						case *helpcenter.ArticleCreateRequest:
 | 
				
			||||||
 | 
							if v.Title == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`title`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if v.Content == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`content`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if v.Locale == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`locale`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						case *helpcenter.ArticleUpdateRequest:
 | 
				
			||||||
 | 
							if v.Title == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`title`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if v.Content == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`content`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if v.Locale == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`locale`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,10 +1,12 @@
 | 
				
			|||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
	"net/mail"
 | 
						"net/mail"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/envelope"
 | 
						"github.com/abhinavxd/libredesk/internal/envelope"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/inbox/channel/livechat"
 | 
				
			||||||
	imodels "github.com/abhinavxd/libredesk/internal/inbox/models"
 | 
						imodels "github.com/abhinavxd/libredesk/internal/inbox/models"
 | 
				
			||||||
	"github.com/valyala/fasthttp"
 | 
						"github.com/valyala/fasthttp"
 | 
				
			||||||
	"github.com/zerodha/fastglue"
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
@@ -47,11 +49,12 @@ func handleCreateInbox(r *fastglue.Request) error {
 | 
				
			|||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), err.Error(), envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), err.Error(), envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := app.inbox.Create(inbox); err != nil {
 | 
						createdInbox, err := app.inbox.Create(inbox)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := validateInbox(app, inbox); err != nil {
 | 
						if err := validateInbox(app, createdInbox); err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -59,7 +62,13 @@ func handleCreateInbox(r *fastglue.Request) error {
 | 
				
			|||||||
		return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.couldNotReload", "name", "{globals.terms.inbox}"), nil, envelope.GeneralError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.couldNotReload", "name", "{globals.terms.inbox}"), nil, envelope.GeneralError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						// Clear passwords before returning.
 | 
				
			||||||
 | 
						if err := createdInbox.ClearPasswords(); err != nil {
 | 
				
			||||||
 | 
							app.lo.Error("error clearing inbox passwords from response", "error", err)
 | 
				
			||||||
 | 
							return envelope.NewError(envelope.GeneralError, app.i18n.Ts("globals.messages.errorFetching", "name", "{globals.terms.inbox}"), nil)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(createdInbox)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleUpdateInbox updates an inbox
 | 
					// handleUpdateInbox updates an inbox
 | 
				
			||||||
@@ -82,7 +91,7 @@ func handleUpdateInbox(r *fastglue.Request) error {
 | 
				
			|||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = app.inbox.Update(id, inbox)
 | 
						updatedInbox, err := app.inbox.Update(id, inbox)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -91,7 +100,13 @@ func handleUpdateInbox(r *fastglue.Request) error {
 | 
				
			|||||||
		return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.couldNotReload", "name", "{globals.terms.inbox}"), nil, envelope.GeneralError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.couldNotReload", "name", "{globals.terms.inbox}"), nil, envelope.GeneralError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope(inbox)
 | 
						// Clear passwords before returning.
 | 
				
			||||||
 | 
						if err := updatedInbox.ClearPasswords(); err != nil {
 | 
				
			||||||
 | 
							app.lo.Error("error clearing inbox passwords from response", "error", err)
 | 
				
			||||||
 | 
							return envelope.NewError(envelope.GeneralError, app.i18n.Ts("globals.messages.errorFetching", "name", "{globals.terms.inbox}"), nil)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(updatedInbox)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleToggleInbox toggles an inbox
 | 
					// handleToggleInbox toggles an inbox
 | 
				
			||||||
@@ -105,7 +120,8 @@ func handleToggleInbox(r *fastglue.Request) error {
 | 
				
			|||||||
			app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
								app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err = app.inbox.Toggle(id); err != nil {
 | 
						toggledInbox, err := app.inbox.Toggle(id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -113,7 +129,13 @@ func handleToggleInbox(r *fastglue.Request) error {
 | 
				
			|||||||
		return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.couldNotReload", "name", "{globals.terms.inbox}"), nil, envelope.GeneralError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.couldNotReload", "name", "{globals.terms.inbox}"), nil, envelope.GeneralError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						// Clear passwords before returning
 | 
				
			||||||
 | 
						if err := toggledInbox.ClearPasswords(); err != nil {
 | 
				
			||||||
 | 
							app.lo.Error("error clearing inbox passwords from response", "error", err)
 | 
				
			||||||
 | 
							return envelope.NewError(envelope.GeneralError, app.i18n.Ts("globals.messages.errorFetching", "name", "{globals.terms.inbox}"), nil)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(toggledInbox)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleDeleteInbox deletes an inbox
 | 
					// handleDeleteInbox deletes an inbox
 | 
				
			||||||
@@ -134,10 +156,12 @@ func handleDeleteInbox(r *fastglue.Request) error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// validateInbox validates the inbox
 | 
					// validateInbox validates the inbox
 | 
				
			||||||
func validateInbox(app *App, inbox imodels.Inbox) error {
 | 
					func validateInbox(app *App, inbox imodels.Inbox) error {
 | 
				
			||||||
	// Validate from address.
 | 
						// Validate from address only for email channels.
 | 
				
			||||||
 | 
						if inbox.Channel == "email" {
 | 
				
			||||||
		if _, err := mail.ParseAddress(inbox.From); err != nil {
 | 
							if _, err := mail.ParseAddress(inbox.From); err != nil {
 | 
				
			||||||
			return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.invalidFromAddress"), nil)
 | 
								return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.invalidFromAddress"), nil)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if len(inbox.Config) == 0 {
 | 
						if len(inbox.Config) == 0 {
 | 
				
			||||||
		return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "config"), nil)
 | 
							return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "config"), nil)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -147,5 +171,17 @@ func validateInbox(app *App, inbox imodels.Inbox) error {
 | 
				
			|||||||
	if inbox.Channel == "" {
 | 
						if inbox.Channel == "" {
 | 
				
			||||||
		return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "channel"), nil)
 | 
							return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "channel"), nil)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Validate livechat-specific configuration
 | 
				
			||||||
 | 
						if inbox.Channel == livechat.ChannelLiveChat {
 | 
				
			||||||
 | 
							var config livechat.Config
 | 
				
			||||||
 | 
							if err := json.Unmarshal(inbox.Config, &config); err == nil {
 | 
				
			||||||
 | 
								// ShowOfficeHoursAfterAssignment cannot be enabled if ShowOfficeHoursInChat is disabled
 | 
				
			||||||
 | 
								if config.ShowOfficeHoursAfterAssignment && !config.ShowOfficeHoursInChat {
 | 
				
			||||||
 | 
									return envelope.NewError(envelope.InputError, "`show_office_hours_after_assignment` cannot be enabled when `show_office_hours_in_chat` is disabled", nil)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										130
									
								
								cmd/init.go
									
									
									
									
									
								
							
							
						
						
									
										130
									
								
								cmd/init.go
									
									
									
									
									
								
							@@ -25,8 +25,10 @@ import (
 | 
				
			|||||||
	"github.com/abhinavxd/libredesk/internal/conversation/status"
 | 
						"github.com/abhinavxd/libredesk/internal/conversation/status"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/csat"
 | 
						"github.com/abhinavxd/libredesk/internal/csat"
 | 
				
			||||||
	customAttribute "github.com/abhinavxd/libredesk/internal/custom_attribute"
 | 
						customAttribute "github.com/abhinavxd/libredesk/internal/custom_attribute"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/helpcenter"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/inbox"
 | 
						"github.com/abhinavxd/libredesk/internal/inbox"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/inbox/channel/email"
 | 
						"github.com/abhinavxd/libredesk/internal/inbox/channel/email"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/inbox/channel/livechat"
 | 
				
			||||||
	imodels "github.com/abhinavxd/libredesk/internal/inbox/models"
 | 
						imodels "github.com/abhinavxd/libredesk/internal/inbox/models"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/macro"
 | 
						"github.com/abhinavxd/libredesk/internal/macro"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/media"
 | 
						"github.com/abhinavxd/libredesk/internal/media"
 | 
				
			||||||
@@ -35,6 +37,8 @@ import (
 | 
				
			|||||||
	notifier "github.com/abhinavxd/libredesk/internal/notification"
 | 
						notifier "github.com/abhinavxd/libredesk/internal/notification"
 | 
				
			||||||
	emailnotifier "github.com/abhinavxd/libredesk/internal/notification/providers/email"
 | 
						emailnotifier "github.com/abhinavxd/libredesk/internal/notification/providers/email"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/oidc"
 | 
						"github.com/abhinavxd/libredesk/internal/oidc"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/ratelimit"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/report"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/role"
 | 
						"github.com/abhinavxd/libredesk/internal/role"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/search"
 | 
						"github.com/abhinavxd/libredesk/internal/search"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/setting"
 | 
						"github.com/abhinavxd/libredesk/internal/setting"
 | 
				
			||||||
@@ -44,6 +48,7 @@ import (
 | 
				
			|||||||
	tmpl "github.com/abhinavxd/libredesk/internal/template"
 | 
						tmpl "github.com/abhinavxd/libredesk/internal/template"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/user"
 | 
						"github.com/abhinavxd/libredesk/internal/user"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/view"
 | 
						"github.com/abhinavxd/libredesk/internal/view"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/webhook"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/ws"
 | 
						"github.com/abhinavxd/libredesk/internal/ws"
 | 
				
			||||||
	"github.com/jmoiron/sqlx"
 | 
						"github.com/jmoiron/sqlx"
 | 
				
			||||||
	"github.com/knadh/go-i18n"
 | 
						"github.com/knadh/go-i18n"
 | 
				
			||||||
@@ -130,7 +135,8 @@ func initConstants() *constants {
 | 
				
			|||||||
// initFS initializes the stuffbin FileSystem.
 | 
					// initFS initializes the stuffbin FileSystem.
 | 
				
			||||||
func initFS() stuffbin.FileSystem {
 | 
					func initFS() stuffbin.FileSystem {
 | 
				
			||||||
	var files = []string{
 | 
						var files = []string{
 | 
				
			||||||
		"frontend/dist",
 | 
							"frontend/dist/main",
 | 
				
			||||||
 | 
							"frontend/dist/widget",
 | 
				
			||||||
		"i18n",
 | 
							"i18n",
 | 
				
			||||||
		"static",
 | 
							"static",
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -219,8 +225,9 @@ func initConversations(
 | 
				
			|||||||
	csat *csat.Manager,
 | 
						csat *csat.Manager,
 | 
				
			||||||
	automationEngine *automation.Engine,
 | 
						automationEngine *automation.Engine,
 | 
				
			||||||
	template *tmpl.Manager,
 | 
						template *tmpl.Manager,
 | 
				
			||||||
 | 
						webhook *webhook.Manager,
 | 
				
			||||||
) *conversation.Manager {
 | 
					) *conversation.Manager {
 | 
				
			||||||
	c, err := conversation.New(hub, i18n, notif, sla, status, priority, inboxStore, userStore, teamStore, mediaStore, settings, csat, automationEngine, template, conversation.Opts{
 | 
						c, err := conversation.New(hub, i18n, notif, sla, status, priority, inboxStore, userStore, teamStore, mediaStore, settings, csat, automationEngine, template, webhook, conversation.Opts{
 | 
				
			||||||
		DB:                       db,
 | 
							DB:                       db,
 | 
				
			||||||
		Lo:                       initLogger("conversation_manager"),
 | 
							Lo:                       initLogger("conversation_manager"),
 | 
				
			||||||
		OutgoingMessageQueueSize: ko.MustInt("message.outgoing_queue_size"),
 | 
							OutgoingMessageQueueSize: ko.MustInt("message.outgoing_queue_size"),
 | 
				
			||||||
@@ -246,6 +253,20 @@ func initTag(db *sqlx.DB, i18n *i18n.I18n) *tag.Manager {
 | 
				
			|||||||
	return mgr
 | 
						return mgr
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// initHelpCenter inits helpcenter manager.
 | 
				
			||||||
 | 
					func initHelpCenter(db *sqlx.DB, i18n *i18n.I18n) *helpcenter.Manager {
 | 
				
			||||||
 | 
						var lo = initLogger("helpcenter_manager")
 | 
				
			||||||
 | 
						mgr, err := helpcenter.New(helpcenter.Opts{
 | 
				
			||||||
 | 
							DB:   db,
 | 
				
			||||||
 | 
							Lo:   lo,
 | 
				
			||||||
 | 
							I18n: i18n,
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Fatalf("error initializing helpcenter: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return mgr
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// initViews inits view manager.
 | 
					// initViews inits view manager.
 | 
				
			||||||
func initView(db *sqlx.DB) *view.Manager {
 | 
					func initView(db *sqlx.DB) *view.Manager {
 | 
				
			||||||
	var lo = initLogger("view_manager")
 | 
						var lo = initLogger("view_manager")
 | 
				
			||||||
@@ -461,6 +482,7 @@ func initMedia(db *sqlx.DB, i18n *i18n.I18n) *media.Manager {
 | 
				
			|||||||
		Lo:     lo,
 | 
							Lo:     lo,
 | 
				
			||||||
		DB:     db,
 | 
							DB:     db,
 | 
				
			||||||
		I18n:   i18n,
 | 
							I18n:   i18n,
 | 
				
			||||||
 | 
							Secret: ko.String("upload.secret"),
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Fatalf("error initializing media: %v", err)
 | 
							log.Fatalf("error initializing media: %v", err)
 | 
				
			||||||
@@ -569,11 +591,41 @@ func initEmailInbox(inboxRecord imodels.Inbox, msgStore inbox.MessageStore, usrS
 | 
				
			|||||||
	return inbox, nil
 | 
						return inbox, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// initLiveChatInbox initializes the live chat inbox.
 | 
				
			||||||
 | 
					func initLiveChatInbox(inboxRecord imodels.Inbox, msgStore inbox.MessageStore, usrStore inbox.UserStore) (inbox.Inbox, error) {
 | 
				
			||||||
 | 
						var config livechat.Config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Load JSON data into Koanf.
 | 
				
			||||||
 | 
						if err := ko.Load(rawbytes.Provider([]byte(inboxRecord.Config)), kjson.Parser()); err != nil {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("loading config: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := ko.UnmarshalWithConf("", &config, koanf.UnmarshalConf{Tag: "json"}); err != nil {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("unmarshalling `%s` %s config: %w", inboxRecord.Channel, inboxRecord.Name, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						inbox, err := livechat.New(msgStore, usrStore, livechat.Opts{
 | 
				
			||||||
 | 
							ID:     inboxRecord.ID,
 | 
				
			||||||
 | 
							Config: config,
 | 
				
			||||||
 | 
							Lo:     initLogger("livechat_inbox"),
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("initializing `%s` inbox: `%s` error : %w", inboxRecord.Channel, inboxRecord.Name, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Printf("`%s` inbox successfully initialized", inboxRecord.Name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return inbox, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// initializeInboxes handles inbox initialization.
 | 
					// initializeInboxes handles inbox initialization.
 | 
				
			||||||
func initializeInboxes(inboxR imodels.Inbox, msgStore inbox.MessageStore, usrStore inbox.UserStore) (inbox.Inbox, error) {
 | 
					func initializeInboxes(inboxR imodels.Inbox, msgStore inbox.MessageStore, usrStore inbox.UserStore) (inbox.Inbox, error) {
 | 
				
			||||||
	switch inboxR.Channel {
 | 
						switch inboxR.Channel {
 | 
				
			||||||
	case "email":
 | 
						case "email":
 | 
				
			||||||
		return initEmailInbox(inboxR, msgStore, usrStore)
 | 
							return initEmailInbox(inboxR, msgStore, usrStore)
 | 
				
			||||||
 | 
						case "livechat":
 | 
				
			||||||
 | 
							return initLiveChatInbox(inboxR, msgStore, usrStore)
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return nil, fmt.Errorf("unknown inbox channel: %s", inboxR.Channel)
 | 
							return nil, fmt.Errorf("unknown inbox channel: %s", inboxR.Channel)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -768,9 +820,39 @@ func initPriority(db *sqlx.DB, i18n *i18n.I18n) *priority.Manager {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// initAI inits AI manager.
 | 
					// initAI inits AI manager.
 | 
				
			||||||
func initAI(db *sqlx.DB, i18n *i18n.I18n) *ai.Manager {
 | 
					func initAI(db *sqlx.DB, i18n *i18n.I18n, conversationStore *conversation.Manager, helpCenterStore *helpcenter.Manager) *ai.Manager {
 | 
				
			||||||
	lo := initLogger("ai")
 | 
						lo := initLogger("ai")
 | 
				
			||||||
	m, err := ai.New(ai.Opts{
 | 
					
 | 
				
			||||||
 | 
						embeddingCfg := ai.EmbeddingConfig{
 | 
				
			||||||
 | 
							Provider: ko.String("ai.embedding.provider"),
 | 
				
			||||||
 | 
							URL:      ko.String("ai.embedding.url"),
 | 
				
			||||||
 | 
							APIKey:   ko.String("ai.embedding.api_key"),
 | 
				
			||||||
 | 
							Model:    ko.String("ai.embedding.model"),
 | 
				
			||||||
 | 
							Timeout:  ko.Duration("ai.embedding.timeout"),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						chunkingCfg := ai.ChunkingConfig{
 | 
				
			||||||
 | 
							MaxTokens:     ko.Int("ai.embedding.chunking.max_tokens"),
 | 
				
			||||||
 | 
							MinTokens:     ko.Int("ai.embedding.chunking.min_tokens"),
 | 
				
			||||||
 | 
							OverlapTokens: ko.Int("ai.embedding.chunking.overlap_tokens"),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						completionCfg := ai.CompletionConfig{
 | 
				
			||||||
 | 
							Provider:    ko.String("ai.completion.provider"),
 | 
				
			||||||
 | 
							URL:         ko.String("ai.completion.url"),
 | 
				
			||||||
 | 
							APIKey:      ko.String("ai.completion.api_key"),
 | 
				
			||||||
 | 
							Model:       ko.String("ai.completion.model"),
 | 
				
			||||||
 | 
							Timeout:     ko.Duration("ai.completion.timeout"),
 | 
				
			||||||
 | 
							MaxTokens:   ko.Int("ai.completion.max_tokens"),
 | 
				
			||||||
 | 
							Temperature: ko.Float64("ai.completion.temperature"),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						workerCfg := ai.WorkerConfig{
 | 
				
			||||||
 | 
							Workers:  ko.Int("ai.worker.workers"),
 | 
				
			||||||
 | 
							Capacity: ko.Int("ai.worker.capacity"),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m, err := ai.New(embeddingCfg, chunkingCfg, completionCfg, workerCfg, conversationStore, helpCenterStore, ai.Opts{
 | 
				
			||||||
		DB:   db,
 | 
							DB:   db,
 | 
				
			||||||
		Lo:   lo,
 | 
							Lo:   lo,
 | 
				
			||||||
		I18n: i18n,
 | 
							I18n: i18n,
 | 
				
			||||||
@@ -823,6 +905,37 @@ func initActivityLog(db *sqlx.DB, i18n *i18n.I18n) *activitylog.Manager {
 | 
				
			|||||||
	return m
 | 
						return m
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// initReport inits report manager.
 | 
				
			||||||
 | 
					func initReport(db *sqlx.DB, i18n *i18n.I18n) *report.Manager {
 | 
				
			||||||
 | 
						lo := initLogger("report")
 | 
				
			||||||
 | 
						m, err := report.New(report.Opts{
 | 
				
			||||||
 | 
							DB:   db,
 | 
				
			||||||
 | 
							Lo:   lo,
 | 
				
			||||||
 | 
							I18n: i18n,
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Fatalf("error initializing report manager: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return m
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// initWebhook inits webhook manager.
 | 
				
			||||||
 | 
					func initWebhook(db *sqlx.DB, i18n *i18n.I18n) *webhook.Manager {
 | 
				
			||||||
 | 
						var lo = initLogger("webhook")
 | 
				
			||||||
 | 
						m, err := webhook.New(webhook.Opts{
 | 
				
			||||||
 | 
							DB:        db,
 | 
				
			||||||
 | 
							Lo:        lo,
 | 
				
			||||||
 | 
							I18n:      i18n,
 | 
				
			||||||
 | 
							Workers:   ko.MustInt("webhook.workers"),
 | 
				
			||||||
 | 
							QueueSize: ko.MustInt("webhook.queue_size"),
 | 
				
			||||||
 | 
							Timeout:   ko.MustDuration("webhook.timeout"),
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Fatalf("error initializing webhook manager: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return m
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// initLogger initializes a logf logger.
 | 
					// initLogger initializes a logf logger.
 | 
				
			||||||
func initLogger(src string) *logf.Logger {
 | 
					func initLogger(src string) *logf.Logger {
 | 
				
			||||||
	lvl, env := ko.MustString("app.log_level"), ko.MustString("app.env")
 | 
						lvl, env := ko.MustString("app.log_level"), ko.MustString("app.env")
 | 
				
			||||||
@@ -860,3 +973,12 @@ func getLogLevel(lvl string) logf.Level {
 | 
				
			|||||||
		return logf.InfoLevel
 | 
							return logf.InfoLevel
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// initRateLimit initializes the rate limiter.
 | 
				
			||||||
 | 
					func initRateLimit(redisClient *redis.Client) *ratelimit.Limiter {
 | 
				
			||||||
 | 
						var config ratelimit.Config
 | 
				
			||||||
 | 
						if err := ko.UnmarshalWithConf("rate_limit", &config, koanf.UnmarshalConf{Tag: "toml"}); err != nil {
 | 
				
			||||||
 | 
							log.Fatalf("error unmarshalling rate limit config: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return ratelimit.New(redisClient, config)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										26
									
								
								cmd/login.go
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								cmd/login.go
									
									
									
									
									
								
							@@ -3,23 +3,35 @@ package main
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	amodels "github.com/abhinavxd/libredesk/internal/auth/models"
 | 
						amodels "github.com/abhinavxd/libredesk/internal/auth/models"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/envelope"
 | 
						"github.com/abhinavxd/libredesk/internal/envelope"
 | 
				
			||||||
	umodels "github.com/abhinavxd/libredesk/internal/user/models"
 | 
					 | 
				
			||||||
	realip "github.com/ferluci/fast-realip"
 | 
						realip "github.com/ferluci/fast-realip"
 | 
				
			||||||
	"github.com/valyala/fasthttp"
 | 
						"github.com/valyala/fasthttp"
 | 
				
			||||||
	"github.com/zerodha/fastglue"
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type loginRequest struct {
 | 
				
			||||||
 | 
						Email    string `json:"email"`
 | 
				
			||||||
 | 
						Password string `json:"password"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleLogin logs in the user and returns the user.
 | 
					// handleLogin logs in the user and returns the user.
 | 
				
			||||||
func handleLogin(r *fastglue.Request) error {
 | 
					func handleLogin(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		app      = r.Context.(*App)
 | 
							app      = r.Context.(*App)
 | 
				
			||||||
		email    = string(r.RequestCtx.PostArgs().Peek("email"))
 | 
					 | 
				
			||||||
		password = r.RequestCtx.PostArgs().Peek("password")
 | 
					 | 
				
			||||||
		ip       = realip.FromRequest(r.RequestCtx)
 | 
							ip       = realip.FromRequest(r.RequestCtx)
 | 
				
			||||||
 | 
							loginReq loginRequest
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Decode JSON request.
 | 
				
			||||||
 | 
						if err := r.Decode(&loginReq, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if loginReq.Email == "" || loginReq.Password == "" {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.T("globals.messages.badRequest"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Verify email and password.
 | 
						// Verify email and password.
 | 
				
			||||||
	user, err := app.user.VerifyPassword(email, password)
 | 
						user, err := app.user.VerifyPassword(loginReq.Email, []byte(loginReq.Password))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -29,12 +41,6 @@ func handleLogin(r *fastglue.Request) error {
 | 
				
			|||||||
		return sendErrorEnvelope(r, envelope.NewError(envelope.GeneralError, app.i18n.T("user.accountDisabled"), nil))
 | 
							return sendErrorEnvelope(r, envelope.NewError(envelope.GeneralError, app.i18n.T("user.accountDisabled"), nil))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Set user availability status to online.
 | 
					 | 
				
			||||||
	if err := app.user.UpdateAvailability(user.ID, umodels.Online); err != nil {
 | 
					 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	user.AvailabilityStatus = umodels.Online
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err := app.auth.SaveSession(amodels.User{
 | 
						if err := app.auth.SaveSession(amodels.User{
 | 
				
			||||||
		ID:        user.ID,
 | 
							ID:        user.ID,
 | 
				
			||||||
		Email:     user.Email.String,
 | 
							Email:     user.Email.String,
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										15
									
								
								cmd/macro.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								cmd/macro.go
									
									
									
									
									
								
							@@ -81,12 +81,12 @@ func handleCreateMacro(r *fastglue.Request) error {
 | 
				
			|||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := app.macro.Create(macro.Name, macro.MessageContent, macro.UserID, macro.TeamID, macro.Visibility, macro.Actions)
 | 
						createdMacro, err := app.macro.Create(macro.Name, macro.MessageContent, macro.UserID, macro.TeamID, macro.Visibility, macro.VisibleWhen, macro.Actions)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope(macro)
 | 
						return r.SendEnvelope(createdMacro)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleUpdateMacro updates a macro.
 | 
					// handleUpdateMacro updates a macro.
 | 
				
			||||||
@@ -110,11 +110,12 @@ func handleUpdateMacro(r *fastglue.Request) error {
 | 
				
			|||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err = app.macro.Update(id, macro.Name, macro.MessageContent, macro.UserID, macro.TeamID, macro.Visibility, macro.Actions); err != nil {
 | 
						updatedMacro, err := app.macro.Update(id, macro.Name, macro.MessageContent, macro.UserID, macro.TeamID, macro.Visibility, macro.VisibleWhen, macro.Actions)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope(macro)
 | 
						return r.SendEnvelope(updatedMacro)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleDeleteMacro deletes macro.
 | 
					// handleDeleteMacro deletes macro.
 | 
				
			||||||
@@ -275,13 +276,17 @@ func validateMacro(app *App, macro models.Macro) error {
 | 
				
			|||||||
		return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil)
 | 
							return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(macro.VisibleWhen) == 0 {
 | 
				
			||||||
 | 
							return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "`visible_when`"), nil)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var act []autoModels.RuleAction
 | 
						var act []autoModels.RuleAction
 | 
				
			||||||
	if err := json.Unmarshal(macro.Actions, &act); err != nil {
 | 
						if err := json.Unmarshal(macro.Actions, &act); err != nil {
 | 
				
			||||||
		return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.macroAction}"), nil)
 | 
							return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.macroAction}"), nil)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for _, a := range act {
 | 
						for _, a := range act {
 | 
				
			||||||
		if len(a.Value) == 0 {
 | 
							if len(a.Value) == 0 {
 | 
				
			||||||
			return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.emptyActionValue", "name", a.Type), nil)
 | 
								return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", a.Type), nil)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										51
									
								
								cmd/main.go
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								cmd/main.go
									
									
									
									
									
								
							@@ -13,6 +13,8 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	_ "time/tzdata"
 | 
						_ "time/tzdata"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_ "github.com/pgvector/pgvector-go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	activitylog "github.com/abhinavxd/libredesk/internal/activity_log"
 | 
						activitylog "github.com/abhinavxd/libredesk/internal/activity_log"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/ai"
 | 
						"github.com/abhinavxd/libredesk/internal/ai"
 | 
				
			||||||
	auth_ "github.com/abhinavxd/libredesk/internal/auth"
 | 
						auth_ "github.com/abhinavxd/libredesk/internal/auth"
 | 
				
			||||||
@@ -21,8 +23,10 @@ import (
 | 
				
			|||||||
	"github.com/abhinavxd/libredesk/internal/colorlog"
 | 
						"github.com/abhinavxd/libredesk/internal/colorlog"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/csat"
 | 
						"github.com/abhinavxd/libredesk/internal/csat"
 | 
				
			||||||
	customAttribute "github.com/abhinavxd/libredesk/internal/custom_attribute"
 | 
						customAttribute "github.com/abhinavxd/libredesk/internal/custom_attribute"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/helpcenter"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/macro"
 | 
						"github.com/abhinavxd/libredesk/internal/macro"
 | 
				
			||||||
	notifier "github.com/abhinavxd/libredesk/internal/notification"
 | 
						notifier "github.com/abhinavxd/libredesk/internal/notification"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/report"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/search"
 | 
						"github.com/abhinavxd/libredesk/internal/search"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/sla"
 | 
						"github.com/abhinavxd/libredesk/internal/sla"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/view"
 | 
						"github.com/abhinavxd/libredesk/internal/view"
 | 
				
			||||||
@@ -34,12 +38,14 @@ import (
 | 
				
			|||||||
	"github.com/abhinavxd/libredesk/internal/inbox"
 | 
						"github.com/abhinavxd/libredesk/internal/inbox"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/media"
 | 
						"github.com/abhinavxd/libredesk/internal/media"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/oidc"
 | 
						"github.com/abhinavxd/libredesk/internal/oidc"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/ratelimit"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/role"
 | 
						"github.com/abhinavxd/libredesk/internal/role"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/setting"
 | 
						"github.com/abhinavxd/libredesk/internal/setting"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/tag"
 | 
						"github.com/abhinavxd/libredesk/internal/tag"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/team"
 | 
						"github.com/abhinavxd/libredesk/internal/team"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/template"
 | 
						"github.com/abhinavxd/libredesk/internal/template"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/user"
 | 
						"github.com/abhinavxd/libredesk/internal/user"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/webhook"
 | 
				
			||||||
	"github.com/knadh/go-i18n"
 | 
						"github.com/knadh/go-i18n"
 | 
				
			||||||
	"github.com/knadh/koanf/v2"
 | 
						"github.com/knadh/koanf/v2"
 | 
				
			||||||
	"github.com/knadh/stuffbin"
 | 
						"github.com/knadh/stuffbin"
 | 
				
			||||||
@@ -52,7 +58,8 @@ var (
 | 
				
			|||||||
	ko          = koanf.New(".")
 | 
						ko          = koanf.New(".")
 | 
				
			||||||
	ctx         = context.Background()
 | 
						ctx         = context.Background()
 | 
				
			||||||
	appName     = "libredesk"
 | 
						appName     = "libredesk"
 | 
				
			||||||
	frontendDir = "frontend/dist"
 | 
						frontendDir = "frontend/dist/main"
 | 
				
			||||||
 | 
						widgetDir   = "frontend/dist/widget"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Injected at build time.
 | 
						// Injected at build time.
 | 
				
			||||||
	buildString   string
 | 
						buildString   string
 | 
				
			||||||
@@ -90,6 +97,10 @@ type App struct {
 | 
				
			|||||||
	activityLog     *activitylog.Manager
 | 
						activityLog     *activitylog.Manager
 | 
				
			||||||
	notifier        *notifier.Service
 | 
						notifier        *notifier.Service
 | 
				
			||||||
	customAttribute *customAttribute.Manager
 | 
						customAttribute *customAttribute.Manager
 | 
				
			||||||
 | 
						report          *report.Manager
 | 
				
			||||||
 | 
						webhook         *webhook.Manager
 | 
				
			||||||
 | 
						rateLimit       *ratelimit.Limiter
 | 
				
			||||||
 | 
						helpcenter      *helpcenter.Manager
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Global state that stores data on an available app update.
 | 
						// Global state that stores data on an available app update.
 | 
				
			||||||
	update *AppUpdate
 | 
						update *AppUpdate
 | 
				
			||||||
@@ -157,13 +168,23 @@ func main() {
 | 
				
			|||||||
	settings := initSettings(db)
 | 
						settings := initSettings(db)
 | 
				
			||||||
	loadSettings(settings)
 | 
						loadSettings(settings)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Fallback for config typo. Logs a warning but continues to work with the incorrect key.
 | 
				
			||||||
 | 
						// Uses 'message.message_outgoing_scan_interval' (correct key) as default key, falls back to the common typo.
 | 
				
			||||||
 | 
						msgOutgoingScanIntervalKey := "message.message_outgoing_scan_interval"
 | 
				
			||||||
 | 
						if ko.String(msgOutgoingScanIntervalKey) == "" {
 | 
				
			||||||
 | 
							if ko.String("message.message_outoing_scan_interval") != "" {
 | 
				
			||||||
 | 
								colorlog.Red("WARNING: typo in config key 'message.message_outoing_scan_interval' detected. Use 'message.message_outgoing_scan_interval' instead in your config.toml file. Support for this incorrect key will be removed in a future release.")
 | 
				
			||||||
 | 
								msgOutgoingScanIntervalKey = "message.message_outoing_scan_interval"
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		autoAssignInterval          = ko.MustDuration("autoassigner.autoassign_interval")
 | 
							autoAssignInterval          = ko.MustDuration("autoassigner.autoassign_interval")
 | 
				
			||||||
		unsnoozeInterval            = ko.MustDuration("conversation.unsnooze_interval")
 | 
							unsnoozeInterval            = ko.MustDuration("conversation.unsnooze_interval")
 | 
				
			||||||
		automationWorkers           = ko.MustInt("automation.worker_count")
 | 
							automationWorkers           = ko.MustInt("automation.worker_count")
 | 
				
			||||||
		messageOutgoingQWorkers     = ko.MustDuration("message.outgoing_queue_workers")
 | 
							messageOutgoingQWorkers     = ko.MustDuration("message.outgoing_queue_workers")
 | 
				
			||||||
		messageIncomingQWorkers     = ko.MustDuration("message.incoming_queue_workers")
 | 
							messageIncomingQWorkers     = ko.MustDuration("message.incoming_queue_workers")
 | 
				
			||||||
		messageOutgoingScanInterval = ko.MustDuration("message.message_outoing_scan_interval")
 | 
							messageOutgoingScanInterval = ko.MustDuration(msgOutgoingScanIntervalKey)
 | 
				
			||||||
		slaEvaluationInterval       = ko.MustDuration("sla.evaluation_interval")
 | 
							slaEvaluationInterval       = ko.MustDuration("sla.evaluation_interval")
 | 
				
			||||||
		lo                          = initLogger(appName)
 | 
							lo                          = initLogger(appName)
 | 
				
			||||||
		rdb                         = initRedis()
 | 
							rdb                         = initRedis()
 | 
				
			||||||
@@ -179,26 +200,38 @@ func main() {
 | 
				
			|||||||
		inbox                       = initInbox(db, i18n)
 | 
							inbox                       = initInbox(db, i18n)
 | 
				
			||||||
		team                        = initTeam(db, i18n)
 | 
							team                        = initTeam(db, i18n)
 | 
				
			||||||
		businessHours               = initBusinessHours(db, i18n)
 | 
							businessHours               = initBusinessHours(db, i18n)
 | 
				
			||||||
 | 
							webhook                     = initWebhook(db, i18n)
 | 
				
			||||||
		user                        = initUser(i18n, db)
 | 
							user                        = initUser(i18n, db)
 | 
				
			||||||
		wsHub                       = initWS(user)
 | 
							wsHub                       = initWS(user)
 | 
				
			||||||
		notifier                    = initNotifier()
 | 
							notifier                    = initNotifier()
 | 
				
			||||||
		automation                  = initAutomationEngine(db, i18n)
 | 
							automation                  = initAutomationEngine(db, i18n)
 | 
				
			||||||
		sla                         = initSLA(db, team, settings, businessHours, notifier, template, user, i18n)
 | 
							sla                         = initSLA(db, team, settings, businessHours, notifier, template, user, i18n)
 | 
				
			||||||
		conversation                = initConversations(i18n, sla, status, priority, wsHub, notifier, db, inbox, user, team, media, settings, csat, automation, template)
 | 
							conversation                = initConversations(i18n, sla, status, priority, wsHub, notifier, db, inbox, user, team, media, settings, csat, automation, template, webhook)
 | 
				
			||||||
		autoassigner                = initAutoAssigner(team, user, conversation)
 | 
							autoassigner                = initAutoAssigner(team, user, conversation)
 | 
				
			||||||
 | 
							rateLimiter                 = initRateLimit(rdb)
 | 
				
			||||||
 | 
							helpcenter                  = initHelpCenter(db, i18n)
 | 
				
			||||||
 | 
							ai                          = initAI(db, i18n, conversation, helpcenter)
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	automation.SetConversationStore(conversation)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						wsHub.SetConversationStore(conversation)
 | 
				
			||||||
 | 
						automation.SetConversationStore(conversation)
 | 
				
			||||||
 | 
						conversation.SetAIStore(ai)
 | 
				
			||||||
 | 
						helpcenter.SetAIStore(ai)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Start inboxes.
 | 
				
			||||||
	startInboxes(ctx, inbox, conversation, user)
 | 
						startInboxes(ctx, inbox, conversation, user)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	go automation.Run(ctx, automationWorkers)
 | 
						go automation.Run(ctx, automationWorkers)
 | 
				
			||||||
	go autoassigner.Run(ctx, autoAssignInterval)
 | 
						go autoassigner.Run(ctx, autoAssignInterval)
 | 
				
			||||||
	go conversation.Run(ctx, messageIncomingQWorkers, messageOutgoingQWorkers, messageOutgoingScanInterval)
 | 
						go conversation.Run(ctx, messageIncomingQWorkers, messageOutgoingQWorkers, messageOutgoingScanInterval)
 | 
				
			||||||
	go conversation.RunUnsnoozer(ctx, unsnoozeInterval)
 | 
						go conversation.RunUnsnoozer(ctx, unsnoozeInterval)
 | 
				
			||||||
 | 
						go webhook.Run(ctx)
 | 
				
			||||||
	go notifier.Run(ctx)
 | 
						go notifier.Run(ctx)
 | 
				
			||||||
	go sla.Run(ctx, slaEvaluationInterval)
 | 
						go sla.Run(ctx, slaEvaluationInterval)
 | 
				
			||||||
	go sla.SendNotifications(ctx)
 | 
						go sla.SendNotifications(ctx)
 | 
				
			||||||
	go media.DeleteUnlinkedMedia(ctx)
 | 
						go media.DeleteUnlinkedMedia(ctx)
 | 
				
			||||||
	go user.MonitorAgentAvailability(ctx)
 | 
						go user.MonitorAgentAvailability(ctx)
 | 
				
			||||||
 | 
						go ai.StartConversationCompletions()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var app = &App{
 | 
						var app = &App{
 | 
				
			||||||
		lo:              lo,
 | 
							lo:              lo,
 | 
				
			||||||
@@ -224,12 +257,16 @@ func main() {
 | 
				
			|||||||
		customAttribute: initCustomAttribute(db, i18n),
 | 
							customAttribute: initCustomAttribute(db, i18n),
 | 
				
			||||||
		authz:           initAuthz(i18n),
 | 
							authz:           initAuthz(i18n),
 | 
				
			||||||
		view:            initView(db),
 | 
							view:            initView(db),
 | 
				
			||||||
 | 
							report:          initReport(db, i18n),
 | 
				
			||||||
		csat:            initCSAT(db, i18n),
 | 
							csat:            initCSAT(db, i18n),
 | 
				
			||||||
		search:          initSearch(db, i18n),
 | 
							search:          initSearch(db, i18n),
 | 
				
			||||||
		role:            initRole(db, i18n),
 | 
							role:            initRole(db, i18n),
 | 
				
			||||||
		tag:             initTag(db, i18n),
 | 
							tag:             initTag(db, i18n),
 | 
				
			||||||
		macro:           initMacro(db, i18n),
 | 
							macro:           initMacro(db, i18n),
 | 
				
			||||||
		ai:              initAI(db, i18n),
 | 
							ai:              ai,
 | 
				
			||||||
 | 
							webhook:         webhook,
 | 
				
			||||||
 | 
							rateLimit:       rateLimiter,
 | 
				
			||||||
 | 
							helpcenter:      helpcenter,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	app.consts.Store(constants)
 | 
						app.consts.Store(constants)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -273,8 +310,12 @@ func main() {
 | 
				
			|||||||
	autoassigner.Close()
 | 
						autoassigner.Close()
 | 
				
			||||||
	colorlog.Red("Shutting down notifier...")
 | 
						colorlog.Red("Shutting down notifier...")
 | 
				
			||||||
	notifier.Close()
 | 
						notifier.Close()
 | 
				
			||||||
 | 
						colorlog.Red("Shutting down webhook...")
 | 
				
			||||||
 | 
						webhook.Close()
 | 
				
			||||||
	colorlog.Red("Shutting down conversation...")
 | 
						colorlog.Red("Shutting down conversation...")
 | 
				
			||||||
	conversation.Close()
 | 
						conversation.Close()
 | 
				
			||||||
 | 
						colorlog.Red("Shutting down AI...")
 | 
				
			||||||
 | 
						app.ai.StopConversationCompletions()
 | 
				
			||||||
	colorlog.Red("Shutting down SLA...")
 | 
						colorlog.Red("Shutting down SLA...")
 | 
				
			||||||
	sla.Close()
 | 
						sla.Close()
 | 
				
			||||||
	colorlog.Red("Shutting down database...")
 | 
						colorlog.Red("Shutting down database...")
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										10
									
								
								cmd/media.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								cmd/media.go
									
									
									
									
									
								
							@@ -143,14 +143,18 @@ func handleMediaUpload(r *fastglue.Request) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleServeMedia serves uploaded media.
 | 
					// handleServeMedia serves uploaded media.
 | 
				
			||||||
 | 
					// Supports both authenticated agent access and unauthenticated access via signed URLs.
 | 
				
			||||||
func handleServeMedia(r *fastglue.Request) error {
 | 
					func handleServeMedia(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		app  = r.Context.(*App)
 | 
							app  = r.Context.(*App)
 | 
				
			||||||
		auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
					 | 
				
			||||||
		uuid = r.RequestCtx.UserValue("uuid").(string)
 | 
							uuid = r.RequestCtx.UserValue("uuid").(string)
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	user, err := app.user.GetAgent(auser.ID, "")
 | 
						// Check if user is authenticated (agent access)
 | 
				
			||||||
 | 
						auser := r.RequestCtx.UserValue("user")
 | 
				
			||||||
 | 
						if auser != nil {
 | 
				
			||||||
 | 
							// Authenticated.
 | 
				
			||||||
 | 
							user, err := app.user.GetAgent(auser.(amodels.User).ID, "")
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return sendErrorEnvelope(r, err)
 | 
								return sendErrorEnvelope(r, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -182,6 +186,8 @@ func handleServeMedia(r *fastglue.Request) error {
 | 
				
			|||||||
		if !allowed {
 | 
							if !allowed {
 | 
				
			||||||
			return r.SendErrorEnvelope(http.StatusUnauthorized, app.i18n.Ts("globals.messages.denied", "name", "{globals.terms.permission}"), nil, envelope.UnauthorizedError)
 | 
								return r.SendErrorEnvelope(http.StatusUnauthorized, app.i18n.Ts("globals.messages.denied", "name", "{globals.terms.permission}"), nil, envelope.UnauthorizedError)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// If no authenticated user, the middleware has already verified the request signature serve the file.
 | 
				
			||||||
	consts := app.consts.Load().(*constants)
 | 
						consts := app.consts.Load().(*constants)
 | 
				
			||||||
	switch consts.UploadProvider {
 | 
						switch consts.UploadProvider {
 | 
				
			||||||
	case "fs":
 | 
						case "fs":
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,7 @@ import (
 | 
				
			|||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	amodels "github.com/abhinavxd/libredesk/internal/auth/models"
 | 
						amodels "github.com/abhinavxd/libredesk/internal/auth/models"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/automation/models"
 | 
						cmodels "github.com/abhinavxd/libredesk/internal/conversation/models"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/envelope"
 | 
						"github.com/abhinavxd/libredesk/internal/envelope"
 | 
				
			||||||
	medModels "github.com/abhinavxd/libredesk/internal/media/models"
 | 
						medModels "github.com/abhinavxd/libredesk/internal/media/models"
 | 
				
			||||||
	"github.com/valyala/fasthttp"
 | 
						"github.com/valyala/fasthttp"
 | 
				
			||||||
@@ -42,7 +42,7 @@ func handleGetMessages(r *fastglue.Request) error {
 | 
				
			|||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	messages, pageSize, err := app.conversation.GetConversationMessages(uuid, page, pageSize)
 | 
						messages, pageSize, err := app.conversation.GetConversationMessages(uuid, []string{cmodels.MessageIncoming, cmodels.MessageOutgoing, cmodels.MessageActivity}, nil, page, pageSize)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -53,10 +53,11 @@ func handleGetMessages(r *fastglue.Request) error {
 | 
				
			|||||||
		for j := range messages[i].Attachments {
 | 
							for j := range messages[i].Attachments {
 | 
				
			||||||
			messages[i].Attachments[j].URL = app.media.GetURL(messages[i].Attachments[j].UUID)
 | 
								messages[i].Attachments[j].URL = app.media.GetURL(messages[i].Attachments[j].UUID)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// Redact CSAT survey link
 | 
					 | 
				
			||||||
		messages[i].CensorCSATContent()
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Process CSAT status for all messages (will only affect CSAT messages)
 | 
				
			||||||
 | 
						app.conversation.ProcessCSATStatus(messages)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope(envelope.PageResults{
 | 
						return r.SendEnvelope(envelope.PageResults{
 | 
				
			||||||
		Total:      total,
 | 
							Total:      total,
 | 
				
			||||||
		Results:    messages,
 | 
							Results:    messages,
 | 
				
			||||||
@@ -90,8 +91,10 @@ func handleGetMessage(r *fastglue.Request) error {
 | 
				
			|||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Redact CSAT survey link
 | 
						// Process CSAT status for the message (will only affect CSAT messages)
 | 
				
			||||||
	message.CensorCSATContent()
 | 
						messages := []cmodels.Message{message}
 | 
				
			||||||
 | 
						app.conversation.ProcessCSATStatus(messages)
 | 
				
			||||||
 | 
						message = messages[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for j := range message.Attachments {
 | 
						for j := range message.Attachments {
 | 
				
			||||||
		message.Attachments[j].URL = app.media.GetURL(message.Attachments[j].UUID)
 | 
							message.Attachments[j].URL = app.media.GetURL(message.Attachments[j].UUID)
 | 
				
			||||||
@@ -132,7 +135,6 @@ func handleSendMessage(r *fastglue.Request) error {
 | 
				
			|||||||
		app   = r.Context.(*App)
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
		auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
							auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
				
			||||||
		cuuid = r.RequestCtx.UserValue("cuuid").(string)
 | 
							cuuid = r.RequestCtx.UserValue("cuuid").(string)
 | 
				
			||||||
		media = []medModels.Media{}
 | 
					 | 
				
			||||||
		req   = messageReq{}
 | 
							req   = messageReq{}
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -152,7 +154,17 @@ func handleSendMessage(r *fastglue.Request) error {
 | 
				
			|||||||
		return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Make sure the inbox is enabled.
 | 
				
			||||||
 | 
						inbox, err := app.inbox.GetDBRecord(conv.InboxID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !inbox.Enabled {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.disabled", "name", "{globals.terms.inbox}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Prepare attachments.
 | 
						// Prepare attachments.
 | 
				
			||||||
 | 
						var media = make([]medModels.Media, 0, len(req.Attachments))
 | 
				
			||||||
	for _, id := range req.Attachments {
 | 
						for _, id := range req.Attachments {
 | 
				
			||||||
		m, err := app.media.Get(id, "")
 | 
							m, err := app.media.Get(id, "")
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
@@ -163,16 +175,16 @@ func handleSendMessage(r *fastglue.Request) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if req.Private {
 | 
						if req.Private {
 | 
				
			||||||
		if err := app.conversation.SendPrivateNote(media, user.ID, cuuid, req.Message); err != nil {
 | 
							message, err := app.conversation.SendPrivateNote(media, user.ID, cuuid, req.Message)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
			return sendErrorEnvelope(r, err)
 | 
								return sendErrorEnvelope(r, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
							return r.SendEnvelope(message)
 | 
				
			||||||
		if err := app.conversation.SendReply(media, conv.InboxID, user.ID, cuuid, req.Message, req.To, req.CC, req.BCC, map[string]any{} /**meta**/); err != nil {
 | 
					 | 
				
			||||||
			return sendErrorEnvelope(r, err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		// Evaluate automation rules.
 | 
					 | 
				
			||||||
		app.automation.EvaluateConversationUpdateRules(cuuid, models.EventConversationMessageOutgoing)
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						message, err := app.conversation.SendReply(media, conv.InboxID, user.ID, conv.ContactID, cuuid, req.Message, req.To, req.CC, req.BCC, map[string]any{} /**meta**/)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(message)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,96 +6,52 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	amodels "github.com/abhinavxd/libredesk/internal/auth/models"
 | 
						amodels "github.com/abhinavxd/libredesk/internal/auth/models"
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/envelope"
 | 
						"github.com/abhinavxd/libredesk/internal/envelope"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/user/models"
 | 
				
			||||||
	"github.com/valyala/fasthttp"
 | 
						"github.com/valyala/fasthttp"
 | 
				
			||||||
	"github.com/zerodha/fastglue"
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
	"github.com/zerodha/simplesessions/v3"
 | 
						"github.com/zerodha/simplesessions/v3"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// tryAuth attempts to authenticate the user and add them to the context but doesn't enforce authentication.
 | 
					// authenticateUser handles both API key and session-based authentication
 | 
				
			||||||
// Handlers can check if user exists in context optionally.
 | 
					// Returns the authenticated user or an error
 | 
				
			||||||
func tryAuth(handler fastglue.FastRequestHandler) fastglue.FastRequestHandler {
 | 
					// For session-based auth, CSRF is checked for POST/PUT/DELETE requests
 | 
				
			||||||
	return func(r *fastglue.Request) error {
 | 
					func authenticateUser(r *fastglue.Request, app *App) (models.User, error) {
 | 
				
			||||||
		app := r.Context.(*App)
 | 
						var user models.User
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Try to validate session without returning error.
 | 
						// Check for Authorization header first (API key authentication)
 | 
				
			||||||
		userSession, err := app.auth.ValidateSession(r)
 | 
						apiKey, apiSecret, err := r.ParseAuthHeader(fastglue.AuthBasic | fastglue.AuthToken)
 | 
				
			||||||
		if err != nil || userSession.ID <= 0 {
 | 
						if err == nil && len(apiKey) > 0 && len(apiSecret) > 0 {
 | 
				
			||||||
			return handler(r)
 | 
							user, err = app.user.ValidateAPIKey(string(apiKey), string(apiSecret))
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Try to get user.
 | 
					 | 
				
			||||||
		user, err := app.user.GetAgent(userSession.ID, "")
 | 
					 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return handler(r)
 | 
								return user, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return user, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Set user in context if found.
 | 
						// Session-based authentication - Check CSRF first.
 | 
				
			||||||
		r.RequestCtx.SetUserValue("user", amodels.User{
 | 
						method := string(r.RequestCtx.Method())
 | 
				
			||||||
			ID:        user.ID,
 | 
						if method == "POST" || method == "PUT" || method == "DELETE" {
 | 
				
			||||||
			Email:     user.Email.String,
 | 
							cookieToken := string(r.RequestCtx.Request.Header.Cookie("csrf_token"))
 | 
				
			||||||
			FirstName: user.FirstName,
 | 
							hdrToken := string(r.RequestCtx.Request.Header.Peek("X-CSRFTOKEN"))
 | 
				
			||||||
			LastName:  user.LastName,
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return handler(r)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// auth validates the session and adds the user to the request context.
 | 
					 | 
				
			||||||
func auth(handler fastglue.FastRequestHandler) fastglue.FastRequestHandler {
 | 
					 | 
				
			||||||
	return func(r *fastglue.Request) error {
 | 
					 | 
				
			||||||
		var app = r.Context.(*App)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Validate session and fetch user.
 | 
					 | 
				
			||||||
		userSession, err := app.auth.ValidateSession(r)
 | 
					 | 
				
			||||||
		if err != nil || userSession.ID <= 0 {
 | 
					 | 
				
			||||||
			app.lo.Error("error validating session", "error", err)
 | 
					 | 
				
			||||||
			return r.SendErrorEnvelope(http.StatusUnauthorized, app.i18n.T("auth.invalidOrExpiredSession"), nil, envelope.GeneralError)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Set user in the request context.
 | 
					 | 
				
			||||||
		user, err := app.user.GetAgent(userSession.ID, "")
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return sendErrorEnvelope(r, err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		r.RequestCtx.SetUserValue("user", amodels.User{
 | 
					 | 
				
			||||||
			ID:        user.ID,
 | 
					 | 
				
			||||||
			Email:     user.Email.String,
 | 
					 | 
				
			||||||
			FirstName: user.FirstName,
 | 
					 | 
				
			||||||
			LastName:  user.LastName,
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return handler(r)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// perm matches the CSRF token and checks if the user has the required permission to access the endpoint.
 | 
					 | 
				
			||||||
// and sets the user in the request context.
 | 
					 | 
				
			||||||
func perm(handler fastglue.FastRequestHandler, perm string) fastglue.FastRequestHandler {
 | 
					 | 
				
			||||||
	return func(r *fastglue.Request) error {
 | 
					 | 
				
			||||||
		var (
 | 
					 | 
				
			||||||
			app         = r.Context.(*App)
 | 
					 | 
				
			||||||
			cookieToken = string(r.RequestCtx.Request.Header.Cookie("csrf_token"))
 | 
					 | 
				
			||||||
			hdrToken    = string(r.RequestCtx.Request.Header.Peek("X-CSRFTOKEN"))
 | 
					 | 
				
			||||||
		)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Match CSRF token from cookie and header.
 | 
							// Match CSRF token from cookie and header.
 | 
				
			||||||
		if cookieToken == "" || hdrToken == "" || cookieToken != hdrToken {
 | 
							if cookieToken == "" || hdrToken == "" || cookieToken != hdrToken {
 | 
				
			||||||
			app.lo.Error("csrf token mismatch", "cookie_token", cookieToken, "header_token", hdrToken)
 | 
								app.lo.Error("csrf token mismatch", "method", method, "cookie_token", cookieToken, "header_token", hdrToken)
 | 
				
			||||||
			return r.SendErrorEnvelope(http.StatusForbidden, app.i18n.T("auth.csrfTokenMismatch"), nil, envelope.PermissionError)
 | 
								return user, envelope.NewError(envelope.PermissionError, app.i18n.T("auth.csrfTokenMismatch"), nil)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Validate session and fetch user.
 | 
						// Validate session and fetch user.
 | 
				
			||||||
	sessUser, err := app.auth.ValidateSession(r)
 | 
						sessUser, err := app.auth.ValidateSession(r)
 | 
				
			||||||
	if err != nil || sessUser.ID <= 0 {
 | 
						if err != nil || sessUser.ID <= 0 {
 | 
				
			||||||
		app.lo.Error("error validating session", "error", err)
 | 
							app.lo.Error("error validating session", "error", err)
 | 
				
			||||||
			return r.SendErrorEnvelope(http.StatusUnauthorized, app.i18n.T("auth.invalidOrExpiredSession"), nil, envelope.GeneralError)
 | 
							return user, envelope.NewError(envelope.GeneralError, app.i18n.T("auth.invalidOrExpiredSession"), nil)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Get user from DB.
 | 
						// Get agent user from cache or load it.
 | 
				
			||||||
		user, err := app.user.GetAgent(sessUser.ID, "")
 | 
						user, err = app.user.GetAgentCachedOrLoad(sessUser.ID)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
			return sendErrorEnvelope(r, err)
 | 
							return user, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Destroy session if user is disabled.
 | 
						// Destroy session if user is disabled.
 | 
				
			||||||
@@ -103,7 +59,101 @@ func perm(handler fastglue.FastRequestHandler, perm string) fastglue.FastRequest
 | 
				
			|||||||
		if err := app.auth.DestroySession(r); err != nil {
 | 
							if err := app.auth.DestroySession(r); err != nil {
 | 
				
			||||||
			app.lo.Error("error destroying session", "error", err)
 | 
								app.lo.Error("error destroying session", "error", err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
			return r.SendErrorEnvelope(http.StatusUnauthorized, app.i18n.T("user.accountDisabled"), nil, envelope.PermissionError)
 | 
							return user, envelope.NewError(envelope.PermissionError, app.i18n.T("user.accountDisabled"), nil)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return user, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// tryAuth attempts to authenticate the user and add them to the context but doesn't enforce authentication.
 | 
				
			||||||
 | 
					// Handlers can check if user exists in context optionally.
 | 
				
			||||||
 | 
					// Supports both API key authentication (Authorization header) and session-based authentication.
 | 
				
			||||||
 | 
					func tryAuth(handler fastglue.FastRequestHandler) fastglue.FastRequestHandler {
 | 
				
			||||||
 | 
						return func(r *fastglue.Request) error {
 | 
				
			||||||
 | 
							app := r.Context.(*App)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Try to authenticate user using shared authentication logic, but don't return errors
 | 
				
			||||||
 | 
							user, err := authenticateUser(r, app)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								// Authentication failed, but this is optional, so continue without user
 | 
				
			||||||
 | 
								return handler(r)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Set user in context if authentication succeeded.
 | 
				
			||||||
 | 
							r.RequestCtx.SetUserValue("user", amodels.User{
 | 
				
			||||||
 | 
								ID:        user.ID,
 | 
				
			||||||
 | 
								Email:     user.Email.String,
 | 
				
			||||||
 | 
								FirstName: user.FirstName,
 | 
				
			||||||
 | 
								LastName:  user.LastName,
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return handler(r)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// auth validates the session or API key and adds the user to the request context.
 | 
				
			||||||
 | 
					// Supports both API key authentication (Authorization header) and session-based authentication.
 | 
				
			||||||
 | 
					func auth(handler fastglue.FastRequestHandler) fastglue.FastRequestHandler {
 | 
				
			||||||
 | 
						return func(r *fastglue.Request) error {
 | 
				
			||||||
 | 
							var app = r.Context.(*App)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// For media uploads, check if signature is provided in the query parameters, if so, verify it.
 | 
				
			||||||
 | 
							path := string(r.RequestCtx.Path())
 | 
				
			||||||
 | 
							if strings.HasPrefix(path, "/uploads/") {
 | 
				
			||||||
 | 
								signature := string(r.RequestCtx.QueryArgs().Peek("signature"))
 | 
				
			||||||
 | 
								expires := string(r.RequestCtx.QueryArgs().Peek("expires"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if signature != "" && expires != "" {
 | 
				
			||||||
 | 
									if err := app.media.VerifySignature(r); err != nil {
 | 
				
			||||||
 | 
										app.lo.Error("error verifying media signature", "error",
 | 
				
			||||||
 | 
											err, "path", string(r.RequestCtx.Path()), "query", string(r.RequestCtx.QueryArgs().QueryString()))
 | 
				
			||||||
 | 
										return r.SendErrorEnvelope(http.StatusUnauthorized, "signature verification failed", nil, envelope.PermissionError)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									return handler(r)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								// If no signature, continue with normal authentication.
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Authenticate user using shared authentication logic
 | 
				
			||||||
 | 
							user, err := authenticateUser(r, app)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								if envErr, ok := err.(envelope.Error); ok {
 | 
				
			||||||
 | 
									if envErr.ErrorType == envelope.PermissionError {
 | 
				
			||||||
 | 
										return r.SendErrorEnvelope(http.StatusForbidden, envErr.Message, nil, envelope.PermissionError)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									return r.SendErrorEnvelope(http.StatusUnauthorized, envErr.Message, nil, envelope.GeneralError)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Set user in the request context.
 | 
				
			||||||
 | 
							r.RequestCtx.SetUserValue("user", amodels.User{
 | 
				
			||||||
 | 
								ID:        user.ID,
 | 
				
			||||||
 | 
								Email:     user.Email.String,
 | 
				
			||||||
 | 
								FirstName: user.FirstName,
 | 
				
			||||||
 | 
								LastName:  user.LastName,
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return handler(r)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// perm checks if the user has the required permission to access the endpoint.
 | 
				
			||||||
 | 
					// Supports both API key authentication (Authorization header) and session-based authentication.
 | 
				
			||||||
 | 
					func perm(handler fastglue.FastRequestHandler, perm string) fastglue.FastRequestHandler {
 | 
				
			||||||
 | 
						return func(r *fastglue.Request) error {
 | 
				
			||||||
 | 
							var app = r.Context.(*App)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Authenticate user using shared authentication logic
 | 
				
			||||||
 | 
							user, err := authenticateUser(r, app)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								if envErr, ok := err.(envelope.Error); ok {
 | 
				
			||||||
 | 
									if envErr.ErrorType == envelope.PermissionError {
 | 
				
			||||||
 | 
										return r.SendErrorEnvelope(http.StatusForbidden, envErr.Message, nil, envelope.PermissionError)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									return r.SendErrorEnvelope(http.StatusUnauthorized, envErr.Message, nil, envelope.GeneralError)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return sendErrorEnvelope(r, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Split the permission string into object and action and enforce it.
 | 
							// Split the permission string into object and action and enforce it.
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										40
									
								
								cmd/oidc.go
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								cmd/oidc.go
									
									
									
									
									
								
							@@ -50,18 +50,6 @@ func handleGetOIDC(r *fastglue.Request) error {
 | 
				
			|||||||
	return r.SendEnvelope(o)
 | 
						return r.SendEnvelope(o)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleTestOIDC tests an OIDC provider URL by doing a discovery on the provider URL.
 | 
					 | 
				
			||||||
func handleTestOIDC(r *fastglue.Request) error {
 | 
					 | 
				
			||||||
	var (
 | 
					 | 
				
			||||||
		app         = r.Context.(*App)
 | 
					 | 
				
			||||||
		providerURL = string(r.RequestCtx.PostArgs().Peek("provider_url"))
 | 
					 | 
				
			||||||
	)
 | 
					 | 
				
			||||||
	if err := app.auth.TestProvider(providerURL); err != nil {
 | 
					 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// handleCreateOIDC creates a new OIDC record.
 | 
					// handleCreateOIDC creates a new OIDC record.
 | 
				
			||||||
func handleCreateOIDC(r *fastglue.Request) error {
 | 
					func handleCreateOIDC(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
@@ -72,7 +60,13 @@ func handleCreateOIDC(r *fastglue.Request) error {
 | 
				
			|||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.GeneralError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.GeneralError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := app.oidc.Create(req); err != nil {
 | 
						// Test OIDC provider URL by performing a discovery.
 | 
				
			||||||
 | 
						if err := app.auth.TestProvider(req.ProviderURL); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						createdOIDC, err := app.oidc.Create(req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -80,7 +74,11 @@ func handleCreateOIDC(r *fastglue.Request) error {
 | 
				
			|||||||
	if err := reloadAuth(app); err != nil {
 | 
						if err := reloadAuth(app); err != nil {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.couldNotReload", "name", "OIDC"), nil, envelope.GeneralError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.couldNotReload", "name", "OIDC"), nil, envelope.GeneralError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope("OIDC created successfully")
 | 
						
 | 
				
			||||||
 | 
						// Clear client secret before returning
 | 
				
			||||||
 | 
						createdOIDC.ClientSecret = strings.Repeat(stringutil.PasswordDummy, 10)
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						return r.SendEnvelope(createdOIDC)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleUpdateOIDC updates an OIDC record.
 | 
					// handleUpdateOIDC updates an OIDC record.
 | 
				
			||||||
@@ -98,7 +96,13 @@ func handleUpdateOIDC(r *fastglue.Request) error {
 | 
				
			|||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.GeneralError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.GeneralError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err = app.oidc.Update(id, req); err != nil {
 | 
						// Test OIDC provider URL by performing a discovery.
 | 
				
			||||||
 | 
						if err := app.auth.TestProvider(req.ProviderURL); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						updatedOIDC, err := app.oidc.Update(id, req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -106,7 +110,11 @@ func handleUpdateOIDC(r *fastglue.Request) error {
 | 
				
			|||||||
	if err := reloadAuth(app); err != nil {
 | 
						if err := reloadAuth(app); err != nil {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.couldNotReload", "name", "OIDC"), nil, envelope.GeneralError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.couldNotReload", "name", "OIDC"), nil, envelope.GeneralError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						
 | 
				
			||||||
 | 
						// Clear client secret before returning
 | 
				
			||||||
 | 
						updatedOIDC.ClientSecret = strings.Repeat(stringutil.PasswordDummy, 10)
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						return r.SendEnvelope(updatedOIDC)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleDeleteOIDC deletes an OIDC record.
 | 
					// handleDeleteOIDC deletes an OIDC record.
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										45
									
								
								cmd/report.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								cmd/report.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleOverviewCounts retrieves general dashboard counts for all users.
 | 
				
			||||||
 | 
					func handleOverviewCounts(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app = r.Context.(*App)
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						counts, err := app.report.GetOverViewCounts()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(counts)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleOverviewCharts retrieves general dashboard chart data.
 | 
				
			||||||
 | 
					func handleOverviewCharts(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app     = r.Context.(*App)
 | 
				
			||||||
 | 
							days, _ = strconv.Atoi(string(r.RequestCtx.QueryArgs().Peek("days")))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						charts, err := app.report.GetOverviewChart(days)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(charts)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleOverviewSLA retrieves SLA data for the dashboard.
 | 
				
			||||||
 | 
					func handleOverviewSLA(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app     = r.Context.(*App)
 | 
				
			||||||
 | 
							days, _ = strconv.Atoi(string(r.RequestCtx.QueryArgs().Peek("days")))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						sla, err := app.report.GetOverviewSLA(days)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(sla)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										10
									
								
								cmd/roles.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								cmd/roles.go
									
									
									
									
									
								
							@@ -55,10 +55,11 @@ func handleCreateRole(r *fastglue.Request) error {
 | 
				
			|||||||
	if err := r.Decode(&req, "json"); err != nil {
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := app.role.Create(req); err != nil {
 | 
						createdRole, err := app.role.Create(req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(createdRole)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleUpdateRole updates a role
 | 
					// handleUpdateRole updates a role
 | 
				
			||||||
@@ -71,8 +72,9 @@ func handleUpdateRole(r *fastglue.Request) error {
 | 
				
			|||||||
	if err := r.Decode(&req, "json"); err != nil {
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := app.role.Update(id, req); err != nil {
 | 
						updatedRole, err := app.role.Update(id, req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(updatedRole)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										72
									
								
								cmd/sla.go
									
									
									
									
									
								
							
							
						
						
									
										72
									
								
								cmd/sla.go
									
									
									
									
									
								
							@@ -29,7 +29,7 @@ func handleGetSLA(r *fastglue.Request) error {
 | 
				
			|||||||
	)
 | 
						)
 | 
				
			||||||
	id, err := strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
						id, err := strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
	if err != nil || id == 0 {
 | 
						if err != nil || id == 0 {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "SLA `id`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sla, err := app.sla.Get(id)
 | 
						sla, err := app.sla.Get(id)
 | 
				
			||||||
@@ -54,11 +54,12 @@ func handleCreateSLA(r *fastglue.Request) error {
 | 
				
			|||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := app.sla.Create(sla.Name, sla.Description, sla.FirstResponseTime, sla.ResolutionTime, sla.Notifications); err != nil {
 | 
						createdSLA, err := app.sla.Create(sla.Name, sla.Description, sla.FirstResponseTime, sla.ResolutionTime, sla.NextResponseTime, sla.Notifications)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope("SLA created successfully.")
 | 
						return r.SendEnvelope(createdSLA)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleUpdateSLA updates the SLA with the given ID.
 | 
					// handleUpdateSLA updates the SLA with the given ID.
 | 
				
			||||||
@@ -70,7 +71,7 @@ func handleUpdateSLA(r *fastglue.Request) error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	id, err := strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
						id, err := strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
	if err != nil || id == 0 {
 | 
						if err != nil || id == 0 {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "SLA `id`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := r.Decode(&sla, "json"); err != nil {
 | 
						if err := r.Decode(&sla, "json"); err != nil {
 | 
				
			||||||
@@ -81,11 +82,12 @@ func handleUpdateSLA(r *fastglue.Request) error {
 | 
				
			|||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := app.sla.Update(id, sla.Name, sla.Description, sla.FirstResponseTime, sla.ResolutionTime, sla.Notifications); err != nil {
 | 
						updatedSLA, err := app.sla.Update(id, sla.Name, sla.Description, sla.FirstResponseTime, sla.ResolutionTime, sla.NextResponseTime, sla.Notifications)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope("SLA updated successfully.")
 | 
						return r.SendEnvelope(updatedSLA)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleDeleteSLA deletes the SLA with the given ID.
 | 
					// handleDeleteSLA deletes the SLA with the given ID.
 | 
				
			||||||
@@ -95,7 +97,7 @@ func handleDeleteSLA(r *fastglue.Request) error {
 | 
				
			|||||||
	)
 | 
						)
 | 
				
			||||||
	id, err := strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
						id, err := strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
	if err != nil || id == 0 {
 | 
						if err != nil || id == 0 {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "SLA `id`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err = app.sla.Delete(id); err != nil {
 | 
						if err = app.sla.Delete(id); err != nil {
 | 
				
			||||||
@@ -108,52 +110,80 @@ func handleDeleteSLA(r *fastglue.Request) error {
 | 
				
			|||||||
// validateSLA validates the SLA policy and returns an envelope.Error if any validation fails.
 | 
					// validateSLA validates the SLA policy and returns an envelope.Error if any validation fails.
 | 
				
			||||||
func validateSLA(app *App, sla *smodels.SLAPolicy) error {
 | 
					func validateSLA(app *App, sla *smodels.SLAPolicy) error {
 | 
				
			||||||
	if sla.Name == "" {
 | 
						if sla.Name == "" {
 | 
				
			||||||
		return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "SLA `name`"), nil)
 | 
							return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if sla.FirstResponseTime == "" {
 | 
						if sla.FirstResponseTime.String == "" && sla.NextResponseTime.String == "" && sla.ResolutionTime.String == "" {
 | 
				
			||||||
		return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "SLA `first_response_time`"), nil)
 | 
							return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "At least one of `first_response_time`, `next_response_time`, or `resolution_time` must be provided."), nil)
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if sla.ResolutionTime == "" {
 | 
					 | 
				
			||||||
		return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "SLA `resolution_time`"), nil)
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Validate notifications if any
 | 
						// Validate notifications if any.
 | 
				
			||||||
	for _, n := range sla.Notifications {
 | 
						for _, n := range sla.Notifications {
 | 
				
			||||||
		if n.Type == "" {
 | 
							if n.Type == "" {
 | 
				
			||||||
			return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "SLA notification `type`"), nil)
 | 
								return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "`type`"), nil)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if n.TimeDelayType == "" {
 | 
							if n.TimeDelayType == "" {
 | 
				
			||||||
			return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "SLA notification `time_delay_type`"), nil)
 | 
								return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "`time_delay_type`"), nil)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if n.Metric == "" {
 | 
				
			||||||
 | 
								return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "`metric`"), nil)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if n.TimeDelayType != "immediately" {
 | 
							if n.TimeDelayType != "immediately" {
 | 
				
			||||||
			if n.TimeDelay == "" {
 | 
								if n.TimeDelay == "" {
 | 
				
			||||||
				return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "SLA notification `time_delay`"), nil)
 | 
									return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "`time_delay`"), nil)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								// Validate time delay duration.
 | 
				
			||||||
 | 
								td, err := time.ParseDuration(n.TimeDelay)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.invalid", "name", "`time_delay`"), nil)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if td.Minutes() < 1 {
 | 
				
			||||||
 | 
									return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.invalid", "name", "`time_delay`"), nil)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if len(n.Recipients) == 0 {
 | 
							if len(n.Recipients) == 0 {
 | 
				
			||||||
			return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "SLA notification `recipients`"), nil)
 | 
								return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "`recipients`"), nil)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Validate time duration strings
 | 
						// Validate first response time duration string if not empty.
 | 
				
			||||||
	frt, err := time.ParseDuration(sla.FirstResponseTime)
 | 
						if sla.FirstResponseTime.String != "" {
 | 
				
			||||||
 | 
							frt, err := time.ParseDuration(sla.FirstResponseTime.String)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.invalid", "name", "`first_response_time`"), nil)
 | 
								return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.invalid", "name", "`first_response_time`"), nil)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if frt.Minutes() < 1 {
 | 
							if frt.Minutes() < 1 {
 | 
				
			||||||
			return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.invalid", "name", "`first_response_time`"), nil)
 | 
								return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.invalid", "name", "`first_response_time`"), nil)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rt, err := time.ParseDuration(sla.ResolutionTime)
 | 
						// Validate resolution time duration string if not empty.
 | 
				
			||||||
 | 
						if sla.ResolutionTime.String != "" {
 | 
				
			||||||
 | 
							rt, err := time.ParseDuration(sla.ResolutionTime.String)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.invalid", "name", "`resolution_time`"), nil)
 | 
								return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.invalid", "name", "`resolution_time`"), nil)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if rt.Minutes() < 1 {
 | 
							if rt.Minutes() < 1 {
 | 
				
			||||||
			return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.invalid", "name", "`resolution_time`"), nil)
 | 
								return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.invalid", "name", "`resolution_time`"), nil)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							// Compare with first response time if both are present.
 | 
				
			||||||
 | 
							if sla.FirstResponseTime.String != "" {
 | 
				
			||||||
 | 
								frt, _ := time.ParseDuration(sla.FirstResponseTime.String)
 | 
				
			||||||
			if frt > rt {
 | 
								if frt > rt {
 | 
				
			||||||
				return envelope.NewError(envelope.InputError, app.i18n.T("sla.firstResponseTimeAfterResolution"), nil)
 | 
									return envelope.NewError(envelope.InputError, app.i18n.T("sla.firstResponseTimeAfterResolution"), nil)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Validate next response time duration string if not empty.
 | 
				
			||||||
 | 
						if sla.NextResponseTime.String != "" {
 | 
				
			||||||
 | 
							nrt, err := time.ParseDuration(sla.NextResponseTime.String)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.invalid", "name", "`next_response_time`"), nil)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if nrt.Minutes() < 1 {
 | 
				
			||||||
 | 
								return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.invalid", "name", "`next_response_time`"), nil)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										108
									
								
								cmd/snippets.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										108
									
								
								cmd/snippets.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,108 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/envelope"
 | 
				
			||||||
 | 
						"github.com/valyala/fasthttp"
 | 
				
			||||||
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// snippetReq represents the request payload for snippets creation and updates.
 | 
				
			||||||
 | 
					type snippetReq struct {
 | 
				
			||||||
 | 
						Content string `json:"content"`
 | 
				
			||||||
 | 
						Enabled bool   `json:"enabled"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// validateSnippetReq validates the snippet request payload.
 | 
				
			||||||
 | 
					func validateSnippetReq(r *fastglue.Request, snippetData *snippetReq) error {
 | 
				
			||||||
 | 
						var app = r.Context.(*App)
 | 
				
			||||||
 | 
						if snippetData.Content == "" {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`content`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleGetAISnippets returns all AI snippets from the database.
 | 
				
			||||||
 | 
					func handleGetAISnippets(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var app = r.Context.(*App)
 | 
				
			||||||
 | 
						snippets, err := app.ai.GetKnowledgeBaseItems()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(snippets)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleGetAISnippet returns a single AI snippet by ID.
 | 
				
			||||||
 | 
					func handleGetAISnippet(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						snippet, err := app.ai.GetKnowledgeBaseItem(id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(snippet)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleCreateAISnippet creates a new AI snippet in the database.
 | 
				
			||||||
 | 
					func handleCreateAISnippet(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app         = r.Context.(*App)
 | 
				
			||||||
 | 
							snippetData snippetReq
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if err := r.Decode(&snippetData, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := validateSnippetReq(r, &snippetData); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						snippet, err := app.ai.CreateKnowledgeBaseItem("snippet", snippetData.Content, snippetData.Enabled)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(snippet)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleUpdateAISnippet updates an existing AI snippet in the database.
 | 
				
			||||||
 | 
					func handleUpdateAISnippet(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app         = r.Context.(*App)
 | 
				
			||||||
 | 
							snippetData snippetReq
 | 
				
			||||||
 | 
							id, _       = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := r.Decode(&snippetData, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := validateSnippetReq(r, &snippetData); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						snippet, err := app.ai.UpdateKnowledgeBaseItem(id, "snippet", snippetData.Content, snippetData.Enabled)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(snippet)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleDeleteAISnippet deletes an AI snippet from the database.
 | 
				
			||||||
 | 
					func handleDeleteAISnippet(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := app.ai.DeleteKnowledgeBaseItem(id); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -33,12 +33,12 @@ func handleCreateStatus(r *fastglue.Request) error {
 | 
				
			|||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := app.status.Create(status.Name)
 | 
						createdStatus, err := app.status.Create(status.Name)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(createdStatus)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func handleDeleteStatus(r *fastglue.Request) error {
 | 
					func handleDeleteStatus(r *fastglue.Request) error {
 | 
				
			||||||
@@ -74,10 +74,10 @@ func handleUpdateStatus(r *fastglue.Request) error {
 | 
				
			|||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = app.status.Update(id, status.Name)
 | 
						updatedStatus, err := app.status.Update(id, status.Name)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(updatedStatus)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										10
									
								
								cmd/tags.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								cmd/tags.go
									
									
									
									
									
								
							@@ -35,11 +35,12 @@ func handleCreateTag(r *fastglue.Request) error {
 | 
				
			|||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := app.tag.Create(tag.Name); err != nil {
 | 
						createdTag, err := app.tag.Create(tag.Name)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(createdTag)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleDeleteTag deletes a tag from the database.
 | 
					// handleDeleteTag deletes a tag from the database.
 | 
				
			||||||
@@ -78,9 +79,10 @@ func handleUpdateTag(r *fastglue.Request) error {
 | 
				
			|||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err = app.tag.Update(id, tag.Name); err != nil {
 | 
						updatedTag, err := app.tag.Update(id, tag.Name)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(updatedTag)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										41
									
								
								cmd/teams.go
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								cmd/teams.go
									
									
									
									
									
								
							@@ -4,8 +4,8 @@ import (
 | 
				
			|||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/abhinavxd/libredesk/internal/envelope"
 | 
						"github.com/abhinavxd/libredesk/internal/envelope"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/team/models"
 | 
				
			||||||
	"github.com/valyala/fasthttp"
 | 
						"github.com/valyala/fasthttp"
 | 
				
			||||||
	"github.com/volatiletech/null/v9"
 | 
					 | 
				
			||||||
	"github.com/zerodha/fastglue"
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -53,40 +53,41 @@ func handleGetTeam(r *fastglue.Request) error {
 | 
				
			|||||||
func handleCreateTeam(r *fastglue.Request) error {
 | 
					func handleCreateTeam(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		app = r.Context.(*App)
 | 
							app = r.Context.(*App)
 | 
				
			||||||
		name                            = string(r.RequestCtx.PostArgs().Peek("name"))
 | 
							req = models.Team{}
 | 
				
			||||||
		timezone                        = string(r.RequestCtx.PostArgs().Peek("timezone"))
 | 
					 | 
				
			||||||
		emoji                           = string(r.RequestCtx.PostArgs().Peek("emoji"))
 | 
					 | 
				
			||||||
		conversationAssignmentType      = string(r.RequestCtx.PostArgs().Peek("conversation_assignment_type"))
 | 
					 | 
				
			||||||
		businessHrsID, _                = strconv.Atoi(string(r.RequestCtx.PostArgs().Peek("business_hours_id")))
 | 
					 | 
				
			||||||
		slaPolicyID, _                  = strconv.Atoi(string(r.RequestCtx.PostArgs().Peek("sla_policy_id")))
 | 
					 | 
				
			||||||
		maxAutoAssignedConversations, _ = strconv.Atoi(string(r.RequestCtx.PostArgs().Peek("max_auto_assigned_conversations")))
 | 
					 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	if err := app.team.Create(name, timezone, conversationAssignmentType, null.NewInt(businessHrsID, businessHrsID != 0), null.NewInt(slaPolicyID, slaPolicyID != 0), emoji, maxAutoAssignedConversations); err != nil {
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						createdTeam, err := app.team.Create(req.Name, req.Timezone, req.ConversationAssignmentType, req.BusinessHoursID, req.SLAPolicyID, req.Emoji.String, req.MaxAutoAssignedConversations)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(createdTeam)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleUpdateTeam updates an existing team.
 | 
					// handleUpdateTeam updates an existing team.
 | 
				
			||||||
func handleUpdateTeam(r *fastglue.Request) error {
 | 
					func handleUpdateTeam(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		app   = r.Context.(*App)
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
		name                            = string(r.RequestCtx.PostArgs().Peek("name"))
 | 
					 | 
				
			||||||
		timezone                        = string(r.RequestCtx.PostArgs().Peek("timezone"))
 | 
					 | 
				
			||||||
		emoji                           = string(r.RequestCtx.PostArgs().Peek("emoji"))
 | 
					 | 
				
			||||||
		conversationAssignmentType      = string(r.RequestCtx.PostArgs().Peek("conversation_assignment_type"))
 | 
					 | 
				
			||||||
		id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
		businessHrsID, _                = strconv.Atoi(string(r.RequestCtx.PostArgs().Peek("business_hours_id")))
 | 
							req   = models.Team{}
 | 
				
			||||||
		slaPolicyID, _                  = strconv.Atoi(string(r.RequestCtx.PostArgs().Peek("sla_policy_id")))
 | 
					 | 
				
			||||||
		maxAutoAssignedConversations, _ = strconv.Atoi(string(r.RequestCtx.PostArgs().Peek("max_auto_assigned_conversations")))
 | 
					 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if id < 1 {
 | 
						if id < 1 {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, "Invalid team `id`", nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := app.team.Update(id, name, timezone, conversationAssignmentType, null.NewInt(businessHrsID, businessHrsID != 0), null.NewInt(slaPolicyID, slaPolicyID != 0), emoji, maxAutoAssignedConversations); err != nil {
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						updatedTeam, err := app.team.Update(id, req.Name, req.Timezone, req.ConversationAssignmentType, req.BusinessHoursID, req.SLAPolicyID, req.Emoji.String, req.MaxAutoAssignedConversations);
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(updatedTeam)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleDeleteTeam deletes a team
 | 
					// handleDeleteTeam deletes a team
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,10 +53,11 @@ func handleCreateTemplate(r *fastglue.Request) error {
 | 
				
			|||||||
	if req.Name == "" {
 | 
						if req.Name == "" {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := app.tmpl.Create(req); err != nil {
 | 
						template, err := app.tmpl.Create(req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(template)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleUpdateTemplate updates a template.
 | 
					// handleUpdateTemplate updates a template.
 | 
				
			||||||
@@ -76,10 +77,11 @@ func handleUpdateTemplate(r *fastglue.Request) error {
 | 
				
			|||||||
	if req.Name == "" {
 | 
						if req.Name == "" {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err = app.tmpl.Update(id, req); err != nil {
 | 
						updatedTemplate, err := app.tmpl.Update(id, req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(updatedTemplate)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleDeleteTemplate deletes a template.
 | 
					// handleDeleteTemplate deletes a template.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,6 +34,9 @@ var migList = []migFunc{
 | 
				
			|||||||
	{"v0.4.0", migrations.V0_4_0},
 | 
						{"v0.4.0", migrations.V0_4_0},
 | 
				
			||||||
	{"v0.5.0", migrations.V0_5_0},
 | 
						{"v0.5.0", migrations.V0_5_0},
 | 
				
			||||||
	{"v0.6.0", migrations.V0_6_0},
 | 
						{"v0.6.0", migrations.V0_6_0},
 | 
				
			||||||
 | 
						{"v0.7.0", migrations.V0_7_0},
 | 
				
			||||||
 | 
						{"v0.8.0", migrations.V0_8_0},
 | 
				
			||||||
 | 
						{"v0.9.0", migrations.V0_9_0},
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// upgrade upgrades the database to the current version by running SQL migration files
 | 
					// upgrade upgrades the database to the current version by running SQL migration files
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										150
									
								
								cmd/users.go
									
									
									
									
									
								
							
							
						
						
									
										150
									
								
								cmd/users.go
									
									
									
									
									
								
							@@ -26,6 +26,29 @@ const (
 | 
				
			|||||||
	maxAvatarSizeMB = 2
 | 
						maxAvatarSizeMB = 2
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Request structs for user-related endpoints
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// UpdateAvailabilityRequest represents the request to update user availability
 | 
				
			||||||
 | 
					type UpdateAvailabilityRequest struct {
 | 
				
			||||||
 | 
						Status string `json:"status"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ResetPasswordRequest represents the password reset request
 | 
				
			||||||
 | 
					type ResetPasswordRequest struct {
 | 
				
			||||||
 | 
						Email string `json:"email"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// SetPasswordRequest represents the set password request
 | 
				
			||||||
 | 
					type SetPasswordRequest struct {
 | 
				
			||||||
 | 
						Token    string `json:"token"`
 | 
				
			||||||
 | 
						Password string `json:"password"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// AvailabilityRequest represents the request to update agent availability
 | 
				
			||||||
 | 
					type AvailabilityRequest struct {
 | 
				
			||||||
 | 
						Status string `json:"status"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleGetAgents returns all agents.
 | 
					// handleGetAgents returns all agents.
 | 
				
			||||||
func handleGetAgents(r *fastglue.Request) error {
 | 
					func handleGetAgents(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
@@ -69,19 +92,36 @@ func handleUpdateAgentAvailability(r *fastglue.Request) error {
 | 
				
			|||||||
	var (
 | 
						var (
 | 
				
			||||||
		app      = r.Context.(*App)
 | 
							app      = r.Context.(*App)
 | 
				
			||||||
		auser    = r.RequestCtx.UserValue("user").(amodels.User)
 | 
							auser    = r.RequestCtx.UserValue("user").(amodels.User)
 | 
				
			||||||
		status = string(r.RequestCtx.PostArgs().Peek("status"))
 | 
					 | 
				
			||||||
		ip       = realip.FromRequest(r.RequestCtx)
 | 
							ip       = realip.FromRequest(r.RequestCtx)
 | 
				
			||||||
 | 
							availReq AvailabilityRequest
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Update availability status.
 | 
						// Decode JSON request
 | 
				
			||||||
	if err := app.user.UpdateAvailability(auser.ID, status); err != nil {
 | 
						if err := r.Decode(&availReq, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						agent, err := app.user.GetAgent(auser.ID, "")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create activity log.
 | 
						// Same status?
 | 
				
			||||||
	if err := app.activityLog.UserAvailability(auser.ID, auser.Email, status, ip, "", 0); err != nil {
 | 
						if agent.AvailabilityStatus == availReq.Status {
 | 
				
			||||||
 | 
							return r.SendEnvelope(true)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Update availability status.
 | 
				
			||||||
 | 
						if err := app.user.UpdateAvailability(auser.ID, availReq.Status); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Skip activity log if agent returns online from away (to avoid spam).
 | 
				
			||||||
 | 
						if !(agent.AvailabilityStatus == models.Away && availReq.Status == models.Online) {
 | 
				
			||||||
 | 
							if err := app.activityLog.UserAvailability(auser.ID, auser.Email, availReq.Status, ip, "", 0); err != nil {
 | 
				
			||||||
			app.lo.Error("error creating activity log", "error", err)
 | 
								app.lo.Error("error creating activity log", "error", err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -145,6 +185,11 @@ func handleCreateAgent(r *fastglue.Request) error {
 | 
				
			|||||||
	if user.Email.String == "" {
 | 
						if user.Email.String == "" {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`email`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`email`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						user.Email = null.StringFrom(strings.TrimSpace(strings.ToLower(user.Email.String)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !stringutil.ValidEmail(user.Email.String) {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`email`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if user.Roles == nil {
 | 
						if user.Roles == nil {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`role`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`role`"), nil, envelope.InputError)
 | 
				
			||||||
@@ -154,7 +199,6 @@ func handleCreateAgent(r *fastglue.Request) error {
 | 
				
			|||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`first_name`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`first_name`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Right now, only agents can be created.
 | 
					 | 
				
			||||||
	if err := app.user.CreateAgent(&user); err != nil {
 | 
						if err := app.user.CreateAgent(&user); err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -203,9 +247,9 @@ func handleUpdateAgent(r *fastglue.Request) error {
 | 
				
			|||||||
		user  = models.User{}
 | 
							user  = models.User{}
 | 
				
			||||||
		auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
							auser = r.RequestCtx.UserValue("user").(amodels.User)
 | 
				
			||||||
		ip    = realip.FromRequest(r.RequestCtx)
 | 
							ip    = realip.FromRequest(r.RequestCtx)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	id, err := strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
						if id == 0 {
 | 
				
			||||||
	if err != nil || id == 0 {
 | 
					 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`id`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -216,6 +260,11 @@ func handleUpdateAgent(r *fastglue.Request) error {
 | 
				
			|||||||
	if user.Email.String == "" {
 | 
						if user.Email.String == "" {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`email`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`email`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						user.Email = null.StringFrom(strings.TrimSpace(strings.ToLower(user.Email.String)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !stringutil.ValidEmail(user.Email.String) {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`email`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if user.Roles == nil {
 | 
						if user.Roles == nil {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`role`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`role`"), nil, envelope.InputError)
 | 
				
			||||||
@@ -236,6 +285,9 @@ func handleUpdateAgent(r *fastglue.Request) error {
 | 
				
			|||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Invalidate authz cache.
 | 
				
			||||||
 | 
						defer app.authz.InvalidateUserCache(id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create activity log if user availability status changed.
 | 
						// Create activity log if user availability status changed.
 | 
				
			||||||
	if oldAvailabilityStatus != user.AvailabilityStatus {
 | 
						if oldAvailabilityStatus != user.AvailabilityStatus {
 | 
				
			||||||
		if err := app.activityLog.UserAvailability(auser.ID, auser.Email, user.AvailabilityStatus, ip, user.Email.String, id); err != nil {
 | 
							if err := app.activityLog.UserAvailability(auser.ID, auser.Email, user.AvailabilityStatus, ip, user.Email.String, id); err != nil {
 | 
				
			||||||
@@ -328,19 +380,23 @@ func handleDeleteCurrentAgentAvatar(r *fastglue.Request) error {
 | 
				
			|||||||
func handleResetPassword(r *fastglue.Request) error {
 | 
					func handleResetPassword(r *fastglue.Request) error {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		app       = r.Context.(*App)
 | 
							app       = r.Context.(*App)
 | 
				
			||||||
		p         = r.RequestCtx.PostArgs()
 | 
					 | 
				
			||||||
		auser, ok = r.RequestCtx.UserValue("user").(amodels.User)
 | 
							auser, ok = r.RequestCtx.UserValue("user").(amodels.User)
 | 
				
			||||||
		email     = string(p.Peek("email"))
 | 
							resetReq  ResetPasswordRequest
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	if ok && auser.ID > 0 {
 | 
						if ok && auser.ID > 0 {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.T("user.userAlreadyLoggedIn"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.T("user.userAlreadyLoggedIn"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if email == "" {
 | 
						// Decode JSON request
 | 
				
			||||||
 | 
						if err := r.Decode(&resetReq, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resetReq.Email == "" {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`email`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`email`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	agent, err := app.user.GetAgent(0, email)
 | 
						agent, err := app.user.GetAgent(0, resetReq.Email)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		// Send 200 even if user not found, to prevent email enumeration.
 | 
							// Send 200 even if user not found, to prevent email enumeration.
 | 
				
			||||||
		return r.SendEnvelope("Reset password email sent successfully.")
 | 
							return r.SendEnvelope("Reset password email sent successfully.")
 | 
				
			||||||
@@ -378,20 +434,22 @@ func handleSetPassword(r *fastglue.Request) error {
 | 
				
			|||||||
	var (
 | 
						var (
 | 
				
			||||||
		app       = r.Context.(*App)
 | 
							app       = r.Context.(*App)
 | 
				
			||||||
		agent, ok = r.RequestCtx.UserValue("user").(amodels.User)
 | 
							agent, ok = r.RequestCtx.UserValue("user").(amodels.User)
 | 
				
			||||||
		p         = r.RequestCtx.PostArgs()
 | 
							req       = SetPasswordRequest{}
 | 
				
			||||||
		password  = string(p.Peek("password"))
 | 
					 | 
				
			||||||
		token     = string(p.Peek("token"))
 | 
					 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ok && agent.ID > 0 {
 | 
						if ok && agent.ID > 0 {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.T("user.userAlreadyLoggedIn"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.T("user.userAlreadyLoggedIn"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if password == "" {
 | 
						if err := r.Decode(&req, "json"); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), nil))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if req.Password == "" {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "{globals.terms.password}"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "{globals.terms.password}"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := app.user.ResetPassword(token, password); err != nil {
 | 
						if err := app.user.ResetPassword(req.Token, req.Password); err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -461,3 +519,61 @@ func uploadUserAvatar(r *fastglue.Request, user *models.User, files []*multipart
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleGenerateAPIKey generates a new API key for a user
 | 
				
			||||||
 | 
					func handleGenerateAPIKey(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Check if user exists
 | 
				
			||||||
 | 
						user, err := app.user.GetAgent(id, "")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Generate API key and secret
 | 
				
			||||||
 | 
						apiKey, apiSecret, err := app.user.GenerateAPIKey(user.ID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Return the API key and secret (only shown once)
 | 
				
			||||||
 | 
						response := struct {
 | 
				
			||||||
 | 
							APIKey    string `json:"api_key"`
 | 
				
			||||||
 | 
							APISecret string `json:"api_secret"`
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							APIKey:    apiKey,
 | 
				
			||||||
 | 
							APISecret: apiSecret,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(response)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleRevokeAPIKey revokes a user's API key
 | 
				
			||||||
 | 
					func handleRevokeAPIKey(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Check if user exists
 | 
				
			||||||
 | 
						_, err := app.user.GetAgent(id, "")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Revoke API key
 | 
				
			||||||
 | 
						if err := app.user.RevokeAPIKey(id); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										10
									
								
								cmd/views.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								cmd/views.go
									
									
									
									
									
								
							@@ -47,10 +47,11 @@ func handleCreateUserView(r *fastglue.Request) error {
 | 
				
			|||||||
	if string(view.Filters) == "" {
 | 
						if string(view.Filters) == "" {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`Filters`"), nil, envelope.InputError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.empty", "name", "`Filters`"), nil, envelope.InputError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := app.view.Create(view.Name, view.Filters, user.ID); err != nil {
 | 
						createdView, err := app.view.Create(view.Name, view.Filters, user.ID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(createdView)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handleDeleteUserView deletes a view for a user.
 | 
					// handleDeleteUserView deletes a view for a user.
 | 
				
			||||||
@@ -111,8 +112,9 @@ func handleUpdateUserView(r *fastglue.Request) error {
 | 
				
			|||||||
	if v.UserID != user.ID {
 | 
						if v.UserID != user.ID {
 | 
				
			||||||
		return r.SendErrorEnvelope(fasthttp.StatusForbidden, app.i18n.Ts("globals.messages.denied", "name", "{globals.terms.permission}"), nil, envelope.PermissionError)
 | 
							return r.SendErrorEnvelope(fasthttp.StatusForbidden, app.i18n.Ts("globals.messages.denied", "name", "{globals.terms.permission}"), nil, envelope.PermissionError)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err = app.view.Update(id, view.Name, view.Filters); err != nil {
 | 
						updatedView, err := app.view.Update(id, view.Name, view.Filters)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return sendErrorEnvelope(r, err)
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return r.SendEnvelope(true)
 | 
						return r.SendEnvelope(updatedView)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										191
									
								
								cmd/webhooks.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										191
									
								
								cmd/webhooks.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,191 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/envelope"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/stringutil"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/webhook/models"
 | 
				
			||||||
 | 
						"github.com/valyala/fasthttp"
 | 
				
			||||||
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleGetWebhooks returns all webhooks from the database.
 | 
				
			||||||
 | 
					func handleGetWebhooks(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app = r.Context.(*App)
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						webhooks, err := app.webhook.GetAll()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// Hide secrets.
 | 
				
			||||||
 | 
						for i := range webhooks {
 | 
				
			||||||
 | 
							if webhooks[i].Secret != "" {
 | 
				
			||||||
 | 
								webhooks[i].Secret = strings.Repeat(stringutil.PasswordDummy, 10)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r.SendEnvelope(webhooks)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleGetWebhook returns a specific webhook by ID.
 | 
				
			||||||
 | 
					func handleGetWebhook(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						webhook, err := app.webhook.Get(id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Hide secret in the response.
 | 
				
			||||||
 | 
						if webhook.Secret != "" {
 | 
				
			||||||
 | 
							webhook.Secret = strings.Repeat(stringutil.PasswordDummy, 10)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(webhook)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleCreateWebhook creates a new webhook in the database.
 | 
				
			||||||
 | 
					func handleCreateWebhook(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app     = r.Context.(*App)
 | 
				
			||||||
 | 
							webhook = models.Webhook{}
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if err := r.Decode(&webhook, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), err.Error(), envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Validate webhook fields
 | 
				
			||||||
 | 
						if err := validateWebhook(app, webhook); err != nil {
 | 
				
			||||||
 | 
							return r.SendEnvelope(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						webhook, err := app.webhook.Create(webhook)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Clear secret before returning
 | 
				
			||||||
 | 
						webhook.Secret = strings.Repeat(stringutil.PasswordDummy, 10)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(webhook)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleUpdateWebhook updates an existing webhook in the database.
 | 
				
			||||||
 | 
					func handleUpdateWebhook(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app     = r.Context.(*App)
 | 
				
			||||||
 | 
							webhook = models.Webhook{}
 | 
				
			||||||
 | 
							id, _   = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := r.Decode(&webhook, "json"); err != nil {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.errorParsing", "name", "{globals.terms.request}"), err.Error(), envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Validate webhook fields
 | 
				
			||||||
 | 
						if err := validateWebhook(app, webhook); err != nil {
 | 
				
			||||||
 | 
							return r.SendEnvelope(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// If secret is empty or contains dummy characters, fetch existing webhook and preserve the secret
 | 
				
			||||||
 | 
						if webhook.Secret == "" || strings.Contains(webhook.Secret, stringutil.PasswordDummy) {
 | 
				
			||||||
 | 
							existingWebhook, err := app.webhook.Get(id)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							webhook.Secret = existingWebhook.Secret
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						updatedWebhook, err := app.webhook.Update(id, webhook)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Clear secret before returning
 | 
				
			||||||
 | 
						updatedWebhook.Secret = strings.Repeat(stringutil.PasswordDummy, 10)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(updatedWebhook)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleDeleteWebhook deletes a webhook from the database.
 | 
				
			||||||
 | 
					func handleDeleteWebhook(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := app.webhook.Delete(id); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleToggleWebhook toggles the active status of a webhook.
 | 
				
			||||||
 | 
					func handleToggleWebhook(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						toggledWebhook, err := app.webhook.Toggle(id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Clear secret before returning
 | 
				
			||||||
 | 
						toggledWebhook.Secret = strings.Repeat(stringutil.PasswordDummy, 10)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(toggledWebhook)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleTestWebhook sends a test payload to a webhook.
 | 
				
			||||||
 | 
					func handleTestWebhook(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var (
 | 
				
			||||||
 | 
							app   = r.Context.(*App)
 | 
				
			||||||
 | 
							id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if id <= 0 {
 | 
				
			||||||
 | 
							return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "`id`"), nil, envelope.InputError)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := app.webhook.SendTestWebhook(id); err != nil {
 | 
				
			||||||
 | 
							return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.SendEnvelope(true)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// validateWebhook validates the webhook data.
 | 
				
			||||||
 | 
					func validateWebhook(app *App, webhook models.Webhook) error {
 | 
				
			||||||
 | 
						if webhook.Name == "" {
 | 
				
			||||||
 | 
							return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "`name`"), nil)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if webhook.URL == "" {
 | 
				
			||||||
 | 
							return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "`url`"), nil)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(webhook.Events) == 0 {
 | 
				
			||||||
 | 
							return envelope.NewError(envelope.InputError, app.i18n.Ts("globals.messages.empty", "name", "`events`"), nil)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										167
									
								
								cmd/widget_middleware.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										167
									
								
								cmd/widget_middleware.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,167 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/envelope"
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/inbox/channel/livechat"
 | 
				
			||||||
 | 
						imodels "github.com/abhinavxd/libredesk/internal/inbox/models"
 | 
				
			||||||
 | 
						"github.com/valyala/fasthttp"
 | 
				
			||||||
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						// Context keys for storing authenticated widget data
 | 
				
			||||||
 | 
						ctxWidgetClaims    = "widget_claims"
 | 
				
			||||||
 | 
						ctxWidgetInboxID   = "widget_inbox_id"
 | 
				
			||||||
 | 
						ctxWidgetContactID = "widget_contact_id"
 | 
				
			||||||
 | 
						ctxWidgetInbox     = "widget_inbox"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Header sent in every widget request to identify the inbox
 | 
				
			||||||
 | 
						hdrWidgetInboxID = "X-Libredesk-Inbox-ID"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// widgetAuth middleware authenticates widget requests using JWT and inbox validation.
 | 
				
			||||||
 | 
					// It always validates the inbox from X-Libredesk-Inbox-ID header, and conditionally validates JWT.
 | 
				
			||||||
 | 
					// For /conversations/init without JWT, it allows visitor creation while still validating inbox.
 | 
				
			||||||
 | 
					func widgetAuth(next func(*fastglue.Request) error) func(*fastglue.Request) error {
 | 
				
			||||||
 | 
						return func(r *fastglue.Request) error {
 | 
				
			||||||
 | 
							var (
 | 
				
			||||||
 | 
								app = r.Context.(*App)
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Always extract and validate inbox_id from custom header
 | 
				
			||||||
 | 
							inboxIDHeader := string(r.RequestCtx.Request.Header.Peek(hdrWidgetInboxID))
 | 
				
			||||||
 | 
							if inboxIDHeader == "" {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.required", "name", "{globals.terms.inbox}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							inboxID, err := strconv.Atoi(inboxIDHeader)
 | 
				
			||||||
 | 
							if err != nil || inboxID <= 0 {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.invalid", "name", "{globals.terms.inbox}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Always fetch and validate inbox
 | 
				
			||||||
 | 
							inbox, err := app.inbox.GetDBRecord(inboxID)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								app.lo.Error("error fetching inbox", "inbox_id", inboxID, "error", err)
 | 
				
			||||||
 | 
								return sendErrorEnvelope(r, err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if !inbox.Enabled {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.disabled", "name", "{globals.terms.inbox}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Check if inbox is the correct type for widget requests
 | 
				
			||||||
 | 
							if inbox.Channel != livechat.ChannelLiveChat {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.Ts("globals.messages.notFound", "name", "{globals.terms.inbox}"), nil, envelope.InputError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Always store inbox data in context
 | 
				
			||||||
 | 
							r.RequestCtx.SetUserValue(ctxWidgetInboxID, inboxID)
 | 
				
			||||||
 | 
							r.RequestCtx.SetUserValue(ctxWidgetInbox, inbox)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Extract JWT from Authorization header (Bearer token)
 | 
				
			||||||
 | 
							authHeader := string(r.RequestCtx.Request.Header.Peek("Authorization"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// For init endpoint, allow requests without JWT (visitor creation)
 | 
				
			||||||
 | 
							if authHeader == "" && strings.Contains(string(r.RequestCtx.Path()), "/conversations/init") {
 | 
				
			||||||
 | 
								return next(r)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// For all other requests, require JWT
 | 
				
			||||||
 | 
							if authHeader == "" || !strings.HasPrefix(authHeader, "Bearer ") {
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusUnauthorized, app.i18n.T("globals.terms.unAuthorized"), nil, envelope.UnauthorizedError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							jwtToken := strings.TrimPrefix(authHeader, "Bearer ")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Verify JWT using inbox secret
 | 
				
			||||||
 | 
							claims, err := verifyStandardJWT(jwtToken, inbox.Secret.String)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								app.lo.Error("invalid JWT", "jwt", jwtToken, "error", err)
 | 
				
			||||||
 | 
								return r.SendErrorEnvelope(fasthttp.StatusUnauthorized, app.i18n.T("globals.terms.unAuthorized"), nil, envelope.UnauthorizedError)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Resolve user/contact ID from JWT claims
 | 
				
			||||||
 | 
							contactID, err := resolveUserIDFromClaims(app, claims)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								envErr, ok := err.(envelope.Error)
 | 
				
			||||||
 | 
								if ok && envErr.ErrorType != envelope.NotFoundError {
 | 
				
			||||||
 | 
									app.lo.Error("error resolving user ID from JWT claims", "error", err)
 | 
				
			||||||
 | 
									return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, app.i18n.Ts("globals.messages.errorFetching", "name", "{globals.terms.user}"), nil, envelope.GeneralError)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Store authenticated data in request context for downstream handlers
 | 
				
			||||||
 | 
							r.RequestCtx.SetUserValue(ctxWidgetClaims, claims)
 | 
				
			||||||
 | 
							r.RequestCtx.SetUserValue(ctxWidgetContactID, contactID)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return next(r)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Helper functions to extract authenticated data from request context
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// getWidgetInboxID extracts inbox ID from request context
 | 
				
			||||||
 | 
					func getWidgetInboxID(r *fastglue.Request) (int, error) {
 | 
				
			||||||
 | 
						val := r.RequestCtx.UserValue(ctxWidgetInboxID)
 | 
				
			||||||
 | 
						if val == nil {
 | 
				
			||||||
 | 
							return 0, fmt.Errorf("widget middleware not applied: missing inbox ID in context")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						inboxID, ok := val.(int)
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							return 0, fmt.Errorf("invalid inbox ID type in context")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return inboxID, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// getWidgetContactID extracts contact ID from request context
 | 
				
			||||||
 | 
					func getWidgetContactID(r *fastglue.Request) (int, error) {
 | 
				
			||||||
 | 
						val := r.RequestCtx.UserValue(ctxWidgetContactID)
 | 
				
			||||||
 | 
						if val == nil {
 | 
				
			||||||
 | 
							return 0, fmt.Errorf("widget middleware not applied: missing contact ID in context")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						contactID, ok := val.(int)
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							return 0, fmt.Errorf("invalid contact ID type in context")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return contactID, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// getWidgetInbox extracts inbox model from request context
 | 
				
			||||||
 | 
					func getWidgetInbox(r *fastglue.Request) (imodels.Inbox, error) {
 | 
				
			||||||
 | 
						val := r.RequestCtx.UserValue(ctxWidgetInbox)
 | 
				
			||||||
 | 
						if val == nil {
 | 
				
			||||||
 | 
							return imodels.Inbox{}, fmt.Errorf("widget middleware not applied: missing inbox in context")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						inbox, ok := val.(imodels.Inbox)
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							return imodels.Inbox{}, fmt.Errorf("invalid inbox type in context")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return inbox, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// getWidgetClaimsOptional extracts JWT claims from request context, returns nil if not set
 | 
				
			||||||
 | 
					func getWidgetClaimsOptional(r *fastglue.Request) *Claims {
 | 
				
			||||||
 | 
						val := r.RequestCtx.UserValue(ctxWidgetClaims)
 | 
				
			||||||
 | 
						if val == nil {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if claims, ok := val.(Claims); ok {
 | 
				
			||||||
 | 
							return &claims
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// rateLimitWidget applies rate limiting to widget endpoints.
 | 
				
			||||||
 | 
					func rateLimitWidget(handler fastglue.FastRequestHandler) fastglue.FastRequestHandler {
 | 
				
			||||||
 | 
						return func(r *fastglue.Request) error {
 | 
				
			||||||
 | 
							app := r.Context.(*App)
 | 
				
			||||||
 | 
							if err := app.rateLimit.CheckWidgetLimit(r.RequestCtx); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return handler(r)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										272
									
								
								cmd/widget_ws.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										272
									
								
								cmd/widget_ws.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,272 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/abhinavxd/libredesk/internal/inbox/channel/livechat"
 | 
				
			||||||
 | 
						"github.com/fasthttp/websocket"
 | 
				
			||||||
 | 
						"github.com/zerodha/fastglue"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Widget WebSocket message types
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						WidgetMsgTypeJoin    = "join"
 | 
				
			||||||
 | 
						WidgetMsgTypeMessage = "message"
 | 
				
			||||||
 | 
						WidgetMsgTypeTyping  = "typing"
 | 
				
			||||||
 | 
						WidgetMsgTypePing    = "ping"
 | 
				
			||||||
 | 
						WidgetMsgTypePong    = "pong"
 | 
				
			||||||
 | 
						WidgetMsgTypeError   = "error"
 | 
				
			||||||
 | 
						WidgetMsgTypeNewMsg  = "new_message"
 | 
				
			||||||
 | 
						WidgetMsgTypeStatus  = "status"
 | 
				
			||||||
 | 
						WidgetMsgTypeJoined  = "joined"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// WidgetMessage represents a message sent through the widget WebSocket
 | 
				
			||||||
 | 
					type WidgetMessage struct {
 | 
				
			||||||
 | 
						Type string `json:"type"`
 | 
				
			||||||
 | 
						JWT  string `json:"jwt,omitempty"`
 | 
				
			||||||
 | 
						Data any    `json:"data"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type WidgetInboxJoinRequest struct {
 | 
				
			||||||
 | 
						InboxID int `json:"inbox_id"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// WidgetMessageData represents a chat message through the widget
 | 
				
			||||||
 | 
					type WidgetMessageData struct {
 | 
				
			||||||
 | 
						ConversationUUID string `json:"conversation_uuid"`
 | 
				
			||||||
 | 
						Content          string `json:"content"`
 | 
				
			||||||
 | 
						SenderName       string `json:"sender_name,omitempty"`
 | 
				
			||||||
 | 
						SenderType       string `json:"sender_type"`
 | 
				
			||||||
 | 
						Timestamp        int64  `json:"timestamp"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// WidgetTypingData represents typing indicator data
 | 
				
			||||||
 | 
					type WidgetTypingData struct {
 | 
				
			||||||
 | 
						ConversationUUID string `json:"conversation_uuid"`
 | 
				
			||||||
 | 
						IsTyping         bool   `json:"is_typing"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleWidgetWS handles the widget WebSocket connection for live chat.
 | 
				
			||||||
 | 
					func handleWidgetWS(r *fastglue.Request) error {
 | 
				
			||||||
 | 
						var app = r.Context.(*App)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := upgrader.Upgrade(r.RequestCtx, func(conn *websocket.Conn) {
 | 
				
			||||||
 | 
							// To store client and live chat references for cleanup.
 | 
				
			||||||
 | 
							var client *livechat.Client
 | 
				
			||||||
 | 
							var liveChat *livechat.LiveChat
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Clean up client when connection closes.
 | 
				
			||||||
 | 
							defer func() {
 | 
				
			||||||
 | 
								conn.Close()
 | 
				
			||||||
 | 
								if client != nil && liveChat != nil {
 | 
				
			||||||
 | 
									liveChat.RemoveClient(client)
 | 
				
			||||||
 | 
									close(client.Channel)
 | 
				
			||||||
 | 
									app.lo.Debug("cleaned up client on websocket disconnect", "client_id", client.ID)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Read messages from the WebSocket connection.
 | 
				
			||||||
 | 
							for {
 | 
				
			||||||
 | 
								var msg WidgetMessage
 | 
				
			||||||
 | 
								if err := conn.ReadJSON(&msg); err != nil {
 | 
				
			||||||
 | 
									app.lo.Debug("widget websocket connection closed", "error", err)
 | 
				
			||||||
 | 
									break
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								switch msg.Type {
 | 
				
			||||||
 | 
								// Inbox join request.
 | 
				
			||||||
 | 
								case WidgetMsgTypeJoin:
 | 
				
			||||||
 | 
									var joinedClient *livechat.Client
 | 
				
			||||||
 | 
									var joinedLiveChat *livechat.LiveChat
 | 
				
			||||||
 | 
									var err error
 | 
				
			||||||
 | 
									if joinedClient, joinedLiveChat, err = handleInboxJoin(app, conn, &msg); err != nil {
 | 
				
			||||||
 | 
										app.lo.Error("error handling widget join", "error", err)
 | 
				
			||||||
 | 
										sendWidgetError(conn, "Failed to join conversation")
 | 
				
			||||||
 | 
										continue
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									// Store the client and livechat reference for cleanup.
 | 
				
			||||||
 | 
									client = joinedClient
 | 
				
			||||||
 | 
									liveChat = joinedLiveChat
 | 
				
			||||||
 | 
								// Typing.
 | 
				
			||||||
 | 
								case WidgetMsgTypeTyping:
 | 
				
			||||||
 | 
									if err := handleWidgetTyping(app, &msg); err != nil {
 | 
				
			||||||
 | 
										app.lo.Error("error handling widget typing", "error", err)
 | 
				
			||||||
 | 
										continue
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								// Ping.
 | 
				
			||||||
 | 
								case WidgetMsgTypePing:
 | 
				
			||||||
 | 
									if err := conn.WriteJSON(WidgetMessage{
 | 
				
			||||||
 | 
										Type: WidgetMsgTypePong,
 | 
				
			||||||
 | 
									}); err != nil {
 | 
				
			||||||
 | 
										app.lo.Error("error writing pong to widget client", "error", err)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}); err != nil {
 | 
				
			||||||
 | 
							app.lo.Error("error upgrading widget websocket connection", "error", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleInboxJoin handles a websocket join request for a live chat inbox.
 | 
				
			||||||
 | 
					func handleInboxJoin(app *App, conn *websocket.Conn, msg *WidgetMessage) (*livechat.Client, *livechat.LiveChat, error) {
 | 
				
			||||||
 | 
						joinDataBytes, err := json.Marshal(msg.Data)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, nil, fmt.Errorf("invalid join data: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var joinData WidgetInboxJoinRequest
 | 
				
			||||||
 | 
						if err := json.Unmarshal(joinDataBytes, &joinData); err != nil {
 | 
				
			||||||
 | 
							return nil, nil, fmt.Errorf("invalid join data format: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Validate JWT with inbox secret
 | 
				
			||||||
 | 
						claims, err := validateWidgetMessageJWT(app, msg.JWT, joinData.InboxID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, nil, fmt.Errorf("JWT validation failed: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Resolve user ID.
 | 
				
			||||||
 | 
						userID, err := resolveUserIDFromClaims(app, claims)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, nil, fmt.Errorf("failed to resolve user ID from claims: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Make sure inbox is active.
 | 
				
			||||||
 | 
						inbox, err := app.inbox.GetDBRecord(joinData.InboxID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, nil, fmt.Errorf("inbox not found: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !inbox.Enabled {
 | 
				
			||||||
 | 
							return nil, nil, fmt.Errorf("inbox is not enabled")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Get live chat inbox
 | 
				
			||||||
 | 
						lcInbox, err := app.inbox.Get(inbox.ID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, nil, fmt.Errorf("live chat inbox not found: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Assert type.
 | 
				
			||||||
 | 
						liveChat, ok := lcInbox.(*livechat.LiveChat)
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							return nil, nil, fmt.Errorf("inbox is not a live chat inbox")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Add client to live chat session
 | 
				
			||||||
 | 
						userIDStr := fmt.Sprintf("%d", userID)
 | 
				
			||||||
 | 
						client, err := liveChat.AddClient(userIDStr)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							app.lo.Error("error adding client to live chat", "error", err, "user_id", userIDStr)
 | 
				
			||||||
 | 
							return nil, nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Start listening for messages from the live chat channel.
 | 
				
			||||||
 | 
						go func() {
 | 
				
			||||||
 | 
							for msgData := range client.Channel {
 | 
				
			||||||
 | 
								if err := conn.WriteMessage(websocket.TextMessage, msgData); err != nil {
 | 
				
			||||||
 | 
									app.lo.Error("error forwarding message to widget client", "error", err)
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Send join confirmation
 | 
				
			||||||
 | 
						joinResp := WidgetMessage{
 | 
				
			||||||
 | 
							Type: WidgetMsgTypeJoined,
 | 
				
			||||||
 | 
							Data: map[string]string{
 | 
				
			||||||
 | 
								"message": "namaste!",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := conn.WriteJSON(joinResp); err != nil {
 | 
				
			||||||
 | 
							return nil, nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						app.lo.Debug("widget client joined live chat", "user_id", userIDStr, "inbox_id", joinData.InboxID)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return client, liveChat, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// handleWidgetTyping handles typing indicators
 | 
				
			||||||
 | 
					func handleWidgetTyping(app *App, msg *WidgetMessage) error {
 | 
				
			||||||
 | 
						typingDataBytes, err := json.Marshal(msg.Data)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							app.lo.Error("error marshalling typing data", "error", err)
 | 
				
			||||||
 | 
							return fmt.Errorf("invalid typing data: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var typingData WidgetTypingData
 | 
				
			||||||
 | 
						if err := json.Unmarshal(typingDataBytes, &typingData); err != nil {
 | 
				
			||||||
 | 
							app.lo.Error("error unmarshalling typing data", "error", err)
 | 
				
			||||||
 | 
							return fmt.Errorf("invalid typing data format: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Get conversation to retrieve inbox ID for JWT validation
 | 
				
			||||||
 | 
						if typingData.ConversationUUID == "" {
 | 
				
			||||||
 | 
							return fmt.Errorf("conversation UUID is required for typing messages")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						conversation, err := app.conversation.GetConversation(0, typingData.ConversationUUID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							app.lo.Error("error fetching conversation for typing", "conversation_uuid", typingData.ConversationUUID, "error", err)
 | 
				
			||||||
 | 
							return fmt.Errorf("conversation not found: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Validate JWT with inbox secret
 | 
				
			||||||
 | 
						claims, err := validateWidgetMessageJWT(app, msg.JWT, conversation.InboxID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("JWT validation failed: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						userID := claims.UserID
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Broadcast typing status to agents via conversation manager
 | 
				
			||||||
 | 
						// Set broadcastToWidgets=false to avoid echoing back to widget clients
 | 
				
			||||||
 | 
						app.conversation.BroadcastTypingToConversation(typingData.ConversationUUID, typingData.IsTyping, false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						app.lo.Debug("Broadcasted typing data from widget user to agents", "user_id", userID, "is_typing", typingData.IsTyping, "conversation_uuid", typingData.ConversationUUID)
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// validateWidgetMessageJWT validates the incoming widget message JWT using inbox secret
 | 
				
			||||||
 | 
					func validateWidgetMessageJWT(app *App, jwtToken string, inboxID int) (Claims, error) {
 | 
				
			||||||
 | 
						if jwtToken == "" {
 | 
				
			||||||
 | 
							return Claims{}, fmt.Errorf("JWT token is empty")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if inboxID <= 0 {
 | 
				
			||||||
 | 
							return Claims{}, fmt.Errorf("inbox ID is required for JWT validation")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Get inbox to retrieve secret for JWT verification
 | 
				
			||||||
 | 
						inbox, err := app.inbox.GetDBRecord(inboxID)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return Claims{}, fmt.Errorf("inbox not found: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !inbox.Secret.Valid || inbox.Secret.String == "" {
 | 
				
			||||||
 | 
							return Claims{}, fmt.Errorf("inbox secret not configured for JWT verification")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Use the existing verifyStandardJWT function which properly validates with inbox secret
 | 
				
			||||||
 | 
						claims, err := verifyStandardJWT(jwtToken, inbox.Secret.String)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return Claims{}, fmt.Errorf("JWT validation failed: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return claims, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// sendWidgetError sends an error message to the widget client
 | 
				
			||||||
 | 
					func sendWidgetError(conn *websocket.Conn, message string) {
 | 
				
			||||||
 | 
						errorMsg := WidgetMessage{
 | 
				
			||||||
 | 
							Type: WidgetMsgTypeError,
 | 
				
			||||||
 | 
							Data: map[string]string{
 | 
				
			||||||
 | 
								"message": message,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						conn.WriteJSON(errorMsg)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,80 +1,158 @@
 | 
				
			|||||||
# App.
 | 
					 | 
				
			||||||
[app]
 | 
					[app]
 | 
				
			||||||
 | 
					# Log level: info, debug, warn, error, fatal
 | 
				
			||||||
log_level = "debug"
 | 
					log_level = "debug"
 | 
				
			||||||
 | 
					# Environment: dev, prod.
 | 
				
			||||||
 | 
					# Setting to "dev" will enable color logging in terminal.
 | 
				
			||||||
env = "dev"
 | 
					env = "dev"
 | 
				
			||||||
 | 
					# Whether to automatically check for application updates on start up, app updates are shown as a banner in the admin panel.
 | 
				
			||||||
check_updates = true
 | 
					check_updates = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# HTTP server.
 | 
					# HTTP server.
 | 
				
			||||||
[app.server]
 | 
					[app.server]
 | 
				
			||||||
 | 
					# Address to bind the HTTP server to.
 | 
				
			||||||
address = "0.0.0.0:9000"
 | 
					address = "0.0.0.0:9000"
 | 
				
			||||||
 | 
					# Unix socket path (leave empty to use TCP address instead)
 | 
				
			||||||
socket = ""
 | 
					socket = ""
 | 
				
			||||||
# Do NOT disable secure cookies in production environment if you don't know
 | 
					# Do NOT disable secure cookies in production environment if you don't know exactly what you're doing!
 | 
				
			||||||
# exactly what you're doing!
 | 
					 | 
				
			||||||
disable_secure_cookies = false
 | 
					disable_secure_cookies = false
 | 
				
			||||||
 | 
					# Request read and write timeouts.
 | 
				
			||||||
read_timeout = "5s"
 | 
					read_timeout = "5s"
 | 
				
			||||||
write_timeout = "5s"
 | 
					write_timeout = "5s"
 | 
				
			||||||
max_body_size = 500000000
 | 
					# Maximum request body size in bytes (100MB)
 | 
				
			||||||
 | 
					# If you are using proxy, you may need to configure them to allow larger request bodies.
 | 
				
			||||||
 | 
					max_body_size = 104857600
 | 
				
			||||||
 | 
					# Size of the read buffer for incoming requests
 | 
				
			||||||
read_buffer_size = 4096
 | 
					read_buffer_size = 4096
 | 
				
			||||||
 | 
					# Keepalive settings.
 | 
				
			||||||
keepalive_timeout = "10s"
 | 
					keepalive_timeout = "10s"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# File upload provider to use, either `fs` or `s3`.
 | 
					# File upload provider to use, either `fs` or `s3`.
 | 
				
			||||||
[upload]
 | 
					[upload]
 | 
				
			||||||
provider = "fs"
 | 
					provider = "fs"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Filesytem provider.
 | 
					# Filesystem provider.
 | 
				
			||||||
[upload.fs]
 | 
					[upload.fs]
 | 
				
			||||||
 | 
					# Directory where uploaded files are stored, make sure this directory exists and is writable by the application.
 | 
				
			||||||
upload_path = 'uploads'
 | 
					upload_path = 'uploads'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# S3 provider.
 | 
					# S3 provider.
 | 
				
			||||||
[upload.s3]
 | 
					[upload.s3]
 | 
				
			||||||
 | 
					# S3 endpoint URL (required only for non-AWS S3-compatible providers like MinIO).
 | 
				
			||||||
 | 
					# Leave empty to use default AWS endpoints.
 | 
				
			||||||
url = ""
 | 
					url = ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# AWS S3 credentials, keep empty to use attached IAM roles.
 | 
				
			||||||
access_key = ""
 | 
					access_key = ""
 | 
				
			||||||
secret_key = ""
 | 
					secret_key = ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# AWS region, e.g., "us-east-1", "eu-west-1", etc.
 | 
				
			||||||
region = "ap-south-1"
 | 
					region = "ap-south-1"
 | 
				
			||||||
bucket = "bucket"
 | 
					# S3 bucket name where files will be stored.
 | 
				
			||||||
 | 
					bucket = "bucket-name"
 | 
				
			||||||
 | 
					# Optional prefix path within the S3 bucket where files will be stored.
 | 
				
			||||||
 | 
					# Example, if set to "uploads/media", files will be stored under that path.
 | 
				
			||||||
 | 
					# Useful for organizing files inside a shared bucket.
 | 
				
			||||||
bucket_path = ""
 | 
					bucket_path = ""
 | 
				
			||||||
expiry = "6h"
 | 
					# S3 signed URL expiry duration (e.g., "30m", "1h")
 | 
				
			||||||
 | 
					expiry = "30m"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Postgres.
 | 
					# Postgres.
 | 
				
			||||||
[db]
 | 
					[db]
 | 
				
			||||||
# If using docker compose, use the service name as the host. e.g. db
 | 
					# If running locally, use `localhost`.
 | 
				
			||||||
host = "127.0.0.1"
 | 
					host = "db"
 | 
				
			||||||
 | 
					# Database port, default is 5432.
 | 
				
			||||||
port = 5432
 | 
					port = 5432
 | 
				
			||||||
# Update the following values with your database credentials.
 | 
					# Update the following values with your database credentials.
 | 
				
			||||||
user = "libredesk"
 | 
					user = "libredesk"
 | 
				
			||||||
password = "libredesk"
 | 
					password = "libredesk"
 | 
				
			||||||
database = "libredesk"
 | 
					database = "libredesk"
 | 
				
			||||||
ssl_mode = "disable"
 | 
					ssl_mode = "disable"
 | 
				
			||||||
 | 
					# Maximum number of open database connections
 | 
				
			||||||
max_open = 30
 | 
					max_open = 30
 | 
				
			||||||
 | 
					# Maximum number of idle connections in the pool
 | 
				
			||||||
max_idle = 30
 | 
					max_idle = 30
 | 
				
			||||||
 | 
					# Maximum time a connection can be reused before being closed
 | 
				
			||||||
max_lifetime = "300s"
 | 
					max_lifetime = "300s"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Redis.
 | 
					# Redis.
 | 
				
			||||||
[redis]
 | 
					[redis]
 | 
				
			||||||
# If using docker compose, use the service name as the host. e.g. redis:6379
 | 
					# If running locally, use `localhost:6379`.
 | 
				
			||||||
address = "127.0.0.1:6379"
 | 
					address = "redis:6379"
 | 
				
			||||||
password = ""
 | 
					password = ""
 | 
				
			||||||
db = 0
 | 
					db = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[message]
 | 
					[message]
 | 
				
			||||||
 | 
					# Number of workers processing outgoing message queue
 | 
				
			||||||
outgoing_queue_workers = 10
 | 
					outgoing_queue_workers = 10
 | 
				
			||||||
 | 
					# Number of workers processing incoming message queue
 | 
				
			||||||
incoming_queue_workers = 10
 | 
					incoming_queue_workers = 10
 | 
				
			||||||
message_outoing_scan_interval = "50ms"
 | 
					# How often to scan for outgoing messages to process, keep it low to process messages quickly.
 | 
				
			||||||
 | 
					message_outgoing_scan_interval = "50ms"
 | 
				
			||||||
 | 
					# Maximum number of messages that can be queued for incoming processing
 | 
				
			||||||
incoming_queue_size = 5000
 | 
					incoming_queue_size = 5000
 | 
				
			||||||
 | 
					# Maximum number of messages that can be queued for outgoing processing
 | 
				
			||||||
outgoing_queue_size = 5000
 | 
					outgoing_queue_size = 5000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[notification]
 | 
					[notification]
 | 
				
			||||||
 | 
					# Number of concurrent notification workers
 | 
				
			||||||
concurrency = 2
 | 
					concurrency = 2
 | 
				
			||||||
 | 
					# Maximum number of notifications that can be queued
 | 
				
			||||||
queue_size = 2000
 | 
					queue_size = 2000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[automation]
 | 
					[automation]
 | 
				
			||||||
 | 
					# Number of workers processing automation rules
 | 
				
			||||||
worker_count = 10
 | 
					worker_count = 10
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[autoassigner]
 | 
					[autoassigner]
 | 
				
			||||||
 | 
					# How often to run automatic conversation assignment
 | 
				
			||||||
autoassign_interval = "5m"
 | 
					autoassign_interval = "5m"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[webhook]
 | 
				
			||||||
 | 
					# Number of webhook delivery workers
 | 
				
			||||||
 | 
					workers = 5
 | 
				
			||||||
 | 
					# Maximum number of webhook deliveries that can be queued
 | 
				
			||||||
 | 
					queue_size = 10000
 | 
				
			||||||
 | 
					# HTTP timeout for webhook requests
 | 
				
			||||||
 | 
					timeout = "15s"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[conversation]
 | 
					[conversation]
 | 
				
			||||||
 | 
					# How often to check for conversations to unsnooze
 | 
				
			||||||
unsnooze_interval = "5m"
 | 
					unsnooze_interval = "5m"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[sla]
 | 
					[sla]
 | 
				
			||||||
 | 
					# How often to evaluate SLA compliance for conversations
 | 
				
			||||||
evaluation_interval = "5m"
 | 
					evaluation_interval = "5m"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[rate_limit]
 | 
				
			||||||
 | 
					[rate_limit.widget]
 | 
				
			||||||
 | 
					enabled = true
 | 
				
			||||||
 | 
					requests_per_minute = 100
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[ai]
 | 
				
			||||||
 | 
					[ai.embedding]
 | 
				
			||||||
 | 
					provider = "openai"
 | 
				
			||||||
 | 
					url = "https://api.openai.com/v1/embeddings"
 | 
				
			||||||
 | 
					api_key = "secret"
 | 
				
			||||||
 | 
					model = "text-embedding-3-small"
 | 
				
			||||||
 | 
					timeout = "20s"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[ai.embedding.chunking]
 | 
				
			||||||
 | 
					# Maximum tokens per chunk (increase for larger context models)
 | 
				
			||||||
 | 
					max_tokens = 2000
 | 
				
			||||||
 | 
					# Minimum tokens per chunk (smaller chunks may lack context)
 | 
				
			||||||
 | 
					min_tokens = 400
 | 
				
			||||||
 | 
					# Overlap tokens between chunks for context continuity
 | 
				
			||||||
 | 
					overlap_tokens = 150
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[ai.completion]
 | 
				
			||||||
 | 
					provider = "openai"
 | 
				
			||||||
 | 
					url = "https://api.openai.com/v1/chat/completions"
 | 
				
			||||||
 | 
					api_key = "secret"
 | 
				
			||||||
 | 
					model = "gpt-oss:20b"
 | 
				
			||||||
 | 
					temperature = 0.2
 | 
				
			||||||
 | 
					max_tokens = 1000
 | 
				
			||||||
 | 
					timeout = "30s"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[ai.worker]
 | 
				
			||||||
 | 
					workers = 50
 | 
				
			||||||
 | 
					capacity = 10000
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										30
									
								
								docs/docs/api-getting-started.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								docs/docs/api-getting-started.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					# API getting started
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You can access the Libredesk API to interact with your instance programmatically.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Generating API keys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. **Edit agent**: Go to Admin → Teammate → Agent → Edit
 | 
				
			||||||
 | 
					2. **Generate new API key**: An API Key and API Secret will be generated for the agent
 | 
				
			||||||
 | 
					3. **Save the credentials**: Keep both the API Key and API Secret secure
 | 
				
			||||||
 | 
					4. **Key management**: You can revoke / regenerate API keys at any time from the same page
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Using the API
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					LibreDesk supports two authentication schemes:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Basic authentication
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					curl -X GET "https://your-libredesk-instance.com/api/endpoint" \
 | 
				
			||||||
 | 
					  -H "Authorization: Basic <base64_encoded_key:secret>"
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Token authentication
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					curl -X GET "https://your-libredesk-instance.com/api/endpoint" \
 | 
				
			||||||
 | 
					  -H "Authorization: token your_api_key:your_api_secret"
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## API Documentation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Complete API documentation with available endpoints and examples coming soon.
 | 
				
			||||||
@@ -4,9 +4,10 @@ Libredesk is a monorepo with a Go backend and a Vue.js frontend. The frontend us
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
### Pre-requisites
 | 
					### Pre-requisites
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- `go`
 | 
					- go
 | 
				
			||||||
- `nodejs` (if you are working on the frontend) and `pnpm`
 | 
					- nodejs (if you are working on the frontend) and `pnpm`
 | 
				
			||||||
- Postgres database (>= 13)
 | 
					- redis
 | 
				
			||||||
 | 
					- postgres database (>= 13)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### First time setup
 | 
					### First time setup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										
											BIN
										
									
								
								docs/docs/images/hero.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								docs/docs/images/hero.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 298 KiB  | 
@@ -1,13 +1,17 @@
 | 
				
			|||||||
# Introduction
 | 
					# Introduction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Libredesk is an open source, self-hosted customer support desk. Single binary app.
 | 
					Libredesk is an open-source, self-hosted customer support desk — single binary app.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<div style="border: 1px solid #ccc; padding: 2px; border-radius: 6px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1); background-color: #f9f9f9;">
 | 
				
			||||||
<div style="border: 1px solid #ccc; padding: 1px; border-radius:5px; box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1); background-color: #fff;">
 | 
					 | 
				
			||||||
  <a href="https://libredesk.io">
 | 
					  <a href="https://libredesk.io">
 | 
				
			||||||
        <img src="https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-HvmxvOkalQSLp4qVezdTXaCd3dB4Rm.png" alt="libredesk screenshot" style="display: block; margin: 0 auto;">
 | 
					    <img src="images/hero.png" alt="libredesk UI screenshot" style="display: block; margin: 0 auto; max-width: 100%; border-radius: 4px;" />
 | 
				
			||||||
  </a>
 | 
					  </a>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Developers
 | 
					## Developers
 | 
				
			||||||
Libredesk is a free and open source software licensed under AGPLv3. If you are interested in contributing, check out the [GitHub repository](https://github.com/abhinavxd/libredesk) and refer to the [developer setup](developer-setup.md). The backend is written in Go and the frontend is Vue js 3 with Shadcn for UI components.
 | 
					
 | 
				
			||||||
 | 
					Libredesk is licensed under AGPLv3. Contributions are welcome.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Source code: [GitHub](https://github.com/abhinavxd/libredesk)
 | 
				
			||||||
 | 
					- Setup guide: [Developer setup](developer-setup.md)
 | 
				
			||||||
 | 
					- Stack: Go backend, Vue 3 frontend (Shadcn UI)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,8 +27,6 @@ curl -LO https://github.com/abhinavxd/libredesk/raw/main/config.sample.toml
 | 
				
			|||||||
# Copy the config.sample.toml to config.toml and edit it as needed.
 | 
					# Copy the config.sample.toml to config.toml and edit it as needed.
 | 
				
			||||||
cp config.sample.toml config.toml
 | 
					cp config.sample.toml config.toml
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Edit config.toml and find commented lines containing "docker compose". Replace the values in the lines below those comments with service names instead of IP addresses.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Run the services in the background.
 | 
					# Run the services in the background.
 | 
				
			||||||
docker compose up -d
 | 
					docker compose up -d
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
# Templating
 | 
					# Templating
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Templating in outgoing emails allows you to personalize content by embedding dynamic expressions like `{{ .Recipient.FullName }}`. These expressions reference fields from the conversation, contact, and recipient objects.
 | 
					Templating in outgoing emails allows you to personalize content by embedding dynamic expressions like `{{ .Recipient.FullName }}`. These expressions reference fields from the conversation, contact, recipient, and author objects.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Outgoing Email Template Expressions
 | 
					## Outgoing Email Template Expressions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -12,9 +12,11 @@ If you want to customize the look of outgoing emails, you can do so in the Admin
 | 
				
			|||||||
|---------------------------------|--------------------------------------------------------|
 | 
					|---------------------------------|--------------------------------------------------------|
 | 
				
			||||||
| {{ .Conversation.ReferenceNumber }} | The unique reference number of the conversation |
 | 
					| {{ .Conversation.ReferenceNumber }} | The unique reference number of the conversation |
 | 
				
			||||||
| {{ .Conversation.Subject }} | The subject of the conversation |
 | 
					| {{ .Conversation.Subject }} | The subject of the conversation |
 | 
				
			||||||
 | 
					| {{ .Conversation.Priority }} | The priority level of the conversation |
 | 
				
			||||||
| {{ .Conversation.UUID }} | The unique identifier of the conversation |
 | 
					| {{ .Conversation.UUID }} | The unique identifier of the conversation |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Contact Variables
 | 
					### Contact Variables
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| Variable | Value |
 | 
					| Variable | Value |
 | 
				
			||||||
|------------------------------|------------------------------------|
 | 
					|------------------------------|------------------------------------|
 | 
				
			||||||
| {{ .Contact.FirstName }} | First name of the contact/customer |
 | 
					| {{ .Contact.FirstName }} | First name of the contact/customer |
 | 
				
			||||||
@@ -23,6 +25,7 @@ If you want to customize the look of outgoing emails, you can do so in the Admin
 | 
				
			|||||||
| {{ .Contact.Email }} | Email address of the contact/customer |
 | 
					| {{ .Contact.Email }} | Email address of the contact/customer |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Recipient Variables
 | 
					### Recipient Variables
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| Variable | Value |
 | 
					| Variable | Value |
 | 
				
			||||||
|--------------------------------|-----------------------------------|
 | 
					|--------------------------------|-----------------------------------|
 | 
				
			||||||
| {{ .Recipient.FirstName }} | First name of the recipient |
 | 
					| {{ .Recipient.FirstName }} | First name of the recipient |
 | 
				
			||||||
@@ -30,14 +33,28 @@ If you want to customize the look of outgoing emails, you can do so in the Admin
 | 
				
			|||||||
| {{ .Recipient.FullName }} | Full name of the recipient |
 | 
					| {{ .Recipient.FullName }} | Full name of the recipient |
 | 
				
			||||||
| {{ .Recipient.Email }} | Email address of the recipient |
 | 
					| {{ .Recipient.Email }} | Email address of the recipient |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Author Variables
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					| Variable | Value |
 | 
				
			||||||
 | 
					|------------------------------|-----------------------------------|
 | 
				
			||||||
 | 
					| {{ .Author.FirstName }} | First name of the message author |
 | 
				
			||||||
 | 
					| {{ .Author.LastName }} | Last name of the message author |
 | 
				
			||||||
 | 
					| {{ .Author.FullName }} | Full name of the message author |
 | 
				
			||||||
 | 
					| {{ .Author.Email }} | Email address of the message author |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Example outgoing email template
 | 
					### Example outgoing email template
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```html
 | 
					```html
 | 
				
			||||||
Dear {{ .Recipient.FirstName }}
 | 
					Dear {{ .Recipient.FirstName }},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{{ template "content" . }}
 | 
					{{ template "content" . }}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Best regards,
 | 
					Best regards,
 | 
				
			||||||
 | 
					{{ .Author.FullName }}
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					Reference: {{ .Conversation.ReferenceNumber }}
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Here, the `{{ template "content" . }}` serves as a placeholder for the body of the outgoing email. It will be replaced with the actual email content at the time of sending.
 | 
					Here, the `{{ template "content" . }}` serves as a placeholder for the body of the outgoing email. It will be replaced with the actual email content at the time of sending.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Similarly, the `{{ .Recipient.FirstName }}` expression will dynamically insert the recipient's first name when the email is sent.
 | 
					Similarly, the `{{ .Recipient.FirstName }}` expression will dynamically insert the recipient's first name when the email is sent.
 | 
				
			||||||
@@ -1,3 +1,3 @@
 | 
				
			|||||||
# Translations / Internationalization
 | 
					# Translations / Internationalization
 | 
				
			||||||
 | 
					
 | 
				
			||||||
You can help translate libreDesk into different languages by contributing here: [LibreDesk Translation Project](https://crowdin.com/project/libredesk)
 | 
					You can help translate libreDesk into different languages by contributing here: [Libredesk Translation Project](https://crowdin.com/project/libredesk)
 | 
				
			||||||
							
								
								
									
										222
									
								
								docs/docs/webhooks.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										222
									
								
								docs/docs/webhooks.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,222 @@
 | 
				
			|||||||
 | 
					# Webhooks
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Webhooks allow you to receive real-time HTTP notifications when specific events occur in your Libredesk instance. This enables you to integrate Libredesk with external systems and automate workflows based on conversation and message events.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Overview
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					When a configured event occurs in Libredesk, a HTTP POST request is sent to the webhook URL you specify. The request contains a JSON payload with event details and relevant data.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Webhook Configuration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. Navigate to **Admin > Integrations > Webhooks** in your Libredesk dashboard
 | 
				
			||||||
 | 
					2. Click **Create Webhook**
 | 
				
			||||||
 | 
					3. Configure the following:
 | 
				
			||||||
 | 
					   - **Name**: A descriptive name for your webhook
 | 
				
			||||||
 | 
					   - **URL**: The endpoint URL where webhook payloads will be sent
 | 
				
			||||||
 | 
					   - **Events**: Select which events you want to subscribe to
 | 
				
			||||||
 | 
					   - **Secret**: Optional secret key for signature verification
 | 
				
			||||||
 | 
					   - **Status**: Enable or disable the webhook
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Security
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Signature Verification
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If you provide a secret key, webhook payloads will be signed using HMAC-SHA256. The signature is included in the `X-Signature-256` header in the format `sha256=<signature>`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To verify the signature:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```python
 | 
				
			||||||
 | 
					import hmac
 | 
				
			||||||
 | 
					import hashlib
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def verify_signature(payload, signature, secret):
 | 
				
			||||||
 | 
					    expected_signature = hmac.new(
 | 
				
			||||||
 | 
					        secret.encode('utf-8'),
 | 
				
			||||||
 | 
					        payload,
 | 
				
			||||||
 | 
					        hashlib.sha256
 | 
				
			||||||
 | 
					    ).hexdigest()
 | 
				
			||||||
 | 
					    return hmac.compare_digest(f"sha256={expected_signature}", signature)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Headers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Each webhook request includes the following headers:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- `Content-Type`: `application/json`
 | 
				
			||||||
 | 
					- `User-Agent`: `Libredesk-Webhook/<libredesk_version_here>`
 | 
				
			||||||
 | 
					- `X-Signature-256`: HMAC signature (if secret is configured)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Available Events
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Conversation Events
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### `conversation.created`
 | 
				
			||||||
 | 
					Triggered when a new conversation is created.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Sample Payload:**
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "event": "conversation.created",
 | 
				
			||||||
 | 
					  "timestamp": "2025-06-15T10:30:00Z",
 | 
				
			||||||
 | 
					  "payload": {
 | 
				
			||||||
 | 
					    "id": 123,
 | 
				
			||||||
 | 
					    "created_at": "2025-06-15T10:30:00Z",
 | 
				
			||||||
 | 
					    "updated_at": "2025-06-15T10:30:00Z",
 | 
				
			||||||
 | 
					    "uuid": "550e8400-e29b-41d4-a716-446655440000",
 | 
				
			||||||
 | 
					    "contact_id": 456,
 | 
				
			||||||
 | 
					    "inbox_id": 1,
 | 
				
			||||||
 | 
					    "reference_number": "100",
 | 
				
			||||||
 | 
					    "priority": "Medium",
 | 
				
			||||||
 | 
					    "priority_id": 2,
 | 
				
			||||||
 | 
					    "status": "Open",
 | 
				
			||||||
 | 
					    "status_id": 1,
 | 
				
			||||||
 | 
					    "subject": "Help with account setup",
 | 
				
			||||||
 | 
					    "inbox_name": "Support",
 | 
				
			||||||
 | 
					    "inbox_channel": "email",
 | 
				
			||||||
 | 
					    "contact": {
 | 
				
			||||||
 | 
					      "id": 456,
 | 
				
			||||||
 | 
					      "first_name": "John",
 | 
				
			||||||
 | 
					      "last_name": "Doe",
 | 
				
			||||||
 | 
					      "email": "john.doe@example.com",
 | 
				
			||||||
 | 
					      "type": "contact"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "custom_attributes": {},
 | 
				
			||||||
 | 
					    "tags": []
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### `conversation.status_changed`
 | 
				
			||||||
 | 
					Triggered when a conversation's status is updated.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Sample Payload:**
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "event": "conversation.status_changed",
 | 
				
			||||||
 | 
					  "timestamp": "2025-06-15T10:35:00Z",
 | 
				
			||||||
 | 
					  "payload": {
 | 
				
			||||||
 | 
					    "conversation_uuid": "550e8400-e29b-41d4-a716-446655440000",
 | 
				
			||||||
 | 
					    "previous_status": "Open",
 | 
				
			||||||
 | 
					    "new_status": "Resolved",
 | 
				
			||||||
 | 
					    "snooze_until": "",
 | 
				
			||||||
 | 
					    "actor_id": 789
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### `conversation.assigned`
 | 
				
			||||||
 | 
					Triggered when a conversation is assigned to a user.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Sample Payload:**
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "event": "conversation.assigned",
 | 
				
			||||||
 | 
					  "timestamp": "2025-06-15T10:32:00Z",
 | 
				
			||||||
 | 
					  "payload": {
 | 
				
			||||||
 | 
					    "conversation_uuid": "550e8400-e29b-41d4-a716-446655440000",
 | 
				
			||||||
 | 
					    "assigned_to": 789,
 | 
				
			||||||
 | 
					    "actor_id": 789
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### `conversation.unassigned`
 | 
				
			||||||
 | 
					Triggered when a conversation is unassigned from a user.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Sample Payload:**
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "event": "conversation.unassigned",
 | 
				
			||||||
 | 
					  "timestamp": "2025-06-15T10:40:00Z",
 | 
				
			||||||
 | 
					  "payload": {
 | 
				
			||||||
 | 
					    "conversation_uuid": "550e8400-e29b-41d4-a716-446655440000",
 | 
				
			||||||
 | 
					    "actor_id": 789
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### `conversation.tags_changed`
 | 
				
			||||||
 | 
					Triggered when tags are added or removed from a conversation.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Sample Payload:**
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "event": "conversation.tags_changed",
 | 
				
			||||||
 | 
					  "timestamp": "2025-06-15T10:45:00Z",
 | 
				
			||||||
 | 
					  "payload": {
 | 
				
			||||||
 | 
					    "conversation_uuid": "550e8400-e29b-41d4-a716-446655440000",
 | 
				
			||||||
 | 
					    "previous_tags": ["bug", "priority"],
 | 
				
			||||||
 | 
					    "new_tags": ["bug", "priority", "resolved"],
 | 
				
			||||||
 | 
					    "actor_id": 789
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Message Events
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### `message.created`
 | 
				
			||||||
 | 
					Triggered when a new message is created in a conversation.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Sample Payload:**
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "event": "message.created",
 | 
				
			||||||
 | 
					  "timestamp": "2025-06-15T10:33:00Z",
 | 
				
			||||||
 | 
					  "payload": {
 | 
				
			||||||
 | 
					    "id": 987,
 | 
				
			||||||
 | 
					    "created_at": "2025-06-15T10:33:00Z",
 | 
				
			||||||
 | 
					    "updated_at": "2025-06-15T10:33:00Z",
 | 
				
			||||||
 | 
					    "uuid": "123e4567-e89b-12d3-a456-426614174000",
 | 
				
			||||||
 | 
					    "type": "outgoing",
 | 
				
			||||||
 | 
					    "status": "sent",
 | 
				
			||||||
 | 
					    "conversation_id": 123,
 | 
				
			||||||
 | 
					    "content": "<p>Hello! How can I help you today?</p>",
 | 
				
			||||||
 | 
					    "text_content": "Hello! How can I help you today?",
 | 
				
			||||||
 | 
					    "content_type": "html",
 | 
				
			||||||
 | 
					    "private": false,
 | 
				
			||||||
 | 
					    "sender_id": 789,
 | 
				
			||||||
 | 
					    "sender_type": "agent",
 | 
				
			||||||
 | 
					    "attachments": []
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### `message.updated`
 | 
				
			||||||
 | 
					Triggered when an existing message is updated.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Sample Payload:**
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "event": "message.updated",
 | 
				
			||||||
 | 
					  "timestamp": "2025-06-15T10:34:00Z",
 | 
				
			||||||
 | 
					  "payload": {
 | 
				
			||||||
 | 
					    "id": 987,
 | 
				
			||||||
 | 
					    "created_at": "2025-06-15T10:33:00Z",
 | 
				
			||||||
 | 
					    "updated_at": "2025-06-15T10:34:00Z",
 | 
				
			||||||
 | 
					    "uuid": "123e4567-e89b-12d3-a456-426614174000",
 | 
				
			||||||
 | 
					    "type": "outgoing",
 | 
				
			||||||
 | 
					    "status": "sent",
 | 
				
			||||||
 | 
					    "conversation_id": 123,
 | 
				
			||||||
 | 
					    "content": "<p>Hello! How can I help you today? (Updated)</p>",
 | 
				
			||||||
 | 
					    "text_content": "Hello! How can I help you today? (Updated)",
 | 
				
			||||||
 | 
					    "content_type": "html",
 | 
				
			||||||
 | 
					    "private": false,
 | 
				
			||||||
 | 
					    "sender_id": 789,
 | 
				
			||||||
 | 
					    "sender_type": "agent",
 | 
				
			||||||
 | 
					    "attachments": []
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Delivery and Retries
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Webhooks requests timeout can be configured in the `config.toml` file
 | 
				
			||||||
 | 
					- Failed deliveries are not automatically retried
 | 
				
			||||||
 | 
					- Webhook delivery runs in a background worker pool for better performance
 | 
				
			||||||
 | 
					- If the webhook queue is full (configurable in config.toml file), new events may be dropped
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Testing Webhooks
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You can test your webhook configuration using tools like:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- [Webhook.site](https://webhook.site) - Generate a temporary URL to inspect webhook payloads
 | 
				
			||||||
@@ -1,13 +1,11 @@
 | 
				
			|||||||
site_name: Libredesk Documentation
 | 
					site_name: Libredesk Docs
 | 
				
			||||||
theme:
 | 
					theme:
 | 
				
			||||||
  name: material
 | 
					  name: material
 | 
				
			||||||
  language: en
 | 
					  language: en
 | 
				
			||||||
  font:
 | 
					  font:
 | 
				
			||||||
    text: Source Sans Pro
 | 
					    text: Source Sans Pro
 | 
				
			||||||
    code: Roboto Mono
 | 
					    code: Roboto Mono
 | 
				
			||||||
    weights: 
 | 
					    weights: [400, 700]
 | 
				
			||||||
      - 400
 | 
					 | 
				
			||||||
      - 700
 | 
					 | 
				
			||||||
  direction: ltr
 | 
					  direction: ltr
 | 
				
			||||||
  palette:
 | 
					  palette:
 | 
				
			||||||
    primary: white
 | 
					    primary: white
 | 
				
			||||||
@@ -30,9 +28,11 @@ nav:
 | 
				
			|||||||
  - Introduction: index.md
 | 
					  - Introduction: index.md
 | 
				
			||||||
  - Getting Started:
 | 
					  - Getting Started:
 | 
				
			||||||
      - Installation: installation.md
 | 
					      - Installation: installation.md
 | 
				
			||||||
      - Upgrade: upgrade.md
 | 
					      - Upgrade Guide: upgrade.md
 | 
				
			||||||
      - Templating: templating.md
 | 
					      - Email Templates: templating.md
 | 
				
			||||||
      - SSO: sso.md
 | 
					      - SSO Setup: sso.md
 | 
				
			||||||
  - Contributors:
 | 
					      - Webhooks: webhooks.md
 | 
				
			||||||
      - Developer setup: developer-setup.md
 | 
					      - API Getting Started: api-getting-started.md
 | 
				
			||||||
      - Translations: translations.md
 | 
					  - Contributions:
 | 
				
			||||||
 | 
					      - Developer Setup: developer-setup.md
 | 
				
			||||||
 | 
					      - Translate Libredesk: translations.md
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										59
									
								
								frontend/README-SETUP.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								frontend/README-SETUP.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,59 @@
 | 
				
			|||||||
 | 
					# Libredesk Frontend - Multi-App Setup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This frontend supports both the main Libredesk application and a chat widget as separate Vue applications sharing common UI components.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Project Structure
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					frontend/
 | 
				
			||||||
 | 
					├── apps/
 | 
				
			||||||
 | 
					│   ├── main/          # Main Libredesk application
 | 
				
			||||||
 | 
					│   │   ├── src/
 | 
				
			||||||
 | 
					│   │   └── index.html
 | 
				
			||||||
 | 
					│   └── widget/        # Chat widget application
 | 
				
			||||||
 | 
					│       ├── src/
 | 
				
			||||||
 | 
					│       └── index.html
 | 
				
			||||||
 | 
					├── shared-ui/         # Shared UI components (shadcn/ui)
 | 
				
			||||||
 | 
					│   ├── components/
 | 
				
			||||||
 | 
					│   │   └── ui/        # shadcn/ui components
 | 
				
			||||||
 | 
					│   ├── lib/           # Utility functions
 | 
				
			||||||
 | 
					│   └── assets/        # Shared styles
 | 
				
			||||||
 | 
					└── package.json
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Development
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Check Makefile for available commands.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Shared UI Components
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The `shared-ui` directory contains all the shadcn/ui components that can be used in both apps.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Using Shared Components
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```vue
 | 
				
			||||||
 | 
					<script setup>
 | 
				
			||||||
 | 
					import { Button } from '@shared-ui/components/ui/button'
 | 
				
			||||||
 | 
					import { Card, CardContent, CardHeader, CardTitle } from '@shared-ui/components/ui/card'
 | 
				
			||||||
 | 
					import { Input } from '@shared-ui/components/ui/input'
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <Card>
 | 
				
			||||||
 | 
					    <CardHeader>
 | 
				
			||||||
 | 
					      <CardTitle>Example Card</CardTitle>
 | 
				
			||||||
 | 
					    </CardHeader>
 | 
				
			||||||
 | 
					    <CardContent>
 | 
				
			||||||
 | 
					      <Input placeholder="Type something..." />
 | 
				
			||||||
 | 
					      <Button>Submit</Button>
 | 
				
			||||||
 | 
					    </CardContent>
 | 
				
			||||||
 | 
					  </Card>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Path Aliases
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- `@shared-ui` - Points to the shared-ui directory
 | 
				
			||||||
 | 
					- `@main` - Points to apps/main/src
 | 
				
			||||||
 | 
					- `@widget` - Points to apps/widget/src
 | 
				
			||||||
 | 
					- `@` - Points to the current app's src directory (context-dependent)
 | 
				
			||||||
@@ -6,8 +6,7 @@
 | 
				
			|||||||
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | 
					  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | 
				
			||||||
  <link rel="preconnect" href="https://fonts.googleapis.com">
 | 
					  <link rel="preconnect" href="https://fonts.googleapis.com">
 | 
				
			||||||
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
 | 
					  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
 | 
				
			||||||
  <link
 | 
					  <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,200..800;1,200..800&display=swap"
 | 
				
			||||||
    href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Plus+Jakarta+Sans:ital,wght@0,200..800;1,200..800&display=swap"
 | 
					 | 
				
			||||||
    rel="stylesheet">
 | 
					    rel="stylesheet">
 | 
				
			||||||
</head>
 | 
					</head>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <div class="flex w-full h-screen">
 | 
					  <div class="flex w-full h-screen text-foreground">
 | 
				
			||||||
    <!-- Icon sidebar always visible -->
 | 
					    <!-- Icon sidebar always visible -->
 | 
				
			||||||
    <SidebarProvider style="--sidebar-width: 3rem" class="w-auto z-50">
 | 
					    <SidebarProvider style="--sidebar-width: 3rem" class="w-auto z-50">
 | 
				
			||||||
      <ShadcnSidebar collapsible="none" class="border-r">
 | 
					      <ShadcnSidebar collapsible="none" class="border-r">
 | 
				
			||||||
@@ -8,38 +8,64 @@
 | 
				
			|||||||
            <SidebarGroupContent>
 | 
					            <SidebarGroupContent>
 | 
				
			||||||
              <SidebarMenu>
 | 
					              <SidebarMenu>
 | 
				
			||||||
                <SidebarMenuItem>
 | 
					                <SidebarMenuItem>
 | 
				
			||||||
 | 
					                  <Tooltip>
 | 
				
			||||||
 | 
					                    <TooltipTrigger as-child>
 | 
				
			||||||
                      <SidebarMenuButton asChild :isActive="route.path.startsWith('/inboxes')">
 | 
					                      <SidebarMenuButton asChild :isActive="route.path.startsWith('/inboxes')">
 | 
				
			||||||
                        <router-link :to="{ name: 'inboxes' }">
 | 
					                        <router-link :to="{ name: 'inboxes' }">
 | 
				
			||||||
                          <Inbox />
 | 
					                          <Inbox />
 | 
				
			||||||
                        </router-link>
 | 
					                        </router-link>
 | 
				
			||||||
                      </SidebarMenuButton>
 | 
					                      </SidebarMenuButton>
 | 
				
			||||||
 | 
					                    </TooltipTrigger>
 | 
				
			||||||
 | 
					                    <TooltipContent side="right">
 | 
				
			||||||
 | 
					                      <p>{{ t('globals.terms.inbox', 2) }}</p>
 | 
				
			||||||
 | 
					                    </TooltipContent>
 | 
				
			||||||
 | 
					                  </Tooltip>
 | 
				
			||||||
                </SidebarMenuItem>
 | 
					                </SidebarMenuItem>
 | 
				
			||||||
                <SidebarMenuItem>
 | 
					                <SidebarMenuItem v-if="userStore.can('contacts:read_all')">
 | 
				
			||||||
                  <SidebarMenuButton
 | 
					                  <Tooltip>
 | 
				
			||||||
                    asChild
 | 
					                    <TooltipTrigger as-child>
 | 
				
			||||||
                    :isActive="route.path.startsWith('/contacts')"
 | 
					                      <SidebarMenuButton asChild :isActive="route.path.startsWith('/contacts')">
 | 
				
			||||||
                    v-if="userStore.can('contacts:read_all')"
 | 
					 | 
				
			||||||
                  >
 | 
					 | 
				
			||||||
                        <router-link :to="{ name: 'contacts' }">
 | 
					                        <router-link :to="{ name: 'contacts' }">
 | 
				
			||||||
                          <BookUser />
 | 
					                          <BookUser />
 | 
				
			||||||
                        </router-link>
 | 
					                        </router-link>
 | 
				
			||||||
                      </SidebarMenuButton>
 | 
					                      </SidebarMenuButton>
 | 
				
			||||||
 | 
					                    </TooltipTrigger>
 | 
				
			||||||
 | 
					                    <TooltipContent side="right">
 | 
				
			||||||
 | 
					                      <p>{{ t('globals.terms.contact', 2) }}</p>
 | 
				
			||||||
 | 
					                    </TooltipContent>
 | 
				
			||||||
 | 
					                  </Tooltip>
 | 
				
			||||||
                </SidebarMenuItem>
 | 
					                </SidebarMenuItem>
 | 
				
			||||||
                <SidebarMenuItem v-if="userStore.hasReportTabPermissions">
 | 
					                <SidebarMenuItem v-if="userStore.hasReportTabPermissions">
 | 
				
			||||||
 | 
					                  <Tooltip>
 | 
				
			||||||
 | 
					                    <TooltipTrigger as-child>
 | 
				
			||||||
                      <SidebarMenuButton asChild :isActive="route.path.startsWith('/reports')">
 | 
					                      <SidebarMenuButton asChild :isActive="route.path.startsWith('/reports')">
 | 
				
			||||||
                        <router-link :to="{ name: 'reports' }">
 | 
					                        <router-link :to="{ name: 'reports' }">
 | 
				
			||||||
                          <FileLineChart />
 | 
					                          <FileLineChart />
 | 
				
			||||||
                        </router-link>
 | 
					                        </router-link>
 | 
				
			||||||
                      </SidebarMenuButton>
 | 
					                      </SidebarMenuButton>
 | 
				
			||||||
 | 
					                    </TooltipTrigger>
 | 
				
			||||||
 | 
					                    <TooltipContent side="right">
 | 
				
			||||||
 | 
					                      <p>{{ t('globals.terms.report', 2) }}</p>
 | 
				
			||||||
 | 
					                    </TooltipContent>
 | 
				
			||||||
 | 
					                  </Tooltip>
 | 
				
			||||||
                </SidebarMenuItem>
 | 
					                </SidebarMenuItem>
 | 
				
			||||||
                <SidebarMenuItem v-if="userStore.hasAdminTabPermissions">
 | 
					                <SidebarMenuItem v-if="userStore.hasAdminTabPermissions">
 | 
				
			||||||
 | 
					                  <Tooltip>
 | 
				
			||||||
 | 
					                    <TooltipTrigger as-child>
 | 
				
			||||||
                      <SidebarMenuButton asChild :isActive="route.path.startsWith('/admin')">
 | 
					                      <SidebarMenuButton asChild :isActive="route.path.startsWith('/admin')">
 | 
				
			||||||
                        <router-link
 | 
					                        <router-link
 | 
				
			||||||
                      :to="{ name: userStore.can('general_settings:manage') ? 'general' : 'admin' }"
 | 
					                          :to="{
 | 
				
			||||||
 | 
					                            name: userStore.can('general_settings:manage') ? 'general' : 'admin'
 | 
				
			||||||
 | 
					                          }"
 | 
				
			||||||
                        >
 | 
					                        >
 | 
				
			||||||
                          <Shield />
 | 
					                          <Shield />
 | 
				
			||||||
                        </router-link>
 | 
					                        </router-link>
 | 
				
			||||||
                      </SidebarMenuButton>
 | 
					                      </SidebarMenuButton>
 | 
				
			||||||
 | 
					                    </TooltipTrigger>
 | 
				
			||||||
 | 
					                    <TooltipContent side="right">
 | 
				
			||||||
 | 
					                      <p>{{ t('globals.terms.admin') }}</p>
 | 
				
			||||||
 | 
					                    </TooltipContent>
 | 
				
			||||||
 | 
					                  </Tooltip>
 | 
				
			||||||
                </SidebarMenuItem>
 | 
					                </SidebarMenuItem>
 | 
				
			||||||
              </SidebarMenu>
 | 
					              </SidebarMenu>
 | 
				
			||||||
            </SidebarGroupContent>
 | 
					            </SidebarGroupContent>
 | 
				
			||||||
@@ -80,32 +106,32 @@
 | 
				
			|||||||
  <Command />
 | 
					  <Command />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <!-- Create conversation dialog -->
 | 
					  <!-- Create conversation dialog -->
 | 
				
			||||||
  <CreateConversation v-model="openCreateConversationDialog" />
 | 
					  <CreateConversation v-model="openCreateConversationDialog" v-if="openCreateConversationDialog" />
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script setup>
 | 
					<script setup>
 | 
				
			||||||
import { onMounted, ref } from 'vue'
 | 
					import { onMounted, ref } from 'vue'
 | 
				
			||||||
import { RouterView } from 'vue-router'
 | 
					import { RouterView } from 'vue-router'
 | 
				
			||||||
import { useUserStore } from '@/stores/user'
 | 
					import { useUserStore } from './stores/user'
 | 
				
			||||||
import { initWS } from '@/websocket.js'
 | 
					import { initWS } from './websocket.js'
 | 
				
			||||||
import { EMITTER_EVENTS } from '@/constants/emitterEvents.js'
 | 
					import { EMITTER_EVENTS } from './constants/emitterEvents.js'
 | 
				
			||||||
import { useEmitter } from '@/composables/useEmitter'
 | 
					import { useEmitter } from './composables/useEmitter'
 | 
				
			||||||
import { handleHTTPError } from '@/utils/http'
 | 
					import { handleHTTPError } from './utils/http'
 | 
				
			||||||
import { useConversationStore } from './stores/conversation'
 | 
					import { useConversationStore } from './stores/conversation'
 | 
				
			||||||
import { useInboxStore } from '@/stores/inbox'
 | 
					import { useInboxStore } from './stores/inbox'
 | 
				
			||||||
import { useUsersStore } from '@/stores/users'
 | 
					import { useUsersStore } from './stores/users'
 | 
				
			||||||
import { useTeamStore } from '@/stores/team'
 | 
					import { useTeamStore } from './stores/team'
 | 
				
			||||||
import { useSlaStore } from '@/stores/sla'
 | 
					import { useSlaStore } from './stores/sla'
 | 
				
			||||||
import { useMacroStore } from '@/stores/macro'
 | 
					import { useMacroStore } from './stores/macro'
 | 
				
			||||||
import { useTagStore } from '@/stores/tag'
 | 
					import { useTagStore } from './stores/tag'
 | 
				
			||||||
import { useCustomAttributeStore } from '@/stores/customAttributes'
 | 
					import { useCustomAttributeStore } from './stores/customAttributes'
 | 
				
			||||||
import { useIdleDetection } from '@/composables/useIdleDetection'
 | 
					import { useIdleDetection } from './composables/useIdleDetection'
 | 
				
			||||||
import PageHeader from './components/layout/PageHeader.vue'
 | 
					import PageHeader from './components/layout/PageHeader.vue'
 | 
				
			||||||
import ViewForm from '@/features/view/ViewForm.vue'
 | 
					import ViewForm from '@/features/view/ViewForm.vue'
 | 
				
			||||||
import AppUpdate from '@/components/update/AppUpdate.vue'
 | 
					import AppUpdate from '@main/components/update/AppUpdate.vue'
 | 
				
			||||||
import api from '@/api'
 | 
					import api from './api'
 | 
				
			||||||
import { toast as sooner } from 'vue-sonner'
 | 
					import { toast as sooner } from 'vue-sonner'
 | 
				
			||||||
import Sidebar from '@/components/sidebar/Sidebar.vue'
 | 
					import Sidebar from '@main/components/sidebar/Sidebar.vue'
 | 
				
			||||||
import Command from '@/features/command/CommandBox.vue'
 | 
					import Command from '@/features/command/CommandBox.vue'
 | 
				
			||||||
import CreateConversation from '@/features/conversation/CreateConversation.vue'
 | 
					import CreateConversation from '@/features/conversation/CreateConversation.vue'
 | 
				
			||||||
import { Inbox, Shield, FileLineChart, BookUser } from 'lucide-vue-next'
 | 
					import { Inbox, Shield, FileLineChart, BookUser } from 'lucide-vue-next'
 | 
				
			||||||
@@ -121,8 +147,9 @@ import {
 | 
				
			|||||||
  SidebarMenuButton,
 | 
					  SidebarMenuButton,
 | 
				
			||||||
  SidebarMenuItem,
 | 
					  SidebarMenuItem,
 | 
				
			||||||
  SidebarProvider
 | 
					  SidebarProvider
 | 
				
			||||||
} from '@/components/ui/sidebar'
 | 
					} from '@shared-ui/components/ui/sidebar'
 | 
				
			||||||
import SidebarNavUser from '@/components/sidebar/SidebarNavUser.vue'
 | 
					import { Tooltip, TooltipContent, TooltipTrigger } from '@shared-ui/components/ui/tooltip'
 | 
				
			||||||
 | 
					import SidebarNavUser from '@main/components/sidebar/SidebarNavUser.vue'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const route = useRoute()
 | 
					const route = useRoute()
 | 
				
			||||||
const emitter = useEmitter()
 | 
					const emitter = useEmitter()
 | 
				
			||||||
@@ -185,7 +212,6 @@ const deleteView = async (view) => {
 | 
				
			|||||||
    })
 | 
					    })
 | 
				
			||||||
  } catch (err) {
 | 
					  } catch (err) {
 | 
				
			||||||
    emitter.emit(EMITTER_EVENTS.SHOW_TOAST, {
 | 
					    emitter.emit(EMITTER_EVENTS.SHOW_TOAST, {
 | 
				
			||||||
      title: 'Error',
 | 
					 | 
				
			||||||
      variant: 'destructive',
 | 
					      variant: 'destructive',
 | 
				
			||||||
      description: handleHTTPError(err).message
 | 
					      description: handleHTTPError(err).message
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
@@ -5,8 +5,8 @@
 | 
				
			|||||||
<script setup>
 | 
					<script setup>
 | 
				
			||||||
import { onMounted } from 'vue'
 | 
					import { onMounted } from 'vue'
 | 
				
			||||||
import { RouterView } from 'vue-router'
 | 
					import { RouterView } from 'vue-router'
 | 
				
			||||||
import { EMITTER_EVENTS } from '@/constants/emitterEvents.js'
 | 
					import { EMITTER_EVENTS } from './constants/emitterEvents.js'
 | 
				
			||||||
import { useEmitter } from '@/composables/useEmitter'
 | 
					import { useEmitter } from './composables/useEmitter'
 | 
				
			||||||
import { toast as sooner } from 'vue-sonner'
 | 
					import { toast as sooner } from 'vue-sonner'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const emitter = useEmitter()
 | 
					const emitter = useEmitter()
 | 
				
			||||||
							
								
								
									
										12
									
								
								frontend/apps/main/src/Root.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								frontend/apps/main/src/Root.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <TooltipProvider :delay-duration="150">
 | 
				
			||||||
 | 
					    <Toaster class="pointer-events-auto" position="top-center" richColors />
 | 
				
			||||||
 | 
					    <RouterView />
 | 
				
			||||||
 | 
					  </TooltipProvider>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script setup>
 | 
				
			||||||
 | 
					import { RouterView } from 'vue-router'
 | 
				
			||||||
 | 
					import { Toaster } from '@shared-ui/components/ui/sonner'
 | 
				
			||||||
 | 
					import { TooltipProvider } from '@shared-ui/components/ui/tooltip'
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
@@ -7,15 +7,15 @@ const http = axios.create({
 | 
				
			|||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getCSRFToken () {
 | 
					function getCSRFToken () {
 | 
				
			||||||
  const name = 'csrf_token=';
 | 
					  const name = 'csrf_token='
 | 
				
			||||||
  const cookies = document.cookie.split(';');
 | 
					  const cookies = document.cookie.split(';')
 | 
				
			||||||
  for (let i = 0; i < cookies.length; i++) {
 | 
					  for (let i = 0; i < cookies.length; i++) {
 | 
				
			||||||
    let c = cookies[i].trim();
 | 
					    let c = cookies[i].trim()
 | 
				
			||||||
    if (c.indexOf(name) === 0) {
 | 
					    if (c.indexOf(name) === 0) {
 | 
				
			||||||
      return c.substring(name.length, c.length);
 | 
					      return c.substring(name.length, c.length)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return '';
 | 
					  return ''
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Request interceptor.
 | 
					// Request interceptor.
 | 
				
			||||||
@@ -27,13 +27,18 @@ http.interceptors.request.use((request) => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // Set content type for POST/PUT requests if the content type is not set.
 | 
					  // Set content type for POST/PUT requests if the content type is not set.
 | 
				
			||||||
  if ((request.method === 'post' || request.method === 'put') && !request.headers['Content-Type']) {
 | 
					  if ((request.method === 'post' || request.method === 'put') && !request.headers['Content-Type']) {
 | 
				
			||||||
    request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
 | 
					    request.headers['Content-Type'] = 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  if (request.headers['Content-Type'] === 'application/x-www-form-urlencoded') {
 | 
				
			||||||
    request.data = qs.stringify(request.data)
 | 
					    request.data = qs.stringify(request.data)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  return request
 | 
					  return request
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getCustomAttributes = (appliesTo) => http.get('/api/v1/custom-attributes', {
 | 
					const getCustomAttributes = (appliesTo) =>
 | 
				
			||||||
 | 
					  http.get('/api/v1/custom-attributes', {
 | 
				
			||||||
    params: { applies_to: appliesTo }
 | 
					    params: { applies_to: appliesTo }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
const createCustomAttribute = (data) =>
 | 
					const createCustomAttribute = (data) =>
 | 
				
			||||||
@@ -42,7 +47,6 @@ const createCustomAttribute = (data) =>
 | 
				
			|||||||
      'Content-Type': 'application/json'
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
const getCustomAttribute = (id) => http.get(`/api/v1/custom-attributes/${id}`)
 | 
					 | 
				
			||||||
const updateCustomAttribute = (id, data) =>
 | 
					const updateCustomAttribute = (id, data) =>
 | 
				
			||||||
  http.put(`/api/v1/custom-attributes/${id}`, data, {
 | 
					  http.put(`/api/v1/custom-attributes/${id}`, data, {
 | 
				
			||||||
    headers: {
 | 
					    headers: {
 | 
				
			||||||
@@ -54,7 +58,8 @@ const searchConversations = (params) => http.get('/api/v1/conversations/search',
 | 
				
			|||||||
const searchMessages = (params) => http.get('/api/v1/messages/search', { params })
 | 
					const searchMessages = (params) => http.get('/api/v1/messages/search', { params })
 | 
				
			||||||
const searchContacts = (params) => http.get('/api/v1/contacts/search', { params })
 | 
					const searchContacts = (params) => http.get('/api/v1/contacts/search', { params })
 | 
				
			||||||
const getEmailNotificationSettings = () => http.get('/api/v1/settings/notifications/email')
 | 
					const getEmailNotificationSettings = () => http.get('/api/v1/settings/notifications/email')
 | 
				
			||||||
const updateEmailNotificationSettings = (data) => http.put('/api/v1/settings/notifications/email', data)
 | 
					const updateEmailNotificationSettings = (data) =>
 | 
				
			||||||
 | 
					  http.put('/api/v1/settings/notifications/email', data)
 | 
				
			||||||
const getPriorities = () => http.get('/api/v1/priorities')
 | 
					const getPriorities = () => http.get('/api/v1/priorities')
 | 
				
			||||||
const getStatuses = () => http.get('/api/v1/statuses')
 | 
					const getStatuses = () => http.get('/api/v1/statuses')
 | 
				
			||||||
const createStatus = (data) => http.post('/api/v1/statuses', data)
 | 
					const createStatus = (data) => http.post('/api/v1/statuses', data)
 | 
				
			||||||
@@ -81,7 +86,8 @@ const updateTemplate = (id, data) =>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const getAllBusinessHours = () => http.get('/api/v1/business-hours')
 | 
					const getAllBusinessHours = () => http.get('/api/v1/business-hours')
 | 
				
			||||||
const getBusinessHours = (id) => http.get(`/api/v1/business-hours/${id}`)
 | 
					const getBusinessHours = (id) => http.get(`/api/v1/business-hours/${id}`)
 | 
				
			||||||
const createBusinessHours = (data) => http.post('/api/v1/business-hours', data, {
 | 
					const createBusinessHours = (data) =>
 | 
				
			||||||
 | 
					  http.post('/api/v1/business-hours', data, {
 | 
				
			||||||
    headers: {
 | 
					    headers: {
 | 
				
			||||||
      'Content-Type': 'application/json'
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -96,12 +102,14 @@ const deleteBusinessHours = (id) => http.delete(`/api/v1/business-hours/${id}`)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const getAllSLAs = () => http.get('/api/v1/sla')
 | 
					const getAllSLAs = () => http.get('/api/v1/sla')
 | 
				
			||||||
const getSLA = (id) => http.get(`/api/v1/sla/${id}`)
 | 
					const getSLA = (id) => http.get(`/api/v1/sla/${id}`)
 | 
				
			||||||
const createSLA = (data) => http.post('/api/v1/sla', data, {
 | 
					const createSLA = (data) =>
 | 
				
			||||||
 | 
					  http.post('/api/v1/sla', data, {
 | 
				
			||||||
    headers: {
 | 
					    headers: {
 | 
				
			||||||
      'Content-Type': 'application/json'
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
const updateSLA = (id, data) => http.put(`/api/v1/sla/${id}`, data, {
 | 
					const updateSLA = (id, data) =>
 | 
				
			||||||
 | 
					  http.put(`/api/v1/sla/${id}`, data, {
 | 
				
			||||||
    headers: {
 | 
					    headers: {
 | 
				
			||||||
      'Content-Type': 'application/json'
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -113,7 +121,6 @@ const createOIDC = (data) =>
 | 
				
			|||||||
      'Content-Type': 'application/json'
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
const testOIDC = (data) => http.post('/api/v1/oidc/test', data)
 | 
					 | 
				
			||||||
const getAllEnabledOIDC = () => http.get('/api/v1/oidc/enabled')
 | 
					const getAllEnabledOIDC = () => http.get('/api/v1/oidc/enabled')
 | 
				
			||||||
const getAllOIDC = () => http.get('/api/v1/oidc')
 | 
					const getAllOIDC = () => http.get('/api/v1/oidc')
 | 
				
			||||||
const getOIDC = (id) => http.get(`/api/v1/oidc/${id}`)
 | 
					const getOIDC = (id) => http.get(`/api/v1/oidc/${id}`)
 | 
				
			||||||
@@ -131,7 +138,11 @@ const updateSettings = (key, data) =>
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
const getSettings = (key) => http.get(`/api/v1/settings/${key}`)
 | 
					const getSettings = (key) => http.get(`/api/v1/settings/${key}`)
 | 
				
			||||||
const login = (data) => http.post(`/api/v1/login`, data)
 | 
					const login = (data) => http.post(`/api/v1/auth/login`, data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
const getAutomationRules = (type) =>
 | 
					const getAutomationRules = (type) =>
 | 
				
			||||||
  http.get(`/api/v1/automations/rules`, {
 | 
					  http.get(`/api/v1/automations/rules`, {
 | 
				
			||||||
    params: { type: type }
 | 
					    params: { type: type }
 | 
				
			||||||
@@ -157,7 +168,12 @@ const updateAutomationRuleWeights = (data) =>
 | 
				
			|||||||
      'Content-Type': 'application/json'
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
const updateAutomationRulesExecutionMode = (data) => http.put(`/api/v1/automations/rules/execution-mode`, data)
 | 
					const updateAutomationRulesExecutionMode = (data) =>
 | 
				
			||||||
 | 
					  http.put(`/api/v1/automations/rules/execution-mode`, data, {
 | 
				
			||||||
 | 
					    headers: {
 | 
				
			||||||
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
const getRoles = () => http.get('/api/v1/roles')
 | 
					const getRoles = () => http.get('/api/v1/roles')
 | 
				
			||||||
const getRole = (id) => http.get(`/api/v1/roles/${id}`)
 | 
					const getRole = (id) => http.get(`/api/v1/roles/${id}`)
 | 
				
			||||||
const createRole = (data) =>
 | 
					const createRole = (data) =>
 | 
				
			||||||
@@ -175,16 +191,29 @@ const updateRole = (id, data) =>
 | 
				
			|||||||
const deleteRole = (id) => http.delete(`/api/v1/roles/${id}`)
 | 
					const deleteRole = (id) => http.delete(`/api/v1/roles/${id}`)
 | 
				
			||||||
const getContacts = (params) => http.get('/api/v1/contacts', { params })
 | 
					const getContacts = (params) => http.get('/api/v1/contacts', { params })
 | 
				
			||||||
const getContact = (id) => http.get(`/api/v1/contacts/${id}`)
 | 
					const getContact = (id) => http.get(`/api/v1/contacts/${id}`)
 | 
				
			||||||
const updateContact = (id, data) => http.put(`/api/v1/contacts/${id}`, data, {
 | 
					const updateContact = (id, data) =>
 | 
				
			||||||
 | 
					  http.put(`/api/v1/contacts/${id}`, data, {
 | 
				
			||||||
    headers: {
 | 
					    headers: {
 | 
				
			||||||
      'Content-Type': 'multipart/form-data'
 | 
					      'Content-Type': 'multipart/form-data'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
const blockContact = (id, data) => http.put(`/api/v1/contacts/${id}/block`, data)
 | 
					const blockContact = (id, data) => http.put(`/api/v1/contacts/${id}/block`, data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
const getTeam = (id) => http.get(`/api/v1/teams/${id}`)
 | 
					const getTeam = (id) => http.get(`/api/v1/teams/${id}`)
 | 
				
			||||||
const getTeams = () => http.get('/api/v1/teams')
 | 
					const getTeams = () => http.get('/api/v1/teams')
 | 
				
			||||||
const updateTeam = (id, data) => http.put(`/api/v1/teams/${id}`, data)
 | 
					const updateTeam = (id, data) => http.put(`/api/v1/teams/${id}`, data, {
 | 
				
			||||||
const createTeam = (data) => http.post('/api/v1/teams', data)
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					const createTeam = (data) => http.post('/api/v1/teams', data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
const getTeamsCompact = () => http.get('/api/v1/teams/compact')
 | 
					const getTeamsCompact = () => http.get('/api/v1/teams/compact')
 | 
				
			||||||
const deleteTeam = (id) => http.delete(`/api/v1/teams/${id}`)
 | 
					const deleteTeam = (id) => http.delete(`/api/v1/teams/${id}`)
 | 
				
			||||||
const updateUser = (id, data) =>
 | 
					const updateUser = (id, data) =>
 | 
				
			||||||
@@ -205,9 +234,21 @@ const getUser = (id) => http.get(`/api/v1/agents/${id}`)
 | 
				
			|||||||
const deleteUserAvatar = () => http.delete('/api/v1/agents/me/avatar')
 | 
					const deleteUserAvatar = () => http.delete('/api/v1/agents/me/avatar')
 | 
				
			||||||
const getCurrentUser = () => http.get('/api/v1/agents/me')
 | 
					const getCurrentUser = () => http.get('/api/v1/agents/me')
 | 
				
			||||||
const getCurrentUserTeams = () => http.get('/api/v1/agents/me/teams')
 | 
					const getCurrentUserTeams = () => http.get('/api/v1/agents/me/teams')
 | 
				
			||||||
const updateCurrentUserAvailability = (data) => http.put('/api/v1/agents/me/availability', data)
 | 
					const updateCurrentUserAvailability = (data) => http.put('/api/v1/agents/me/availability', data, {
 | 
				
			||||||
const resetPassword = (data) => http.post('/api/v1/agents/reset-password', data)
 | 
					  headers: {
 | 
				
			||||||
const setPassword = (data) => http.post('/api/v1/agents/set-password', data)
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					const resetPassword = (data) => http.post('/api/v1/agents/reset-password', data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					const setPassword = (data) => http.post('/api/v1/agents/set-password', data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
const deleteUser = (id) => http.delete(`/api/v1/agents/${id}`)
 | 
					const deleteUser = (id) => http.delete(`/api/v1/agents/${id}`)
 | 
				
			||||||
const createUser = (data) =>
 | 
					const createUser = (data) =>
 | 
				
			||||||
  http.post('/api/v1/agents', data, {
 | 
					  http.post('/api/v1/agents', data, {
 | 
				
			||||||
@@ -216,28 +257,56 @@ const createUser = (data) =>
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
const getTags = () => http.get('/api/v1/tags')
 | 
					const getTags = () => http.get('/api/v1/tags')
 | 
				
			||||||
const upsertTags = (uuid, data) => http.post(`/api/v1/conversations/${uuid}/tags`, data)
 | 
					const upsertTags = (uuid, data) => http.post(`/api/v1/conversations/${uuid}/tags`, data, {
 | 
				
			||||||
const updateAssignee = (uuid, assignee_type, data) => http.put(`/api/v1/conversations/${uuid}/assignee/${assignee_type}`, data)
 | 
					 | 
				
			||||||
const removeAssignee = (uuid, assignee_type) => http.put(`/api/v1/conversations/${uuid}/assignee/${assignee_type}/remove`)
 | 
					 | 
				
			||||||
const updateContactCustomAttribute = (uuid, data) => http.put(`/api/v1/conversations/${uuid}/contacts/custom-attributes`, data,
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  headers: {
 | 
					  headers: {
 | 
				
			||||||
    'Content-Type': 'application/json'
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
const updateConversationCustomAttribute = (uuid, data) => http.put(`/api/v1/conversations/${uuid}/custom-attributes`, data,
 | 
					const updateAssignee = (uuid, assignee_type, data) =>
 | 
				
			||||||
  {
 | 
					  http.put(`/api/v1/conversations/${uuid}/assignee/${assignee_type}`, data, {
 | 
				
			||||||
 | 
					    headers: {
 | 
				
			||||||
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					const removeAssignee = (uuid, assignee_type) =>
 | 
				
			||||||
 | 
					  http.put(`/api/v1/conversations/${uuid}/assignee/${assignee_type}/remove`)
 | 
				
			||||||
 | 
					const updateContactCustomAttribute = (uuid, data) =>
 | 
				
			||||||
 | 
					  http.put(`/api/v1/conversations/${uuid}/contacts/custom-attributes`, data, {
 | 
				
			||||||
 | 
					    headers: {
 | 
				
			||||||
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					const updateConversationCustomAttribute = (uuid, data) =>
 | 
				
			||||||
 | 
					  http.put(`/api/v1/conversations/${uuid}/custom-attributes`, data, {
 | 
				
			||||||
 | 
					    headers: {
 | 
				
			||||||
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					const createConversation = (data) =>
 | 
				
			||||||
 | 
					  http.post('/api/v1/conversations', data, {
 | 
				
			||||||
 | 
					    headers: {
 | 
				
			||||||
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					const updateConversationStatus = (uuid, data) =>
 | 
				
			||||||
 | 
					  http.put(`/api/v1/conversations/${uuid}/status`, data, {
 | 
				
			||||||
 | 
					    headers: {
 | 
				
			||||||
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					const updateConversationPriority = (uuid, data) =>
 | 
				
			||||||
 | 
					  http.put(`/api/v1/conversations/${uuid}/priority`, data, {
 | 
				
			||||||
    headers: {
 | 
					    headers: {
 | 
				
			||||||
      'Content-Type': 'application/json'
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
const createConversation = (data) => http.post('/api/v1/conversations', data)
 | 
					 | 
				
			||||||
const updateConversationStatus = (uuid, data) => http.put(`/api/v1/conversations/${uuid}/status`, data)
 | 
					 | 
				
			||||||
const updateConversationPriority = (uuid, data) => http.put(`/api/v1/conversations/${uuid}/priority`, data)
 | 
					 | 
				
			||||||
const updateAssigneeLastSeen = (uuid) => http.put(`/api/v1/conversations/${uuid}/last-seen`)
 | 
					const updateAssigneeLastSeen = (uuid) => http.put(`/api/v1/conversations/${uuid}/last-seen`)
 | 
				
			||||||
const getConversationMessage = (cuuid, uuid) => http.get(`/api/v1/conversations/${cuuid}/messages/${uuid}`)
 | 
					const getConversationMessage = (cuuid, uuid) =>
 | 
				
			||||||
const retryMessage = (cuuid, uuid) => http.put(`/api/v1/conversations/${cuuid}/messages/${uuid}/retry`)
 | 
					  http.get(`/api/v1/conversations/${cuuid}/messages/${uuid}`)
 | 
				
			||||||
const getConversationMessages = (uuid, params) => http.get(`/api/v1/conversations/${uuid}/messages`, { params })
 | 
					const retryMessage = (cuuid, uuid) =>
 | 
				
			||||||
 | 
					  http.put(`/api/v1/conversations/${cuuid}/messages/${uuid}/retry`)
 | 
				
			||||||
 | 
					const getConversationMessages = (uuid, params) =>
 | 
				
			||||||
 | 
					  http.get(`/api/v1/conversations/${uuid}/messages`, { params })
 | 
				
			||||||
const sendMessage = (uuid, data) =>
 | 
					const sendMessage = (uuid, data) =>
 | 
				
			||||||
  http.post(`/api/v1/conversations/${uuid}/messages`, data, {
 | 
					  http.post(`/api/v1/conversations/${uuid}/messages`, data, {
 | 
				
			||||||
    headers: {
 | 
					    headers: {
 | 
				
			||||||
@@ -248,18 +317,21 @@ const getConversation = (uuid) => http.get(`/api/v1/conversations/${uuid}`)
 | 
				
			|||||||
const getConversationParticipants = (uuid) => http.get(`/api/v1/conversations/${uuid}/participants`)
 | 
					const getConversationParticipants = (uuid) => http.get(`/api/v1/conversations/${uuid}/participants`)
 | 
				
			||||||
const getAllMacros = () => http.get('/api/v1/macros')
 | 
					const getAllMacros = () => http.get('/api/v1/macros')
 | 
				
			||||||
const getMacro = (id) => http.get(`/api/v1/macros/${id}`)
 | 
					const getMacro = (id) => http.get(`/api/v1/macros/${id}`)
 | 
				
			||||||
const createMacro = (data) => http.post('/api/v1/macros', data, {
 | 
					const createMacro = (data) =>
 | 
				
			||||||
 | 
					  http.post('/api/v1/macros', data, {
 | 
				
			||||||
    headers: {
 | 
					    headers: {
 | 
				
			||||||
      'Content-Type': 'application/json'
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
const updateMacro = (id, data) => http.put(`/api/v1/macros/${id}`, data, {
 | 
					const updateMacro = (id, data) =>
 | 
				
			||||||
 | 
					  http.put(`/api/v1/macros/${id}`, data, {
 | 
				
			||||||
    headers: {
 | 
					    headers: {
 | 
				
			||||||
      'Content-Type': 'application/json'
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
const deleteMacro = (id) => http.delete(`/api/v1/macros/${id}`)
 | 
					const deleteMacro = (id) => http.delete(`/api/v1/macros/${id}`)
 | 
				
			||||||
const applyMacro = (uuid, id, data) => http.post(`/api/v1/conversations/${uuid}/macros/${id}/apply`, data, {
 | 
					const applyMacro = (uuid, id, data) =>
 | 
				
			||||||
 | 
					  http.post(`/api/v1/conversations/${uuid}/macros/${id}/apply`, data, {
 | 
				
			||||||
    headers: {
 | 
					    headers: {
 | 
				
			||||||
      'Content-Type': 'application/json'
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -267,9 +339,11 @@ const applyMacro = (uuid, id, data) => http.post(`/api/v1/conversations/${uuid}/
 | 
				
			|||||||
const getTeamUnassignedConversations = (teamID, params) =>
 | 
					const getTeamUnassignedConversations = (teamID, params) =>
 | 
				
			||||||
  http.get(`/api/v1/teams/${teamID}/conversations/unassigned`, { params })
 | 
					  http.get(`/api/v1/teams/${teamID}/conversations/unassigned`, { params })
 | 
				
			||||||
const getAssignedConversations = (params) => http.get('/api/v1/conversations/assigned', { params })
 | 
					const getAssignedConversations = (params) => http.get('/api/v1/conversations/assigned', { params })
 | 
				
			||||||
const getUnassignedConversations = (params) => http.get('/api/v1/conversations/unassigned', { params })
 | 
					const getUnassignedConversations = (params) =>
 | 
				
			||||||
 | 
					  http.get('/api/v1/conversations/unassigned', { params })
 | 
				
			||||||
const getAllConversations = (params) => http.get('/api/v1/conversations/all', { params })
 | 
					const getAllConversations = (params) => http.get('/api/v1/conversations/all', { params })
 | 
				
			||||||
const getViewConversations = (id, params) => http.get(`/api/v1/views/${id}/conversations`, { params })
 | 
					const getViewConversations = (id, params) =>
 | 
				
			||||||
 | 
					  http.get(`/api/v1/views/${id}/conversations`, { params })
 | 
				
			||||||
const uploadMedia = (data) =>
 | 
					const uploadMedia = (data) =>
 | 
				
			||||||
  http.post('/api/v1/media', data, {
 | 
					  http.post('/api/v1/media', data, {
 | 
				
			||||||
    headers: {
 | 
					    headers: {
 | 
				
			||||||
@@ -277,7 +351,8 @@ const uploadMedia = (data) =>
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
const getOverviewCounts = () => http.get('/api/v1/reports/overview/counts')
 | 
					const getOverviewCounts = () => http.get('/api/v1/reports/overview/counts')
 | 
				
			||||||
const getOverviewCharts = () => http.get('/api/v1/reports/overview/charts')
 | 
					const getOverviewCharts = (params) => http.get('/api/v1/reports/overview/charts', { params })
 | 
				
			||||||
 | 
					const getOverviewSLA = (params) => http.get('/api/v1/reports/overview/sla', { params })
 | 
				
			||||||
const getLanguage = (lang) => http.get(`/api/v1/lang/${lang}`)
 | 
					const getLanguage = (lang) => http.get(`/api/v1/lang/${lang}`)
 | 
				
			||||||
const createInbox = (data) =>
 | 
					const createInbox = (data) =>
 | 
				
			||||||
  http.post('/api/v1/inboxes', data, {
 | 
					  http.post('/api/v1/inboxes', data, {
 | 
				
			||||||
@@ -310,12 +385,140 @@ const updateView = (id, data) =>
 | 
				
			|||||||
  })
 | 
					  })
 | 
				
			||||||
const deleteView = (id) => http.delete(`/api/v1/views/me/${id}`)
 | 
					const deleteView = (id) => http.delete(`/api/v1/views/me/${id}`)
 | 
				
			||||||
const getAiPrompts = () => http.get('/api/v1/ai/prompts')
 | 
					const getAiPrompts = () => http.get('/api/v1/ai/prompts')
 | 
				
			||||||
const aiCompletion = (data) => http.post('/api/v1/ai/completion', data)
 | 
					const aiCompletion = (data) => http.post('/api/v1/ai/completion', data, {
 | 
				
			||||||
const updateAIProvider = (data) => http.put('/api/v1/ai/provider', data)
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					const updateAIProvider = (data) => http.put('/api/v1/ai/provider', data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
const getContactNotes = (id) => http.get(`/api/v1/contacts/${id}/notes`)
 | 
					const getContactNotes = (id) => http.get(`/api/v1/contacts/${id}/notes`)
 | 
				
			||||||
const createContactNote = (id, data) => http.post(`/api/v1/contacts/${id}/notes`, data)
 | 
					const createContactNote = (id, data) => http.post(`/api/v1/contacts/${id}/notes`, data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
const deleteContactNote = (id, noteId) => http.delete(`/api/v1/contacts/${id}/notes/${noteId}`)
 | 
					const deleteContactNote = (id, noteId) => http.delete(`/api/v1/contacts/${id}/notes/${noteId}`)
 | 
				
			||||||
const getActivityLogs = (params) => http.get('/api/v1/activity-logs', { params })
 | 
					const getActivityLogs = (params) => http.get('/api/v1/activity-logs', { params })
 | 
				
			||||||
 | 
					const getWebhooks = () => http.get('/api/v1/webhooks')
 | 
				
			||||||
 | 
					const getWebhook = (id) => http.get(`/api/v1/webhooks/${id}`)
 | 
				
			||||||
 | 
					const createWebhook = (data) =>
 | 
				
			||||||
 | 
					  http.post('/api/v1/webhooks', data, {
 | 
				
			||||||
 | 
					    headers: {
 | 
				
			||||||
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					const updateWebhook = (id, data) =>
 | 
				
			||||||
 | 
					  http.put(`/api/v1/webhooks/${id}`, data, {
 | 
				
			||||||
 | 
					    headers: {
 | 
				
			||||||
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					const deleteWebhook = (id) => http.delete(`/api/v1/webhooks/${id}`)
 | 
				
			||||||
 | 
					const toggleWebhook = (id) => http.put(`/api/v1/webhooks/${id}/toggle`)
 | 
				
			||||||
 | 
					const testWebhook = (id) => http.post(`/api/v1/webhooks/${id}/test`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const generateAPIKey = (id) => 
 | 
				
			||||||
 | 
					  http.post(`/api/v1/agents/${id}/api-key`, {}, {
 | 
				
			||||||
 | 
					    headers: {
 | 
				
			||||||
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const revokeAPIKey = (id) => http.delete(`/api/v1/agents/${id}/api-key`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Help center.
 | 
				
			||||||
 | 
					const getHelpCenters = () => http.get('/api/v1/help-centers')
 | 
				
			||||||
 | 
					const getHelpCenter = (id) => http.get(`/api/v1/help-centers/${id}`)
 | 
				
			||||||
 | 
					const createHelpCenter = (data) => http.post('/api/v1/help-centers', data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					const updateHelpCenter = (id, data) => http.put(`/api/v1/help-centers/${id}`, data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					const deleteHelpCenter = (id) => http.delete(`/api/v1/help-centers/${id}`)
 | 
				
			||||||
 | 
					const getHelpCenterTree = (id, params) => http.get(`/api/v1/help-centers/${id}/tree`, { params })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const getCollections = (helpCenterId, params) => http.get(`/api/v1/help-centers/${helpCenterId}/collections`, { params })
 | 
				
			||||||
 | 
					const getCollection = (id) => http.get(`/api/v1/help-centers/*/collections/${id}`)
 | 
				
			||||||
 | 
					const createCollection = (helpCenterId, data) => http.post(`/api/v1/help-centers/${helpCenterId}/collections`, data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					const updateCollection = (helpCenterId, id, data) => http.put(`/api/v1/help-centers/${helpCenterId}/collections/${id}`, data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					const deleteCollection = (helpCenterId, id) => http.delete(`/api/v1/help-centers/${helpCenterId}/collections/${id}`)
 | 
				
			||||||
 | 
					const toggleCollection = (id) => http.put(`/api/v1/collections/${id}/toggle`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const getArticles = (collectionId, params) => http.get(`/api/v1/collections/${collectionId}/articles`, { params })
 | 
				
			||||||
 | 
					const getArticle = (id) => http.get(`/api/v1/collections/*/articles/${id}`)
 | 
				
			||||||
 | 
					const createArticle = (collectionId, data) => http.post(`/api/v1/collections/${collectionId}/articles`, data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					const updateArticle = (collectionId, id, data) => http.put(`/api/v1/collections/${collectionId}/articles/${id}`, data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					const updateArticleByID = (id, data) => http.put(`/api/v1/articles/${id}`, data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					const deleteArticle = (collectionId, id) => http.delete(`/api/v1/collections/${collectionId}/articles/${id}`)
 | 
				
			||||||
 | 
					const updateArticleStatus = (id, data) => http.put(`/api/v1/articles/${id}/status`, data, {
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// AI Assistants
 | 
				
			||||||
 | 
					const getAIAssistants = () => http.get('/api/v1/ai-assistants')
 | 
				
			||||||
 | 
					const getAIAssistant = (id) => http.get(`/api/v1/ai-assistants/${id}`)
 | 
				
			||||||
 | 
					const createAIAssistant = (data) =>
 | 
				
			||||||
 | 
					  http.post('/api/v1/ai-assistants', data, {
 | 
				
			||||||
 | 
					    headers: {
 | 
				
			||||||
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					const updateAIAssistant = (id, data) =>
 | 
				
			||||||
 | 
					  http.put(`/api/v1/ai-assistants/${id}`, data, {
 | 
				
			||||||
 | 
					    headers: {
 | 
				
			||||||
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					const deleteAIAssistant = (id) => http.delete(`/api/v1/ai-assistants/${id}`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// AI Snippets
 | 
				
			||||||
 | 
					const getAISnippets = () => http.get('/api/v1/ai-snippets')
 | 
				
			||||||
 | 
					const getAISnippet = (id) => http.get(`/api/v1/ai-snippets/${id}`)
 | 
				
			||||||
 | 
					const createAISnippet = (data) =>
 | 
				
			||||||
 | 
					  http.post('/api/v1/ai-snippets', data, {
 | 
				
			||||||
 | 
					    headers: {
 | 
				
			||||||
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					const updateAISnippet = (id, data) =>
 | 
				
			||||||
 | 
					  http.put(`/api/v1/ai-snippets/${id}`, data, {
 | 
				
			||||||
 | 
					    headers: {
 | 
				
			||||||
 | 
					      'Content-Type': 'application/json'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					const deleteAISnippet = (id) => http.delete(`/api/v1/ai-snippets/${id}`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
  login,
 | 
					  login,
 | 
				
			||||||
@@ -356,6 +559,7 @@ export default {
 | 
				
			|||||||
  getViewConversations,
 | 
					  getViewConversations,
 | 
				
			||||||
  getOverviewCharts,
 | 
					  getOverviewCharts,
 | 
				
			||||||
  getOverviewCounts,
 | 
					  getOverviewCounts,
 | 
				
			||||||
 | 
					  getOverviewSLA,
 | 
				
			||||||
  getConversationParticipants,
 | 
					  getConversationParticipants,
 | 
				
			||||||
  getConversationMessage,
 | 
					  getConversationMessage,
 | 
				
			||||||
  getConversationMessages,
 | 
					  getConversationMessages,
 | 
				
			||||||
@@ -389,6 +593,18 @@ export default {
 | 
				
			|||||||
  sendMessage,
 | 
					  sendMessage,
 | 
				
			||||||
  retryMessage,
 | 
					  retryMessage,
 | 
				
			||||||
  createUser,
 | 
					  createUser,
 | 
				
			||||||
 | 
					  // AI Assistants
 | 
				
			||||||
 | 
					  getAIAssistants,
 | 
				
			||||||
 | 
					  getAIAssistant,
 | 
				
			||||||
 | 
					  createAIAssistant,
 | 
				
			||||||
 | 
					  updateAIAssistant,
 | 
				
			||||||
 | 
					  deleteAIAssistant,
 | 
				
			||||||
 | 
					  // AI Snippets
 | 
				
			||||||
 | 
					  getAISnippets,
 | 
				
			||||||
 | 
					  getAISnippet,
 | 
				
			||||||
 | 
					  createAISnippet,
 | 
				
			||||||
 | 
					  updateAISnippet,
 | 
				
			||||||
 | 
					  deleteAISnippet,
 | 
				
			||||||
  createInbox,
 | 
					  createInbox,
 | 
				
			||||||
  updateInbox,
 | 
					  updateInbox,
 | 
				
			||||||
  deleteInbox,
 | 
					  deleteInbox,
 | 
				
			||||||
@@ -402,7 +618,6 @@ export default {
 | 
				
			|||||||
  getAllEnabledOIDC,
 | 
					  getAllEnabledOIDC,
 | 
				
			||||||
  getOIDC,
 | 
					  getOIDC,
 | 
				
			||||||
  updateOIDC,
 | 
					  updateOIDC,
 | 
				
			||||||
  testOIDC,
 | 
					 | 
				
			||||||
  deleteOIDC,
 | 
					  deleteOIDC,
 | 
				
			||||||
  getTemplate,
 | 
					  getTemplate,
 | 
				
			||||||
  getTemplates,
 | 
					  getTemplates,
 | 
				
			||||||
@@ -440,9 +655,37 @@ export default {
 | 
				
			|||||||
  createCustomAttribute,
 | 
					  createCustomAttribute,
 | 
				
			||||||
  updateCustomAttribute,
 | 
					  updateCustomAttribute,
 | 
				
			||||||
  deleteCustomAttribute,
 | 
					  deleteCustomAttribute,
 | 
				
			||||||
  getCustomAttribute,
 | 
					 | 
				
			||||||
  getContactNotes,
 | 
					  getContactNotes,
 | 
				
			||||||
  createContactNote,
 | 
					  createContactNote,
 | 
				
			||||||
  deleteContactNote,
 | 
					  deleteContactNote,
 | 
				
			||||||
  getActivityLogs
 | 
					  getActivityLogs,
 | 
				
			||||||
 | 
					  getWebhooks,
 | 
				
			||||||
 | 
					  getWebhook,
 | 
				
			||||||
 | 
					  createWebhook,
 | 
				
			||||||
 | 
					  updateWebhook,
 | 
				
			||||||
 | 
					  deleteWebhook,
 | 
				
			||||||
 | 
					  toggleWebhook,
 | 
				
			||||||
 | 
					  testWebhook,
 | 
				
			||||||
 | 
					  generateAPIKey,
 | 
				
			||||||
 | 
					  revokeAPIKey,
 | 
				
			||||||
 | 
					  // Help Center
 | 
				
			||||||
 | 
					  getHelpCenters,
 | 
				
			||||||
 | 
					  getHelpCenter,
 | 
				
			||||||
 | 
					  createHelpCenter,
 | 
				
			||||||
 | 
					  updateHelpCenter,
 | 
				
			||||||
 | 
					  deleteHelpCenter,
 | 
				
			||||||
 | 
					  getHelpCenterTree,
 | 
				
			||||||
 | 
					  getCollections,
 | 
				
			||||||
 | 
					  getCollection,
 | 
				
			||||||
 | 
					  createCollection,
 | 
				
			||||||
 | 
					  updateCollection,
 | 
				
			||||||
 | 
					  deleteCollection,
 | 
				
			||||||
 | 
					  toggleCollection,
 | 
				
			||||||
 | 
					  getArticles,
 | 
				
			||||||
 | 
					  getArticle,
 | 
				
			||||||
 | 
					  createArticle,
 | 
				
			||||||
 | 
					  updateArticle,
 | 
				
			||||||
 | 
					  updateArticleByID,
 | 
				
			||||||
 | 
					  deleteArticle,
 | 
				
			||||||
 | 
					  updateArticleStatus,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										24
									
								
								frontend/apps/main/src/components/button/CloseButton.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								frontend/apps/main/src/components/button/CloseButton.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <Button
 | 
				
			||||||
 | 
					    variant="ghost"
 | 
				
			||||||
 | 
					    @click.prevent="onClose"
 | 
				
			||||||
 | 
					    size="xs"
 | 
				
			||||||
 | 
					    class="text-gray-400 dark:text-gray-500 hover:text-gray-600 hover:bg-gray-100 dark:hover:bg-gray-800 w-6 h-6 p-0"
 | 
				
			||||||
 | 
					  >
 | 
				
			||||||
 | 
					    <slot>
 | 
				
			||||||
 | 
					      <X size="16" />
 | 
				
			||||||
 | 
					    </slot>
 | 
				
			||||||
 | 
					  </Button>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script setup>
 | 
				
			||||||
 | 
					import { Button } from '@shared-ui/components/ui/button'
 | 
				
			||||||
 | 
					import { X } from 'lucide-vue-next'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					defineProps({
 | 
				
			||||||
 | 
					  onClose: {
 | 
				
			||||||
 | 
					    type: Function,
 | 
				
			||||||
 | 
					    required: true
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
@@ -0,0 +1,61 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <ComboBox
 | 
				
			||||||
 | 
					    :model-value="normalizedValue"
 | 
				
			||||||
 | 
					    @update:model-value="$emit('update:modelValue', $event)"
 | 
				
			||||||
 | 
					    :items="items"
 | 
				
			||||||
 | 
					    :placeholder="placeholder"
 | 
				
			||||||
 | 
					  >
 | 
				
			||||||
 | 
					    <!-- Items -->
 | 
				
			||||||
 | 
					    <template #item="{ item }">
 | 
				
			||||||
 | 
					      <div class="flex items-center gap-2">
 | 
				
			||||||
 | 
					        <!--USER -->
 | 
				
			||||||
 | 
					        <Avatar v-if="type === 'user'" class="w-7 h-7">
 | 
				
			||||||
 | 
					          <AvatarImage :src="item.avatar_url || ''" :alt="item.label.slice(0, 2)" />
 | 
				
			||||||
 | 
					          <AvatarFallback>{{ item.label.slice(0, 2).toUpperCase() }}</AvatarFallback>
 | 
				
			||||||
 | 
					        </Avatar>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <!-- Others -->
 | 
				
			||||||
 | 
					        <span v-else-if="item.emoji">{{ item.emoji }}</span>
 | 
				
			||||||
 | 
					        <span>{{ item.label }}</span>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- Selected -->
 | 
				
			||||||
 | 
					    <template #selected="{ selected }">
 | 
				
			||||||
 | 
					      <div class="flex items-center gap-2">
 | 
				
			||||||
 | 
					        <div v-if="selected" class="flex items-center gap-2">
 | 
				
			||||||
 | 
					          <!--USER -->
 | 
				
			||||||
 | 
					          <Avatar v-if="type === 'user'" class="w-7 h-7">
 | 
				
			||||||
 | 
					            <AvatarImage :src="selected.avatar_url || ''" :alt="selected.label.slice(0, 2)" />
 | 
				
			||||||
 | 
					            <AvatarFallback>{{ selected.label.slice(0, 2).toUpperCase() }}</AvatarFallback>
 | 
				
			||||||
 | 
					          </Avatar>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          <!-- Others -->
 | 
				
			||||||
 | 
					          <span v-else-if="selected.emoji">{{ selected.emoji }}</span>
 | 
				
			||||||
 | 
					          <span>{{ selected.label }}</span>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <span v-else>{{ placeholder }}</span>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </template>
 | 
				
			||||||
 | 
					  </ComboBox>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script setup>
 | 
				
			||||||
 | 
					import { computed } from 'vue'
 | 
				
			||||||
 | 
					import { Avatar, AvatarImage, AvatarFallback } from '@shared-ui/components/ui/avatar'
 | 
				
			||||||
 | 
					import ComboBox from '@shared-ui/components/ui/combobox/ComboBox.vue'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const props = defineProps({
 | 
				
			||||||
 | 
					  modelValue: [String, Number, Object],
 | 
				
			||||||
 | 
					  placeholder: String,
 | 
				
			||||||
 | 
					  items: Array,
 | 
				
			||||||
 | 
					  type: {
 | 
				
			||||||
 | 
					    type: String
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Convert to str.
 | 
				
			||||||
 | 
					const normalizedValue = computed(() => String(props.modelValue || ''))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					defineEmits(['update:modelValue'])
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <div class="w-full">
 | 
					  <div class="w-full">
 | 
				
			||||||
    <div class="rounded-md border shadow">
 | 
					    <div class="rounded border shadow">
 | 
				
			||||||
      <Table>
 | 
					      <Table>
 | 
				
			||||||
        <TableHeader>
 | 
					        <TableHeader>
 | 
				
			||||||
          <TableRow v-for="headerGroup in table.getHeaderGroups()" :key="headerGroup.id">
 | 
					          <TableRow v-for="headerGroup in table.getHeaderGroups()" :key="headerGroup.id">
 | 
				
			||||||
@@ -51,7 +51,7 @@ import {
 | 
				
			|||||||
  TableHead,
 | 
					  TableHead,
 | 
				
			||||||
  TableHeader,
 | 
					  TableHeader,
 | 
				
			||||||
  TableRow
 | 
					  TableRow
 | 
				
			||||||
} from '@/components/ui/table'
 | 
					} from '@shared-ui/components/ui/table'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const { t } = useI18n()
 | 
					const { t } = useI18n()
 | 
				
			||||||
const props = defineProps({
 | 
					const props = defineProps({
 | 
				
			||||||
							
								
								
									
										65
									
								
								frontend/apps/main/src/components/editor/CodeEditor.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								frontend/apps/main/src/components/editor/CodeEditor.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,65 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					    <div ref="codeEditor" @click="editorView?.focus()" class="w-full h-[28rem] border rounded-md" />
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script setup>
 | 
				
			||||||
 | 
					import { ref, onMounted, watch, nextTick, useTemplateRef } from 'vue'
 | 
				
			||||||
 | 
					import { EditorView, basicSetup } from 'codemirror'
 | 
				
			||||||
 | 
					import { html } from '@codemirror/lang-html'
 | 
				
			||||||
 | 
					import { oneDark } from '@codemirror/theme-one-dark'
 | 
				
			||||||
 | 
					import { useColorMode } from '@vueuse/core'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const props = defineProps({
 | 
				
			||||||
 | 
					    modelValue: { type: String, default: '' },
 | 
				
			||||||
 | 
					    language: { type: String, default: 'html' },
 | 
				
			||||||
 | 
					    disabled: Boolean
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const emit = defineEmits(['update:modelValue'])
 | 
				
			||||||
 | 
					const data = ref('')
 | 
				
			||||||
 | 
					let editorView = null 
 | 
				
			||||||
 | 
					const codeEditor = useTemplateRef('codeEditor')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const initCodeEditor = (body) => {
 | 
				
			||||||
 | 
					    const isDark = useColorMode().value === 'dark'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    editorView = new EditorView({
 | 
				
			||||||
 | 
					        doc: body,
 | 
				
			||||||
 | 
					        extensions: [
 | 
				
			||||||
 | 
					            basicSetup,
 | 
				
			||||||
 | 
					            html(),
 | 
				
			||||||
 | 
					            ...(isDark ? [oneDark] : []),
 | 
				
			||||||
 | 
					            EditorView.editable.of(!props.disabled),
 | 
				
			||||||
 | 
					            EditorView.theme({
 | 
				
			||||||
 | 
					                '&': { height: '100%' },
 | 
				
			||||||
 | 
					                '.cm-editor': { height: '100%' },
 | 
				
			||||||
 | 
					                '.cm-scroller': { overflow: 'auto' }
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
 | 
					            EditorView.updateListener.of((update) => {
 | 
				
			||||||
 | 
					                if (!update.docChanged) return
 | 
				
			||||||
 | 
					                const v = update.state.doc.toString()
 | 
				
			||||||
 | 
					                emit('update:modelValue', v)
 | 
				
			||||||
 | 
					                data.value = v
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        parent: codeEditor.value
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    nextTick(() => {
 | 
				
			||||||
 | 
					        editorView?.focus()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					onMounted(() => {
 | 
				
			||||||
 | 
					    initCodeEditor(props.modelValue || '')
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					watch(() => props.modelValue, (newVal) => {
 | 
				
			||||||
 | 
					    if (newVal !== data.value) {
 | 
				
			||||||
 | 
					        editorView?.dispatch({
 | 
				
			||||||
 | 
					            changes: { from: 0, to: editorView.state.doc.length, insert: newVal }
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
							
								
								
									
										438
									
								
								frontend/apps/main/src/components/editor/TextEditor.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										438
									
								
								frontend/apps/main/src/components/editor/TextEditor.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,438 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <div class="editor-wrapper h-full overflow-y-auto">
 | 
				
			||||||
 | 
					    <BubbleMenu
 | 
				
			||||||
 | 
					      :editor="editor"
 | 
				
			||||||
 | 
					      :tippy-options="{ duration: 100 }"
 | 
				
			||||||
 | 
					      v-if="editor"
 | 
				
			||||||
 | 
					      class="bg-background p-2 box will-change-transform max-w-fit"
 | 
				
			||||||
 | 
					    >
 | 
				
			||||||
 | 
					      <div class="flex gap-1 items-center justify-start whitespace-nowrap">
 | 
				
			||||||
 | 
					        <DropdownMenu v-if="aiPrompts.length > 0">
 | 
				
			||||||
 | 
					          <DropdownMenuTrigger>
 | 
				
			||||||
 | 
					            <Button size="sm" variant="ghost" class="flex items-center justify-center" title="AI Prompts">
 | 
				
			||||||
 | 
					              <span class="flex items-center">
 | 
				
			||||||
 | 
					                <span class="text-medium">AI</span>
 | 
				
			||||||
 | 
					                <Bot size="14" class="ml-1" />
 | 
				
			||||||
 | 
					                <ChevronDown class="w-4 h-4 ml-2" />
 | 
				
			||||||
 | 
					              </span>
 | 
				
			||||||
 | 
					            </Button>
 | 
				
			||||||
 | 
					          </DropdownMenuTrigger>
 | 
				
			||||||
 | 
					          <DropdownMenuContent>
 | 
				
			||||||
 | 
					            <DropdownMenuItem
 | 
				
			||||||
 | 
					              v-for="prompt in aiPrompts"
 | 
				
			||||||
 | 
					              :key="prompt.key"
 | 
				
			||||||
 | 
					              @select="emitPrompt(prompt.key)"
 | 
				
			||||||
 | 
					            >
 | 
				
			||||||
 | 
					              {{ prompt.title }}
 | 
				
			||||||
 | 
					            </DropdownMenuItem>
 | 
				
			||||||
 | 
					          </DropdownMenuContent>
 | 
				
			||||||
 | 
					        </DropdownMenu>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <!-- Heading Dropdown for Article Mode -->
 | 
				
			||||||
 | 
					        <DropdownMenu v-if="editorType === 'article'">
 | 
				
			||||||
 | 
					          <DropdownMenuTrigger>
 | 
				
			||||||
 | 
					            <Button size="sm" variant="ghost" class="flex items-center justify-center" title="Heading Options">
 | 
				
			||||||
 | 
					              <span class="flex items-center">
 | 
				
			||||||
 | 
					                <Type size="14" />
 | 
				
			||||||
 | 
					                <span class="ml-1 text-xs font-medium">{{ getCurrentHeadingText() }}</span>
 | 
				
			||||||
 | 
					                <ChevronDown class="w-3 h-3 ml-1" />
 | 
				
			||||||
 | 
					              </span>
 | 
				
			||||||
 | 
					            </Button>
 | 
				
			||||||
 | 
					          </DropdownMenuTrigger>
 | 
				
			||||||
 | 
					          <DropdownMenuContent>
 | 
				
			||||||
 | 
					            <DropdownMenuItem @select="setParagraph" title="Set Paragraph">
 | 
				
			||||||
 | 
					              <span class="font-normal">Paragraph</span>
 | 
				
			||||||
 | 
					            </DropdownMenuItem>
 | 
				
			||||||
 | 
					            <DropdownMenuItem @select="() => setHeading(1)" title="Set Heading 1">
 | 
				
			||||||
 | 
					              <span class="text-xl font-bold">Heading 1</span>
 | 
				
			||||||
 | 
					            </DropdownMenuItem>
 | 
				
			||||||
 | 
					            <DropdownMenuItem @select="() => setHeading(2)" title="Set Heading 2">
 | 
				
			||||||
 | 
					              <span class="text-lg font-bold">Heading 2</span>
 | 
				
			||||||
 | 
					            </DropdownMenuItem>
 | 
				
			||||||
 | 
					            <DropdownMenuItem @select="() => setHeading(3)" title="Set Heading 3">
 | 
				
			||||||
 | 
					              <span class="text-base font-semibold">Heading 3</span>
 | 
				
			||||||
 | 
					            </DropdownMenuItem>
 | 
				
			||||||
 | 
					            <DropdownMenuItem @select="() => setHeading(4)" title="Set Heading 4">
 | 
				
			||||||
 | 
					              <span class="text-sm font-semibold">Heading 4</span>
 | 
				
			||||||
 | 
					            </DropdownMenuItem>
 | 
				
			||||||
 | 
					          </DropdownMenuContent>
 | 
				
			||||||
 | 
					        </DropdownMenu>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <Button
 | 
				
			||||||
 | 
					          size="sm"
 | 
				
			||||||
 | 
					          variant="ghost"
 | 
				
			||||||
 | 
					          @click.prevent="editor?.chain().focus().toggleBold().run()"
 | 
				
			||||||
 | 
					          :class="{ 'bg-gray-200 dark:bg-secondary': editor?.isActive('bold') }"
 | 
				
			||||||
 | 
					          title="Bold"
 | 
				
			||||||
 | 
					        >
 | 
				
			||||||
 | 
					          <Bold size="14" />
 | 
				
			||||||
 | 
					        </Button>
 | 
				
			||||||
 | 
					        <Button
 | 
				
			||||||
 | 
					          size="sm"
 | 
				
			||||||
 | 
					          variant="ghost"
 | 
				
			||||||
 | 
					          @click.prevent="editor?.chain().focus().toggleItalic().run()"
 | 
				
			||||||
 | 
					          :class="{ 'bg-gray-200 dark:bg-secondary': editor?.isActive('italic') }"
 | 
				
			||||||
 | 
					          title="Italic"
 | 
				
			||||||
 | 
					        >
 | 
				
			||||||
 | 
					          <Italic size="14" />
 | 
				
			||||||
 | 
					        </Button>
 | 
				
			||||||
 | 
					        <Button
 | 
				
			||||||
 | 
					          size="sm"
 | 
				
			||||||
 | 
					          variant="ghost"
 | 
				
			||||||
 | 
					          @click.prevent="editor?.chain().focus().toggleBulletList().run()"
 | 
				
			||||||
 | 
					          :class="{ 'bg-gray-200 dark:bg-secondary': editor?.isActive('bulletList') }"
 | 
				
			||||||
 | 
					          title="Bullet List"
 | 
				
			||||||
 | 
					        >
 | 
				
			||||||
 | 
					          <List size="14" />
 | 
				
			||||||
 | 
					        </Button>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <Button
 | 
				
			||||||
 | 
					          size="sm"
 | 
				
			||||||
 | 
					          variant="ghost"
 | 
				
			||||||
 | 
					          @click.prevent="editor?.chain().focus().toggleOrderedList().run()"
 | 
				
			||||||
 | 
					          :class="{ 'bg-gray-200 dark:bg-secondary': editor?.isActive('orderedList') }"
 | 
				
			||||||
 | 
					          title="Ordered List"
 | 
				
			||||||
 | 
					        >
 | 
				
			||||||
 | 
					          <ListOrdered size="14" />
 | 
				
			||||||
 | 
					        </Button>
 | 
				
			||||||
 | 
					        <Button
 | 
				
			||||||
 | 
					          size="sm"
 | 
				
			||||||
 | 
					          variant="ghost"
 | 
				
			||||||
 | 
					          @click.prevent="openLinkModal"
 | 
				
			||||||
 | 
					          :class="{ 'bg-gray-200 dark:bg-secondary': editor?.isActive('link') }"
 | 
				
			||||||
 | 
					          title="Insert Link"
 | 
				
			||||||
 | 
					        >
 | 
				
			||||||
 | 
					          <LinkIcon size="14" />
 | 
				
			||||||
 | 
					        </Button>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <!-- Additional tools for Article Mode -->
 | 
				
			||||||
 | 
					        <template v-if="editorType === 'article'">
 | 
				
			||||||
 | 
					          <Button
 | 
				
			||||||
 | 
					            size="sm"
 | 
				
			||||||
 | 
					            variant="ghost"
 | 
				
			||||||
 | 
					            @click.prevent="editor?.chain().focus().toggleCodeBlock().run()"
 | 
				
			||||||
 | 
					            :class="{ 'bg-gray-200 dark:bg-secondary': editor?.isActive('codeBlock') }"
 | 
				
			||||||
 | 
					            title="Code Block"
 | 
				
			||||||
 | 
					          >
 | 
				
			||||||
 | 
					            <Code size="14" />
 | 
				
			||||||
 | 
					          </Button>
 | 
				
			||||||
 | 
					          <Button
 | 
				
			||||||
 | 
					            size="sm"
 | 
				
			||||||
 | 
					            variant="ghost"
 | 
				
			||||||
 | 
					            @click.prevent="editor?.chain().focus().toggleBlockquote().run()"
 | 
				
			||||||
 | 
					            :class="{ 'bg-gray-200 dark:bg-secondary': editor?.isActive('blockquote') }"
 | 
				
			||||||
 | 
					            title="Blockquote"
 | 
				
			||||||
 | 
					          >
 | 
				
			||||||
 | 
					            <Quote size="14" />
 | 
				
			||||||
 | 
					          </Button>
 | 
				
			||||||
 | 
					        </template>
 | 
				
			||||||
 | 
					        <div v-if="showLinkInput" class="flex space-x-2 p-2 bg-background border rounded">
 | 
				
			||||||
 | 
					          <Input
 | 
				
			||||||
 | 
					            v-model="linkUrl"
 | 
				
			||||||
 | 
					            type="text"
 | 
				
			||||||
 | 
					            placeholder="Enter link URL"
 | 
				
			||||||
 | 
					            class="border p-1 text-sm w-[200px]"
 | 
				
			||||||
 | 
					          />
 | 
				
			||||||
 | 
					          <Button size="sm" @click="setLink" title="Set Link">
 | 
				
			||||||
 | 
					            <Check size="14" />
 | 
				
			||||||
 | 
					          </Button>
 | 
				
			||||||
 | 
					          <Button size="sm" @click="unsetLink" title="Unset Link">
 | 
				
			||||||
 | 
					            <X size="14" />
 | 
				
			||||||
 | 
					          </Button>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </BubbleMenu>
 | 
				
			||||||
 | 
					    <EditorContent :editor="editor" class="native-html" />
 | 
				
			||||||
 | 
					  </div>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script setup>
 | 
				
			||||||
 | 
					import { ref, watch, onUnmounted } from 'vue'
 | 
				
			||||||
 | 
					import { useEditor, EditorContent, BubbleMenu } from '@tiptap/vue-3'
 | 
				
			||||||
 | 
					import {
 | 
				
			||||||
 | 
					  ChevronDown,
 | 
				
			||||||
 | 
					  Bold,
 | 
				
			||||||
 | 
					  Italic,
 | 
				
			||||||
 | 
					  Bot,
 | 
				
			||||||
 | 
					  List,
 | 
				
			||||||
 | 
					  ListOrdered,
 | 
				
			||||||
 | 
					  Link as LinkIcon,
 | 
				
			||||||
 | 
					  Check,
 | 
				
			||||||
 | 
					  X,
 | 
				
			||||||
 | 
					  Type,
 | 
				
			||||||
 | 
					  Code,
 | 
				
			||||||
 | 
					  Quote
 | 
				
			||||||
 | 
					} from 'lucide-vue-next'
 | 
				
			||||||
 | 
					import { Button } from '@shared-ui/components/ui/button'
 | 
				
			||||||
 | 
					import {
 | 
				
			||||||
 | 
					  DropdownMenu,
 | 
				
			||||||
 | 
					  DropdownMenuContent,
 | 
				
			||||||
 | 
					  DropdownMenuItem,
 | 
				
			||||||
 | 
					  DropdownMenuTrigger
 | 
				
			||||||
 | 
					} from '@shared-ui/components/ui/dropdown-menu'
 | 
				
			||||||
 | 
					import { Input } from '@shared-ui/components/ui/input'
 | 
				
			||||||
 | 
					import Placeholder from '@tiptap/extension-placeholder'
 | 
				
			||||||
 | 
					import Image from '@tiptap/extension-image'
 | 
				
			||||||
 | 
					import StarterKit from '@tiptap/starter-kit'
 | 
				
			||||||
 | 
					import Link from '@tiptap/extension-link'
 | 
				
			||||||
 | 
					import Table from '@tiptap/extension-table'
 | 
				
			||||||
 | 
					import TableRow from '@tiptap/extension-table-row'
 | 
				
			||||||
 | 
					import TableCell from '@tiptap/extension-table-cell'
 | 
				
			||||||
 | 
					import TableHeader from '@tiptap/extension-table-header'
 | 
				
			||||||
 | 
					import { useTypingIndicator } from '@shared-ui/composables'
 | 
				
			||||||
 | 
					import { useConversationStore } from '@main/stores/conversation'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const textContent = defineModel('textContent', { default: '' })
 | 
				
			||||||
 | 
					const htmlContent = defineModel('htmlContent', { default: '' })
 | 
				
			||||||
 | 
					const showLinkInput = ref(false)
 | 
				
			||||||
 | 
					const linkUrl = ref('')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const props = defineProps({
 | 
				
			||||||
 | 
					  placeholder: String,
 | 
				
			||||||
 | 
					  insertContent: String,
 | 
				
			||||||
 | 
					  autoFocus: {
 | 
				
			||||||
 | 
					    type: Boolean,
 | 
				
			||||||
 | 
					    default: true
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  aiPrompts: {
 | 
				
			||||||
 | 
					    type: Array,
 | 
				
			||||||
 | 
					    default: () => []
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  editorType: {
 | 
				
			||||||
 | 
					    type: String,
 | 
				
			||||||
 | 
					    default: 'conversation',
 | 
				
			||||||
 | 
					    validator: (value) => ['conversation', 'article'].includes(value)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const emit = defineEmits(['send', 'aiPromptSelected'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const emitPrompt = (key) => emit('aiPromptSelected', key)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Set up typing indicator
 | 
				
			||||||
 | 
					const conversationStore = useConversationStore()
 | 
				
			||||||
 | 
					const { startTyping, stopTyping } = useTypingIndicator(conversationStore.sendTyping)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// To preseve the table styling in emails, need to set the table style inline.
 | 
				
			||||||
 | 
					// Created these custom extensions to set the table style inline.
 | 
				
			||||||
 | 
					const CustomTable = Table.extend({
 | 
				
			||||||
 | 
					  addAttributes() {
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      ...this.parent?.(),
 | 
				
			||||||
 | 
					      style: {
 | 
				
			||||||
 | 
					        parseHTML: (element) =>
 | 
				
			||||||
 | 
					          (element.getAttribute('style') || '') + '; border: 1px solid #dee2e6 !important; width: 100%; margin:0; table-layout: fixed; border-collapse: collapse; position:relative; border-radius: 0.25rem;'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const CustomTableCell = TableCell.extend({
 | 
				
			||||||
 | 
					  addAttributes() {
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      ...this.parent?.(),
 | 
				
			||||||
 | 
					      style: {
 | 
				
			||||||
 | 
					        parseHTML: (element) =>
 | 
				
			||||||
 | 
					          (element.getAttribute('style') || '') +
 | 
				
			||||||
 | 
					          '; border: 1px solid #dee2e6 !important; box-sizing: border-box !important; min-width: 1em !important; padding: 6px 8px !important; vertical-align: top !important;'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const CustomTableHeader = TableHeader.extend({
 | 
				
			||||||
 | 
					  addAttributes() {
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      ...this.parent?.(),
 | 
				
			||||||
 | 
					      style: {
 | 
				
			||||||
 | 
					        parseHTML: (element) =>
 | 
				
			||||||
 | 
					          (element.getAttribute('style') || '') +
 | 
				
			||||||
 | 
					          '; background-color: #f8f9fa !important; color: #212529 !important; font-weight: bold !important; text-align: left !important; border: 1px solid #dee2e6 !important; padding: 6px 8px !important;'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const isInternalUpdate = ref(false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Configure extensions based on editor type
 | 
				
			||||||
 | 
					const getExtensions = () => {
 | 
				
			||||||
 | 
					  const baseExtensions = [
 | 
				
			||||||
 | 
					    StarterKit.configure({
 | 
				
			||||||
 | 
					      heading: props.editorType === 'article' ? { levels: [1, 2, 3, 4] } : false
 | 
				
			||||||
 | 
					    }),
 | 
				
			||||||
 | 
					    Image.configure({ HTMLAttributes: { class: 'inline-image' } }),
 | 
				
			||||||
 | 
					    Placeholder.configure({ placeholder: () => props.placeholder }),
 | 
				
			||||||
 | 
					    Link
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Add table extensions
 | 
				
			||||||
 | 
					  if (props.editorType === 'article') {
 | 
				
			||||||
 | 
					    baseExtensions.push(
 | 
				
			||||||
 | 
					      CustomTable.configure({ resizable: true }),
 | 
				
			||||||
 | 
					      TableRow,
 | 
				
			||||||
 | 
					      CustomTableCell,
 | 
				
			||||||
 | 
					      CustomTableHeader
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    baseExtensions.push(
 | 
				
			||||||
 | 
					      CustomTable.configure({ resizable: false }),
 | 
				
			||||||
 | 
					      TableRow,
 | 
				
			||||||
 | 
					      CustomTableCell,
 | 
				
			||||||
 | 
					      CustomTableHeader
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return baseExtensions
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const editor = useEditor({
 | 
				
			||||||
 | 
					  extensions: getExtensions(),
 | 
				
			||||||
 | 
					  autofocus: props.autoFocus,
 | 
				
			||||||
 | 
					  content: htmlContent.value,
 | 
				
			||||||
 | 
					  editorProps: {
 | 
				
			||||||
 | 
					    attributes: { class: 'outline-none' },
 | 
				
			||||||
 | 
					    handleKeyDown: (view, event) => {
 | 
				
			||||||
 | 
					      if (event.ctrlKey && event.key === 'Enter') {
 | 
				
			||||||
 | 
					        emit('send')
 | 
				
			||||||
 | 
					        // Stop typing when sending
 | 
				
			||||||
 | 
					        stopTyping()
 | 
				
			||||||
 | 
					        return true
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  // To update state when user types.
 | 
				
			||||||
 | 
					  onUpdate: ({ editor }) => {
 | 
				
			||||||
 | 
					    isInternalUpdate.value = true
 | 
				
			||||||
 | 
					    htmlContent.value = editor.getHTML()
 | 
				
			||||||
 | 
					    textContent.value = editor.getText()
 | 
				
			||||||
 | 
					    isInternalUpdate.value = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Trigger typing indicator when user types
 | 
				
			||||||
 | 
					    startTyping()
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  onBlur: () => {
 | 
				
			||||||
 | 
					    // Stop typing when editor loses focus
 | 
				
			||||||
 | 
					    stopTyping()
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					watch(
 | 
				
			||||||
 | 
					  htmlContent,
 | 
				
			||||||
 | 
					  (newContent) => {
 | 
				
			||||||
 | 
					    if (!isInternalUpdate.value && editor.value && newContent !== editor.value.getHTML()) {
 | 
				
			||||||
 | 
					      editor.value.commands.setContent(newContent || '', false)
 | 
				
			||||||
 | 
					      textContent.value = editor.value.getText()
 | 
				
			||||||
 | 
					      editor.value.commands.focus()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  { immediate: true }
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Insert content at cursor position when insertContent prop changes.
 | 
				
			||||||
 | 
					watch(
 | 
				
			||||||
 | 
					  () => props.insertContent,
 | 
				
			||||||
 | 
					  (val) => {
 | 
				
			||||||
 | 
					    if (val) editor.value?.commands.insertContent(val)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					onUnmounted(() => {
 | 
				
			||||||
 | 
					  editor.value?.destroy()
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const openLinkModal = () => {
 | 
				
			||||||
 | 
					  if (editor.value?.isActive('link')) {
 | 
				
			||||||
 | 
					    linkUrl.value = editor.value.getAttributes('link').href
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    linkUrl.value = ''
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  showLinkInput.value = true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const setLink = () => {
 | 
				
			||||||
 | 
					  if (linkUrl.value) {
 | 
				
			||||||
 | 
					    editor.value?.chain().focus().extendMarkRange('link').setLink({ href: linkUrl.value }).run()
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  showLinkInput.value = false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const unsetLink = () => {
 | 
				
			||||||
 | 
					  editor.value?.chain().focus().unsetLink().run()
 | 
				
			||||||
 | 
					  showLinkInput.value = false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Heading functions for article mode
 | 
				
			||||||
 | 
					const setHeading = (level) => {
 | 
				
			||||||
 | 
					  editor.value?.chain().focus().toggleHeading({ level }).run()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const setParagraph = () => {
 | 
				
			||||||
 | 
					  editor.value?.chain().focus().setParagraph().run()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const getCurrentHeadingLevel = () => {
 | 
				
			||||||
 | 
					  if (!editor.value) return null
 | 
				
			||||||
 | 
					  for (let level = 1; level <= 4; level++) {
 | 
				
			||||||
 | 
					    if (editor.value.isActive('heading', { level })) {
 | 
				
			||||||
 | 
					      return level
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return null
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const getCurrentHeadingText = () => {
 | 
				
			||||||
 | 
					  const level = getCurrentHeadingLevel()
 | 
				
			||||||
 | 
					  if (level) return `H${level}`
 | 
				
			||||||
 | 
					  if (editor.value?.isActive('paragraph')) return 'P'
 | 
				
			||||||
 | 
					  return 'T'
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<style lang="scss">
 | 
				
			||||||
 | 
					// Moving placeholder to the top.
 | 
				
			||||||
 | 
					.tiptap p.is-editor-empty:first-child::before {
 | 
				
			||||||
 | 
					  content: attr(data-placeholder);
 | 
				
			||||||
 | 
					  float: left;
 | 
				
			||||||
 | 
					  color: #adb5bd;
 | 
				
			||||||
 | 
					  pointer-events: none;
 | 
				
			||||||
 | 
					  height: 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Ensure the parent div has a proper height
 | 
				
			||||||
 | 
					.editor-wrapper div[aria-expanded='false'] {
 | 
				
			||||||
 | 
					  display: flex;
 | 
				
			||||||
 | 
					  flex-direction: column;
 | 
				
			||||||
 | 
					  height: 100%;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Ensure the editor content has a proper height and breaks words
 | 
				
			||||||
 | 
					.tiptap.ProseMirror {
 | 
				
			||||||
 | 
					  flex: 1;
 | 
				
			||||||
 | 
					  min-height: 70px;
 | 
				
			||||||
 | 
					  overflow-y: auto;
 | 
				
			||||||
 | 
					  word-wrap: break-word !important;
 | 
				
			||||||
 | 
					  overflow-wrap: break-word !important;
 | 
				
			||||||
 | 
					  word-break: break-word;
 | 
				
			||||||
 | 
					  white-space: pre-wrap;
 | 
				
			||||||
 | 
					  max-width: 100%;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.tiptap {
 | 
				
			||||||
 | 
					  // Table styling
 | 
				
			||||||
 | 
					  .tableWrapper {
 | 
				
			||||||
 | 
					    margin: 1.5rem 0;
 | 
				
			||||||
 | 
					    overflow-x: auto;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Anchor tag styling
 | 
				
			||||||
 | 
					  a {
 | 
				
			||||||
 | 
					    color: #0066cc;
 | 
				
			||||||
 | 
					    cursor: pointer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    &:hover {
 | 
				
			||||||
 | 
					      color: #003d7a;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</style>
 | 
				
			||||||
@@ -11,8 +11,12 @@
 | 
				
			|||||||
        <!-- Field -->
 | 
					        <!-- Field -->
 | 
				
			||||||
        <div class="flex-1">
 | 
					        <div class="flex-1">
 | 
				
			||||||
          <Select v-model="modelFilter.field">
 | 
					          <Select v-model="modelFilter.field">
 | 
				
			||||||
            <SelectTrigger class="bg-transparent hover:bg-slate-100 w-full">
 | 
					            <SelectTrigger>
 | 
				
			||||||
              <SelectValue :placeholder="t('form.field.selectField')" />
 | 
					              <SelectValue
 | 
				
			||||||
 | 
					                :placeholder="
 | 
				
			||||||
 | 
					                  t('globals.messages.select', { name: t('globals.terms.field').toLowerCase() })
 | 
				
			||||||
 | 
					                "
 | 
				
			||||||
 | 
					              />
 | 
				
			||||||
            </SelectTrigger>
 | 
					            </SelectTrigger>
 | 
				
			||||||
            <SelectContent>
 | 
					            <SelectContent>
 | 
				
			||||||
              <SelectGroup>
 | 
					              <SelectGroup>
 | 
				
			||||||
@@ -27,8 +31,12 @@
 | 
				
			|||||||
        <!-- Operator -->
 | 
					        <!-- Operator -->
 | 
				
			||||||
        <div class="flex-1">
 | 
					        <div class="flex-1">
 | 
				
			||||||
          <Select v-model="modelFilter.operator" v-if="modelFilter.field">
 | 
					          <Select v-model="modelFilter.operator" v-if="modelFilter.field">
 | 
				
			||||||
            <SelectTrigger class="bg-transparent hover:bg-slate-100 w-full">
 | 
					            <SelectTrigger>
 | 
				
			||||||
              <SelectValue :placeholder="t('form.field.selectOperator')" />
 | 
					              <SelectValue
 | 
				
			||||||
 | 
					                :placeholder="
 | 
				
			||||||
 | 
					                  t('globals.messages.select', { name: t('globals.terms.operator').toLowerCase() })
 | 
				
			||||||
 | 
					                "
 | 
				
			||||||
 | 
					              />
 | 
				
			||||||
            </SelectTrigger>
 | 
					            </SelectTrigger>
 | 
				
			||||||
            <SelectContent>
 | 
					            <SelectContent>
 | 
				
			||||||
              <SelectGroup>
 | 
					              <SelectGroup>
 | 
				
			||||||
@@ -44,79 +52,46 @@
 | 
				
			|||||||
        <div class="flex-1">
 | 
					        <div class="flex-1">
 | 
				
			||||||
          <div v-if="modelFilter.field && modelFilter.operator">
 | 
					          <div v-if="modelFilter.field && modelFilter.operator">
 | 
				
			||||||
            <template v-if="modelFilter.operator !== 'set' && modelFilter.operator !== 'not set'">
 | 
					            <template v-if="modelFilter.operator !== 'set' && modelFilter.operator !== 'not set'">
 | 
				
			||||||
              <ComboBox
 | 
					              <SelectComboBox
 | 
				
			||||||
                v-if="getFieldOptions(modelFilter).length > 0"
 | 
					                v-if="
 | 
				
			||||||
 | 
					                  getFieldOptions(modelFilter).length > 0 &&
 | 
				
			||||||
 | 
					                  modelFilter.field === 'assigned_user_id'
 | 
				
			||||||
 | 
					                "
 | 
				
			||||||
                v-model="modelFilter.value"
 | 
					                v-model="modelFilter.value"
 | 
				
			||||||
                :items="getFieldOptions(modelFilter)"
 | 
					                :items="getFieldOptions(modelFilter)"
 | 
				
			||||||
                :placeholder="t('form.field.select')"
 | 
					                :placeholder="t('globals.messages.select', { name: '' })"
 | 
				
			||||||
              >
 | 
					                type="user"
 | 
				
			||||||
                <template #item="{ item }">
 | 
					 | 
				
			||||||
                  <div v-if="modelFilter.field === 'assigned_user_id'">
 | 
					 | 
				
			||||||
                    <div class="flex items-center gap-1">
 | 
					 | 
				
			||||||
                      <Avatar class="w-6 h-6">
 | 
					 | 
				
			||||||
                        <AvatarImage :src="item.avatar_url || ''" :alt="item.label.slice(0, 2)" />
 | 
					 | 
				
			||||||
                        <AvatarFallback>{{ item.label.slice(0, 2).toUpperCase() }} </AvatarFallback>
 | 
					 | 
				
			||||||
                      </Avatar>
 | 
					 | 
				
			||||||
                      <span>{{ item.label }}</span>
 | 
					 | 
				
			||||||
                    </div>
 | 
					 | 
				
			||||||
                  </div>
 | 
					 | 
				
			||||||
                  <div v-else-if="modelFilter.field === 'assigned_team_id'">
 | 
					 | 
				
			||||||
                    <div class="flex items-center gap-2 ml-2">
 | 
					 | 
				
			||||||
                      <span>{{ item.emoji }}</span>
 | 
					 | 
				
			||||||
                      <span>{{ item.label }}</span>
 | 
					 | 
				
			||||||
                    </div>
 | 
					 | 
				
			||||||
                  </div>
 | 
					 | 
				
			||||||
                  <div v-else>
 | 
					 | 
				
			||||||
                    {{ item.label }}
 | 
					 | 
				
			||||||
                  </div>
 | 
					 | 
				
			||||||
                </template>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                <template #selected="{ selected }">
 | 
					 | 
				
			||||||
                  <div v-if="!selected">{{ $t('form.field.selectValue') }}</div>
 | 
					 | 
				
			||||||
                  <div v-if="modelFilter.field === 'assigned_user_id'">
 | 
					 | 
				
			||||||
                    <div class="flex items-center gap-2">
 | 
					 | 
				
			||||||
                      <div v-if="selected" class="flex items-center gap-1">
 | 
					 | 
				
			||||||
                        <Avatar class="w-6 h-6">
 | 
					 | 
				
			||||||
                          <AvatarImage
 | 
					 | 
				
			||||||
                            :src="selected.avatar_url || ''"
 | 
					 | 
				
			||||||
                            :alt="selected.label.slice(0, 2)"
 | 
					 | 
				
			||||||
              />
 | 
					              />
 | 
				
			||||||
                          <AvatarFallback>{{
 | 
					
 | 
				
			||||||
                            selected.label.slice(0, 2).toUpperCase()
 | 
					              <SelectComboBox
 | 
				
			||||||
                          }}</AvatarFallback>
 | 
					                v-else-if="
 | 
				
			||||||
                        </Avatar>
 | 
					                  getFieldOptions(modelFilter).length > 0 &&
 | 
				
			||||||
                        <span>{{ selected.label }}</span>
 | 
					                  modelFilter.field === 'assigned_team_id'
 | 
				
			||||||
                      </div>
 | 
					                "
 | 
				
			||||||
                    </div>
 | 
					                v-model="modelFilter.value"
 | 
				
			||||||
                  </div>
 | 
					                :items="getFieldOptions(modelFilter)"
 | 
				
			||||||
                  <div v-else-if="modelFilter.field === 'assigned_team_id'">
 | 
					                :placeholder="t('globals.messages.select', { name: '' })"
 | 
				
			||||||
                    <div class="flex items-center gap-2">
 | 
					                type="team"
 | 
				
			||||||
                      <span v-if="selected">
 | 
					              />
 | 
				
			||||||
                        {{ selected.emoji }}
 | 
					
 | 
				
			||||||
                        <span>{{ selected.label }}</span>
 | 
					              <SelectComboBox
 | 
				
			||||||
                      </span>
 | 
					                v-else-if="getFieldOptions(modelFilter).length > 0"
 | 
				
			||||||
                    </div>
 | 
					                v-model="modelFilter.value"
 | 
				
			||||||
                  </div>
 | 
					                :items="getFieldOptions(modelFilter)"
 | 
				
			||||||
                  <div v-else-if="selected">
 | 
					                :placeholder="t('globals.messages.select', { name: '' })"
 | 
				
			||||||
                    {{ selected.label }}
 | 
					              />
 | 
				
			||||||
                  </div>
 | 
					
 | 
				
			||||||
                </template>
 | 
					 | 
				
			||||||
              </ComboBox>
 | 
					 | 
				
			||||||
              <Input
 | 
					              <Input
 | 
				
			||||||
                v-else
 | 
					                v-else
 | 
				
			||||||
                v-model="modelFilter.value"
 | 
					                v-model="modelFilter.value"
 | 
				
			||||||
                class="bg-transparent hover:bg-slate-100"
 | 
					                :placeholder="t('globals.terms.value')"
 | 
				
			||||||
                :placeholder="t('form.field.value')"
 | 
					 | 
				
			||||||
                type="text"
 | 
					                type="text"
 | 
				
			||||||
              />
 | 
					              />
 | 
				
			||||||
            </template>
 | 
					            </template>
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
 | 
					      <CloseButton :onClose="() => removeFilter(index)" />
 | 
				
			||||||
      <button @click="removeFilter(index)" class="p-1 hover:bg-slate-100 rounded">
 | 
					 | 
				
			||||||
        <X class="w-4 h-4 text-slate-500" />
 | 
					 | 
				
			||||||
      </button>
 | 
					 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <div class="flex items-center justify-between pt-3">
 | 
					    <div class="flex items-center justify-between pt-3">
 | 
				
			||||||
@@ -129,8 +104,8 @@
 | 
				
			|||||||
        }}
 | 
					        }}
 | 
				
			||||||
      </Button>
 | 
					      </Button>
 | 
				
			||||||
      <div class="flex gap-2" v-if="showButtons">
 | 
					      <div class="flex gap-2" v-if="showButtons">
 | 
				
			||||||
        <Button variant="ghost" @click="clearFilters">{{ $t('globals.buttons.reset') }}</Button>
 | 
					        <Button variant="ghost" @click="clearFilters">{{ $t('globals.messages.reset') }}</Button>
 | 
				
			||||||
        <Button @click="applyFilters">{{ $t('globals.buttons.apply') }}</Button>
 | 
					        <Button @click="applyFilters">{{ $t('globals.messages.apply') }}</Button>
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
@@ -145,13 +120,13 @@ import {
 | 
				
			|||||||
  SelectItem,
 | 
					  SelectItem,
 | 
				
			||||||
  SelectTrigger,
 | 
					  SelectTrigger,
 | 
				
			||||||
  SelectValue
 | 
					  SelectValue
 | 
				
			||||||
} from '@/components/ui/select'
 | 
					} from '@shared-ui/components/ui/select'
 | 
				
			||||||
import { Plus, X } from 'lucide-vue-next'
 | 
					import { Plus } from 'lucide-vue-next'
 | 
				
			||||||
import { Button } from '@/components/ui/button'
 | 
					import { Button } from '@shared-ui/components/ui/button'
 | 
				
			||||||
import { Input } from '@/components/ui/input'
 | 
					import { Input } from '@shared-ui/components/ui/input'
 | 
				
			||||||
import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar'
 | 
					 | 
				
			||||||
import { useI18n } from 'vue-i18n'
 | 
					import { useI18n } from 'vue-i18n'
 | 
				
			||||||
import ComboBox from '@/components/ui/combobox/ComboBox.vue'
 | 
					import CloseButton from '@main/components/button/CloseButton.vue'
 | 
				
			||||||
 | 
					import SelectComboBox from '@main/components/combobox/SelectCombobox.vue'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const props = defineProps({
 | 
					const props = defineProps({
 | 
				
			||||||
  fields: {
 | 
					  fields: {
 | 
				
			||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <div v-if="!isHidden">
 | 
					  <div v-if="!isHidden">
 | 
				
			||||||
    <div class="flex items-center space-x-4 h-12 px-2">
 | 
					    <div class="flex items-center space-x-4 h-12 px-2">
 | 
				
			||||||
      <SidebarTrigger class="cursor-pointer w-4 h-4" />
 | 
					      <SidebarTrigger class="cursor-pointer" />
 | 
				
			||||||
      <span class="text-xl font-semibold text-gray-800">
 | 
					      <span class="text-xl font-semibold">
 | 
				
			||||||
        {{ title }}
 | 
					        {{ title }}
 | 
				
			||||||
      </span>
 | 
					      </span>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
@@ -12,8 +12,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
<script setup>
 | 
					<script setup>
 | 
				
			||||||
import { computed } from 'vue'
 | 
					import { computed } from 'vue'
 | 
				
			||||||
import { Separator } from '@/components/ui/separator'
 | 
					import { Separator } from '@shared-ui/components/ui/separator'
 | 
				
			||||||
import { SidebarTrigger } from '@/components/ui/sidebar'
 | 
					import { SidebarTrigger } from '@shared-ui/components/ui/sidebar'
 | 
				
			||||||
import { useRoute } from 'vue-router'
 | 
					import { useRoute } from 'vue-router'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const route = useRoute()
 | 
					const route = useRoute()
 | 
				
			||||||
@@ -4,9 +4,9 @@ import {
 | 
				
			|||||||
  reportsNavItems,
 | 
					  reportsNavItems,
 | 
				
			||||||
  accountNavItems,
 | 
					  accountNavItems,
 | 
				
			||||||
  contactNavItems
 | 
					  contactNavItems
 | 
				
			||||||
} from '@/constants/navigation'
 | 
					} from '../../constants/navigation'
 | 
				
			||||||
import { RouterLink, useRoute } from 'vue-router'
 | 
					import { RouterLink, useRoute, useRouter } from 'vue-router'
 | 
				
			||||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'
 | 
					import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@shared-ui/components/ui/collapsible'
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  Sidebar,
 | 
					  Sidebar,
 | 
				
			||||||
  SidebarContent,
 | 
					  SidebarContent,
 | 
				
			||||||
@@ -14,7 +14,6 @@ import {
 | 
				
			|||||||
  SidebarHeader,
 | 
					  SidebarHeader,
 | 
				
			||||||
  SidebarInset,
 | 
					  SidebarInset,
 | 
				
			||||||
  SidebarMenu,
 | 
					  SidebarMenu,
 | 
				
			||||||
  SidebarSeparator,
 | 
					 | 
				
			||||||
  SidebarMenuAction,
 | 
					  SidebarMenuAction,
 | 
				
			||||||
  SidebarMenuButton,
 | 
					  SidebarMenuButton,
 | 
				
			||||||
  SidebarMenuItem,
 | 
					  SidebarMenuItem,
 | 
				
			||||||
@@ -22,39 +21,50 @@ import {
 | 
				
			|||||||
  SidebarMenuSubItem,
 | 
					  SidebarMenuSubItem,
 | 
				
			||||||
  SidebarProvider,
 | 
					  SidebarProvider,
 | 
				
			||||||
  SidebarRail
 | 
					  SidebarRail
 | 
				
			||||||
} from '@/components/ui/sidebar'
 | 
					} from '@shared-ui/components/ui/sidebar'
 | 
				
			||||||
import { useAppSettingsStore } from '@/stores/appSettings'
 | 
					import { useAppSettingsStore } from '../../stores/appSettings'
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  ChevronRight,
 | 
					  ChevronRight,
 | 
				
			||||||
  EllipsisVertical,
 | 
					  EllipsisVertical,
 | 
				
			||||||
  User,
 | 
					  User,
 | 
				
			||||||
  UserSearch,
 | 
					 | 
				
			||||||
  UsersRound,
 | 
					 | 
				
			||||||
  Search,
 | 
					  Search,
 | 
				
			||||||
  Plus
 | 
					  Plus,
 | 
				
			||||||
 | 
					  CircleDashed,
 | 
				
			||||||
 | 
					  List
 | 
				
			||||||
} from 'lucide-vue-next'
 | 
					} from 'lucide-vue-next'
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  DropdownMenu,
 | 
					  DropdownMenu,
 | 
				
			||||||
  DropdownMenuContent,
 | 
					  DropdownMenuContent,
 | 
				
			||||||
  DropdownMenuItem,
 | 
					  DropdownMenuItem,
 | 
				
			||||||
  DropdownMenuTrigger
 | 
					  DropdownMenuTrigger
 | 
				
			||||||
} from '@/components/ui/dropdown-menu'
 | 
					} from '@shared-ui/components/ui/dropdown-menu'
 | 
				
			||||||
import { filterNavItems } from '@/utils/nav-permissions'
 | 
					import { filterNavItems } from '../../utils/nav-permissions'
 | 
				
			||||||
import { useStorage } from '@vueuse/core'
 | 
					import { useStorage } from '@vueuse/core'
 | 
				
			||||||
import { computed } from 'vue'
 | 
					import { computed, ref, watch } from 'vue'
 | 
				
			||||||
import { useI18n } from 'vue-i18n'
 | 
					import { useI18n } from 'vue-i18n'
 | 
				
			||||||
import { useUserStore } from '@/stores/user'
 | 
					import { useUserStore } from '../../stores/user'
 | 
				
			||||||
 | 
					import { useConversationStore } from '../../stores/conversation'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
defineProps({
 | 
					defineProps({
 | 
				
			||||||
  userTeams: { type: Array, default: () => [] },
 | 
					  userTeams: { type: Array, default: () => [] },
 | 
				
			||||||
  userViews: { type: Array, default: () => [] }
 | 
					  userViews: { type: Array, default: () => [] }
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
const userStore = useUserStore()
 | 
					const userStore = useUserStore()
 | 
				
			||||||
 | 
					const conversationStore = useConversationStore()
 | 
				
			||||||
const settingsStore = useAppSettingsStore()
 | 
					const settingsStore = useAppSettingsStore()
 | 
				
			||||||
const route = useRoute()
 | 
					const route = useRoute()
 | 
				
			||||||
 | 
					const router = useRouter()
 | 
				
			||||||
const { t } = useI18n()
 | 
					const { t } = useI18n()
 | 
				
			||||||
const emit = defineEmits(['createView', 'editView', 'deleteView', 'createConversation'])
 | 
					const emit = defineEmits(['createView', 'editView', 'deleteView', 'createConversation'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const isActiveParent = (parentHref) => {
 | 
				
			||||||
 | 
					  return route.path.startsWith(parentHref)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const isInboxRoute = (path) => {
 | 
				
			||||||
 | 
					  return path.startsWith('/inboxes')
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const openCreateViewDialog = () => {
 | 
					const openCreateViewDialog = () => {
 | 
				
			||||||
  emit('createView')
 | 
					  emit('createView')
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -67,18 +77,83 @@ const deleteView = (view) => {
 | 
				
			|||||||
  emit('deleteView', view)
 | 
					  emit('deleteView', view)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Navigation methods with conversation retention
 | 
				
			||||||
 | 
					const navigateToInbox = (type) => {
 | 
				
			||||||
 | 
					  if (conversationStore.hasConversationOpen && conversationStore.conversation.data?.uuid) {
 | 
				
			||||||
 | 
					    router.push({
 | 
				
			||||||
 | 
					      name: 'inbox-conversation',
 | 
				
			||||||
 | 
					      params: {
 | 
				
			||||||
 | 
					        type,
 | 
				
			||||||
 | 
					        uuid: conversationStore.conversation.data.uuid
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    router.push({
 | 
				
			||||||
 | 
					      name: 'inbox',
 | 
				
			||||||
 | 
					      params: { type }
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const navigateToTeamInbox = (teamID) => {
 | 
				
			||||||
 | 
					  if (conversationStore.hasConversationOpen && conversationStore.conversation.data?.uuid) {
 | 
				
			||||||
 | 
					    router.push({
 | 
				
			||||||
 | 
					      name: 'team-inbox-conversation',
 | 
				
			||||||
 | 
					      params: {
 | 
				
			||||||
 | 
					        teamID,
 | 
				
			||||||
 | 
					        uuid: conversationStore.conversation.data.uuid
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    router.push({
 | 
				
			||||||
 | 
					      name: 'team-inbox',
 | 
				
			||||||
 | 
					      params: { teamID }
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const navigateToViewInbox = (viewID) => {
 | 
				
			||||||
 | 
					  if (conversationStore.hasConversationOpen && conversationStore.conversation.data?.uuid) {
 | 
				
			||||||
 | 
					    router.push({
 | 
				
			||||||
 | 
					      name: 'view-inbox-conversation',
 | 
				
			||||||
 | 
					      params: {
 | 
				
			||||||
 | 
					        viewID,
 | 
				
			||||||
 | 
					        uuid: conversationStore.conversation.data.uuid
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    router.push({
 | 
				
			||||||
 | 
					      name: 'view-inbox',
 | 
				
			||||||
 | 
					      params: { viewID }
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const filteredAdminNavItems = computed(() => filterNavItems(adminNavItems, userStore.can))
 | 
					const filteredAdminNavItems = computed(() => filterNavItems(adminNavItems, userStore.can))
 | 
				
			||||||
const filteredReportsNavItems = computed(() => filterNavItems(reportsNavItems, userStore.can))
 | 
					const filteredReportsNavItems = computed(() => filterNavItems(reportsNavItems, userStore.can))
 | 
				
			||||||
const filteredContactsNavItems = computed(() => filterNavItems(contactNavItems, userStore.can))
 | 
					const filteredContactsNavItems = computed(() => filterNavItems(contactNavItems, userStore.can))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const isActiveParent = (parentHref) => {
 | 
					// For auto opening admin collapsibles when a child route is active
 | 
				
			||||||
  return route.path.startsWith(parentHref)
 | 
					const openAdminCollapsible = ref(null)
 | 
				
			||||||
 | 
					const toggleAdminCollapsible = (titleKey) => {
 | 
				
			||||||
 | 
					  openAdminCollapsible.value = openAdminCollapsible.value === titleKey ? null : titleKey
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					// Watch for route changes and update the active collapsible
 | 
				
			||||||
const isInboxRoute = (path) => {
 | 
					watch(
 | 
				
			||||||
  return path.startsWith('/inboxes')
 | 
					  [() => route.path, filteredAdminNavItems],
 | 
				
			||||||
 | 
					  () => {
 | 
				
			||||||
 | 
					    const activeItem = filteredAdminNavItems.value.find((item) => {
 | 
				
			||||||
 | 
					      if (!item.children) return isActiveParent(item.href)
 | 
				
			||||||
 | 
					      return item.children.some((child) => isActiveParent(child.href))
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    if (activeItem) {
 | 
				
			||||||
 | 
					      openAdminCollapsible.value = activeItem.titleKey
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  { immediate: true }
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Sidebar open state in local storage
 | 
				
			||||||
const sidebarOpen = useStorage('mainSidebarOpen', true)
 | 
					const sidebarOpen = useStorage('mainSidebarOpen', true)
 | 
				
			||||||
const teamInboxOpen = useStorage('teamInboxOpen', true)
 | 
					const teamInboxOpen = useStorage('teamInboxOpen', true)
 | 
				
			||||||
const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
					const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
				
			||||||
@@ -98,24 +173,25 @@ const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
				
			|||||||
        <SidebarHeader>
 | 
					        <SidebarHeader>
 | 
				
			||||||
          <SidebarMenu>
 | 
					          <SidebarMenu>
 | 
				
			||||||
            <SidebarMenuItem>
 | 
					            <SidebarMenuItem>
 | 
				
			||||||
              <SidebarMenuButton :isActive="isActiveParent('/contacts')" asChild>
 | 
					              <div class="px-1">
 | 
				
			||||||
                <div>
 | 
					 | 
				
			||||||
                <span class="font-semibold text-xl">
 | 
					                <span class="font-semibold text-xl">
 | 
				
			||||||
                  {{ t('globals.terms.contact', 2) }}
 | 
					                  {{ t('globals.terms.contact', 2) }}
 | 
				
			||||||
                </span>
 | 
					                </span>
 | 
				
			||||||
              </div>
 | 
					              </div>
 | 
				
			||||||
              </SidebarMenuButton>
 | 
					 | 
				
			||||||
            </SidebarMenuItem>
 | 
					            </SidebarMenuItem>
 | 
				
			||||||
          </SidebarMenu>
 | 
					          </SidebarMenu>
 | 
				
			||||||
        </SidebarHeader>
 | 
					        </SidebarHeader>
 | 
				
			||||||
        <SidebarSeparator />
 | 
					 | 
				
			||||||
        <SidebarContent>
 | 
					        <SidebarContent>
 | 
				
			||||||
          <SidebarGroup>
 | 
					          <SidebarGroup>
 | 
				
			||||||
            <SidebarMenu>
 | 
					            <SidebarMenu>
 | 
				
			||||||
              <SidebarMenuItem v-for="item in filteredContactsNavItems" :key="item.titleKey">
 | 
					              <SidebarMenuItem v-for="item in filteredContactsNavItems" :key="item.titleKey">
 | 
				
			||||||
                <SidebarMenuButton :isActive="isActiveParent(item.href)" asChild>
 | 
					                <SidebarMenuButton :isActive="isActiveParent(item.href)" asChild>
 | 
				
			||||||
                  <router-link :to="item.href">
 | 
					                  <router-link :to="item.href">
 | 
				
			||||||
                    <span>{{ t(item.titleKey) }}</span>
 | 
					                    <span>{{
 | 
				
			||||||
 | 
					                      t('globals.messages.all', {
 | 
				
			||||||
 | 
					                        name: t(item.titleKey, 2).toLowerCase()
 | 
				
			||||||
 | 
					                      })
 | 
				
			||||||
 | 
					                    }}</span>
 | 
				
			||||||
                  </router-link>
 | 
					                  </router-link>
 | 
				
			||||||
                </SidebarMenuButton>
 | 
					                </SidebarMenuButton>
 | 
				
			||||||
              </SidebarMenuItem>
 | 
					              </SidebarMenuItem>
 | 
				
			||||||
@@ -137,17 +213,14 @@ const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
				
			|||||||
        <SidebarHeader>
 | 
					        <SidebarHeader>
 | 
				
			||||||
          <SidebarMenu>
 | 
					          <SidebarMenu>
 | 
				
			||||||
            <SidebarMenuItem>
 | 
					            <SidebarMenuItem>
 | 
				
			||||||
              <SidebarMenuButton :isActive="isActiveParent('/reports/overview')" asChild>
 | 
					              <div class="px-1">
 | 
				
			||||||
                <div>
 | 
					 | 
				
			||||||
                <span class="font-semibold text-xl">
 | 
					                <span class="font-semibold text-xl">
 | 
				
			||||||
                    {{ t('navigation.reports') }}
 | 
					                  {{ t('globals.terms.report', 2) }}
 | 
				
			||||||
                </span>
 | 
					                </span>
 | 
				
			||||||
              </div>
 | 
					              </div>
 | 
				
			||||||
              </SidebarMenuButton>
 | 
					 | 
				
			||||||
            </SidebarMenuItem>
 | 
					            </SidebarMenuItem>
 | 
				
			||||||
          </SidebarMenu>
 | 
					          </SidebarMenu>
 | 
				
			||||||
        </SidebarHeader>
 | 
					        </SidebarHeader>
 | 
				
			||||||
        <SidebarSeparator />
 | 
					 | 
				
			||||||
        <SidebarContent>
 | 
					        <SidebarContent>
 | 
				
			||||||
          <SidebarGroup>
 | 
					          <SidebarGroup>
 | 
				
			||||||
            <SidebarMenu>
 | 
					            <SidebarMenu>
 | 
				
			||||||
@@ -171,21 +244,18 @@ const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
				
			|||||||
        <SidebarHeader>
 | 
					        <SidebarHeader>
 | 
				
			||||||
          <SidebarMenu>
 | 
					          <SidebarMenu>
 | 
				
			||||||
            <SidebarMenuItem>
 | 
					            <SidebarMenuItem>
 | 
				
			||||||
              <SidebarMenuButton :isActive="isActiveParent('/admin')" asChild>
 | 
					              <div class="flex flex-col items-start justify-between w-full px-1">
 | 
				
			||||||
                <div class="flex items-center justify-between w-full">
 | 
					 | 
				
			||||||
                <span class="font-semibold text-xl">
 | 
					                <span class="font-semibold text-xl">
 | 
				
			||||||
                    {{ t('navigation.admin') }}
 | 
					                  {{ t('globals.terms.admin') }}
 | 
				
			||||||
                </span>
 | 
					                </span>
 | 
				
			||||||
                </div>
 | 
					 | 
				
			||||||
                <!-- App version -->
 | 
					                <!-- App version -->
 | 
				
			||||||
                <div class="text-xs text-muted-foreground ml-2">
 | 
					                <div class="text-xs text-muted-foreground">
 | 
				
			||||||
                  ({{ settingsStore.settings['app.version'] }})
 | 
					                  ({{ settingsStore.settings['app.version'] }})
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
              </SidebarMenuButton>
 | 
					              </div>
 | 
				
			||||||
            </SidebarMenuItem>
 | 
					            </SidebarMenuItem>
 | 
				
			||||||
          </SidebarMenu>
 | 
					          </SidebarMenu>
 | 
				
			||||||
        </SidebarHeader>
 | 
					        </SidebarHeader>
 | 
				
			||||||
        <SidebarSeparator />
 | 
					 | 
				
			||||||
        <SidebarContent>
 | 
					        <SidebarContent>
 | 
				
			||||||
          <SidebarGroup>
 | 
					          <SidebarGroup>
 | 
				
			||||||
            <SidebarMenu>
 | 
					            <SidebarMenu>
 | 
				
			||||||
@@ -203,11 +273,12 @@ const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
				
			|||||||
                <Collapsible
 | 
					                <Collapsible
 | 
				
			||||||
                  v-else
 | 
					                  v-else
 | 
				
			||||||
                  class="group/collapsible"
 | 
					                  class="group/collapsible"
 | 
				
			||||||
                  :default-open="isActiveParent(item.href)"
 | 
					                  :open="openAdminCollapsible === item.titleKey"
 | 
				
			||||||
 | 
					                  @update:open="toggleAdminCollapsible(item.titleKey)"
 | 
				
			||||||
                >
 | 
					                >
 | 
				
			||||||
                  <CollapsibleTrigger as-child>
 | 
					                  <CollapsibleTrigger as-child>
 | 
				
			||||||
                    <SidebarMenuButton :isActive="isActiveParent(item.href)">
 | 
					                    <SidebarMenuButton :isActive="isActiveParent(item.href)">
 | 
				
			||||||
                      <span>{{ t(item.titleKey) }}</span>
 | 
					                      <span>{{ t(item.titleKey, item.isTitleKeyPlural === true ? 2 : 1) }}</span>
 | 
				
			||||||
                      <ChevronRight
 | 
					                      <ChevronRight
 | 
				
			||||||
                        class="ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90"
 | 
					                        class="ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90"
 | 
				
			||||||
                      />
 | 
					                      />
 | 
				
			||||||
@@ -218,7 +289,7 @@ const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
				
			|||||||
                      <SidebarMenuSubItem v-for="child in item.children" :key="child.titleKey">
 | 
					                      <SidebarMenuSubItem v-for="child in item.children" :key="child.titleKey">
 | 
				
			||||||
                        <SidebarMenuButton size="sm" :isActive="isActiveParent(child.href)" asChild>
 | 
					                        <SidebarMenuButton size="sm" :isActive="isActiveParent(child.href)" asChild>
 | 
				
			||||||
                          <router-link :to="child.href">
 | 
					                          <router-link :to="child.href">
 | 
				
			||||||
                            <span>{{ t(child.titleKey) }}</span>
 | 
					                            <span>{{ t(child.titleKey, child.isTitleKeyPlural === true ? 2 : 1) }}</span>
 | 
				
			||||||
                          </router-link>
 | 
					                          </router-link>
 | 
				
			||||||
                        </SidebarMenuButton>
 | 
					                        </SidebarMenuButton>
 | 
				
			||||||
                      </SidebarMenuSubItem>
 | 
					                      </SidebarMenuSubItem>
 | 
				
			||||||
@@ -239,17 +310,14 @@ const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
				
			|||||||
        <SidebarHeader>
 | 
					        <SidebarHeader>
 | 
				
			||||||
          <SidebarMenu>
 | 
					          <SidebarMenu>
 | 
				
			||||||
            <SidebarMenuItem>
 | 
					            <SidebarMenuItem>
 | 
				
			||||||
              <SidebarMenuButton :isActive="isActiveParent('/account/profile')" asChild>
 | 
					              <div class="px-1">
 | 
				
			||||||
                <div>
 | 
					 | 
				
			||||||
                <span class="font-semibold text-xl">
 | 
					                <span class="font-semibold text-xl">
 | 
				
			||||||
                    {{ t('navigation.account') }}
 | 
					                  {{ t('globals.terms.account') }}
 | 
				
			||||||
                </span>
 | 
					                </span>
 | 
				
			||||||
              </div>
 | 
					              </div>
 | 
				
			||||||
              </SidebarMenuButton>
 | 
					 | 
				
			||||||
            </SidebarMenuItem>
 | 
					            </SidebarMenuItem>
 | 
				
			||||||
          </SidebarMenu>
 | 
					          </SidebarMenu>
 | 
				
			||||||
        </SidebarHeader>
 | 
					        </SidebarHeader>
 | 
				
			||||||
        <SidebarSeparator />
 | 
					 | 
				
			||||||
        <SidebarContent>
 | 
					        <SidebarContent>
 | 
				
			||||||
          <SidebarGroup>
 | 
					          <SidebarGroup>
 | 
				
			||||||
            <SidebarMenu>
 | 
					            <SidebarMenu>
 | 
				
			||||||
@@ -276,28 +344,20 @@ const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
				
			|||||||
        <SidebarHeader>
 | 
					        <SidebarHeader>
 | 
				
			||||||
          <SidebarMenu>
 | 
					          <SidebarMenu>
 | 
				
			||||||
            <SidebarMenuItem>
 | 
					            <SidebarMenuItem>
 | 
				
			||||||
              <SidebarMenuButton asChild>
 | 
					              <div class="flex items-center justify-between w-full px-1">
 | 
				
			||||||
                <div class="flex items-center justify-between w-full">
 | 
					 | 
				
			||||||
                <div class="font-semibold text-xl">
 | 
					                <div class="font-semibold text-xl">
 | 
				
			||||||
                    <span>{{ t('navigation.inbox') }}</span>
 | 
					                  <span>{{ t('globals.terms.inbox') }}</span>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
                  <div class="ml-auto">
 | 
					                <div class="mr-1 mt-1 hover:scale-110 transition-transform">
 | 
				
			||||||
                    <div class="flex items-center space-x-2">
 | 
					 | 
				
			||||||
                  <router-link :to="{ name: 'search' }">
 | 
					                  <router-link :to="{ name: 'search' }">
 | 
				
			||||||
                        <button
 | 
					                    <Search size="18" stroke-width="2.5" />
 | 
				
			||||||
                          class="flex items-center bg-accent p-2 rounded-full hover:scale-110 transition-transform duration-100"
 | 
					 | 
				
			||||||
                        >
 | 
					 | 
				
			||||||
                          <Search size="15" stroke-width="2.5" />
 | 
					 | 
				
			||||||
                        </button>
 | 
					 | 
				
			||||||
                  </router-link>
 | 
					                  </router-link>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
              </div>
 | 
					              </div>
 | 
				
			||||||
                </div>
 | 
					 | 
				
			||||||
              </SidebarMenuButton>
 | 
					 | 
				
			||||||
            </SidebarMenuItem>
 | 
					            </SidebarMenuItem>
 | 
				
			||||||
          </SidebarMenu>
 | 
					          </SidebarMenu>
 | 
				
			||||||
        </SidebarHeader>
 | 
					        </SidebarHeader>
 | 
				
			||||||
        <SidebarSeparator />
 | 
					
 | 
				
			||||||
        <SidebarContent>
 | 
					        <SidebarContent>
 | 
				
			||||||
          <SidebarGroup>
 | 
					          <SidebarGroup>
 | 
				
			||||||
            <SidebarMenu>
 | 
					            <SidebarMenu>
 | 
				
			||||||
@@ -317,32 +377,32 @@ const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
				
			|||||||
              </SidebarMenuItem>
 | 
					              </SidebarMenuItem>
 | 
				
			||||||
              <SidebarMenuItem>
 | 
					              <SidebarMenuItem>
 | 
				
			||||||
                <SidebarMenuButton asChild :isActive="isActiveParent('/inboxes/assigned')">
 | 
					                <SidebarMenuButton asChild :isActive="isActiveParent('/inboxes/assigned')">
 | 
				
			||||||
                  <router-link :to="{ name: 'inbox', params: { type: 'assigned' } }">
 | 
					                  <a href="#" @click.prevent="navigateToInbox('assigned')">
 | 
				
			||||||
                    <User />
 | 
					                    <User />
 | 
				
			||||||
                    <span>{{ t('navigation.myInbox') }}</span>
 | 
					                    <span>{{ t('globals.terms.myInbox') }}</span>
 | 
				
			||||||
                  </router-link>
 | 
					                  </a>
 | 
				
			||||||
                </SidebarMenuButton>
 | 
					                </SidebarMenuButton>
 | 
				
			||||||
              </SidebarMenuItem>
 | 
					              </SidebarMenuItem>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              <SidebarMenuItem>
 | 
					              <SidebarMenuItem>
 | 
				
			||||||
                <SidebarMenuButton asChild :isActive="isActiveParent('/inboxes/unassigned')">
 | 
					                <SidebarMenuButton asChild :isActive="isActiveParent('/inboxes/unassigned')">
 | 
				
			||||||
                  <router-link :to="{ name: 'inbox', params: { type: 'unassigned' } }">
 | 
					                  <a href="#" @click.prevent="navigateToInbox('unassigned')">
 | 
				
			||||||
                    <UserSearch />
 | 
					                    <CircleDashed />
 | 
				
			||||||
                    <span>
 | 
					                    <span>
 | 
				
			||||||
                      {{ t('navigation.unassigned') }}
 | 
					                      {{ t('globals.terms.unassigned') }}
 | 
				
			||||||
                    </span>
 | 
					                    </span>
 | 
				
			||||||
                  </router-link>
 | 
					                  </a>
 | 
				
			||||||
                </SidebarMenuButton>
 | 
					                </SidebarMenuButton>
 | 
				
			||||||
              </SidebarMenuItem>
 | 
					              </SidebarMenuItem>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              <SidebarMenuItem>
 | 
					              <SidebarMenuItem>
 | 
				
			||||||
                <SidebarMenuButton asChild :isActive="isActiveParent('/inboxes/all')">
 | 
					                <SidebarMenuButton asChild :isActive="isActiveParent('/inboxes/all')">
 | 
				
			||||||
                  <router-link :to="{ name: 'inbox', params: { type: 'all' } }">
 | 
					                  <a href="#" @click.prevent="navigateToInbox('all')">
 | 
				
			||||||
                    <UsersRound />
 | 
					                    <List />
 | 
				
			||||||
                    <span>
 | 
					                    <span>
 | 
				
			||||||
                      {{ t('navigation.all') }}
 | 
					                      {{ t('globals.messages.all') }}
 | 
				
			||||||
                    </span>
 | 
					                    </span>
 | 
				
			||||||
                  </router-link>
 | 
					                  </a>
 | 
				
			||||||
                </SidebarMenuButton>
 | 
					                </SidebarMenuButton>
 | 
				
			||||||
              </SidebarMenuItem>
 | 
					              </SidebarMenuItem>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -359,7 +419,7 @@ const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
				
			|||||||
                      <router-link to="#">
 | 
					                      <router-link to="#">
 | 
				
			||||||
                        <!-- <Users /> -->
 | 
					                        <!-- <Users /> -->
 | 
				
			||||||
                        <span>
 | 
					                        <span>
 | 
				
			||||||
                          {{ t('navigation.teamInboxes') }}
 | 
					                          {{ t('globals.terms.teamInbox', 2) }}
 | 
				
			||||||
                        </span>
 | 
					                        </span>
 | 
				
			||||||
                        <ChevronRight
 | 
					                        <ChevronRight
 | 
				
			||||||
                          class="ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90"
 | 
					                          class="ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90"
 | 
				
			||||||
@@ -375,9 +435,9 @@ const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
				
			|||||||
                          :is-active="route.params.teamID == team.id"
 | 
					                          :is-active="route.params.teamID == team.id"
 | 
				
			||||||
                          asChild
 | 
					                          asChild
 | 
				
			||||||
                        >
 | 
					                        >
 | 
				
			||||||
                          <router-link :to="{ name: 'team-inbox', params: { teamID: team.id } }">
 | 
					                          <a href="#" @click.prevent="navigateToTeamInbox(team.id)">
 | 
				
			||||||
                            {{ team.emoji }}<span>{{ team.name }}</span>
 | 
					                            {{ team.emoji }}<span>{{ team.name }}</span>
 | 
				
			||||||
                          </router-link>
 | 
					                          </a>
 | 
				
			||||||
                        </SidebarMenuButton>
 | 
					                        </SidebarMenuButton>
 | 
				
			||||||
                      </SidebarMenuSubItem>
 | 
					                      </SidebarMenuSubItem>
 | 
				
			||||||
                    </SidebarMenuSub>
 | 
					                    </SidebarMenuSub>
 | 
				
			||||||
@@ -388,18 +448,18 @@ const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
				
			|||||||
              <!-- Views -->
 | 
					              <!-- Views -->
 | 
				
			||||||
              <Collapsible class="group/collapsible" defaultOpen v-model:open="viewInboxOpen">
 | 
					              <Collapsible class="group/collapsible" defaultOpen v-model:open="viewInboxOpen">
 | 
				
			||||||
                <SidebarMenuItem>
 | 
					                <SidebarMenuItem>
 | 
				
			||||||
                  <CollapsibleTrigger as-child>
 | 
					                  <CollapsibleTrigger asChild>
 | 
				
			||||||
                    <SidebarMenuButton asChild>
 | 
					                    <SidebarMenuButton asChild>
 | 
				
			||||||
                      <router-link to="#" class="group/item">
 | 
					                      <router-link to="#" class="group/item !p-2">
 | 
				
			||||||
                        <!-- <SlidersHorizontal /> -->
 | 
					                        <!-- <SlidersHorizontal /> -->
 | 
				
			||||||
                        <span>
 | 
					                        <span>
 | 
				
			||||||
                          {{ t('navigation.views') }}
 | 
					                          {{ t('globals.terms.view', 2) }}
 | 
				
			||||||
                        </span>
 | 
					                        </span>
 | 
				
			||||||
                        <div>
 | 
					                        <div>
 | 
				
			||||||
                          <Plus
 | 
					                          <Plus
 | 
				
			||||||
                            size="18"
 | 
					                            size="18"
 | 
				
			||||||
                            @click.stop="openCreateViewDialog"
 | 
					                            @click.stop="openCreateViewDialog"
 | 
				
			||||||
                            class="rounded-lg cursor-pointer opacity-0 transition-all duration-200 group-hover/item:opacity-100 hover:bg-gray-200 hover:shadow-sm text-gray-600 hover:text-gray-800 transform hover:scale-105 active:scale-100 p-1"
 | 
					                            class="rounded cursor-pointer opacity-0 transition-all duration-200 group-hover/item:opacity-100 hover:bg-gray-200 hover:shadow-sm text-gray-600 hover:text-gray-800 transform hover:scale-105 active:scale-100 p-1"
 | 
				
			||||||
                          />
 | 
					                          />
 | 
				
			||||||
                        </div>
 | 
					                        </div>
 | 
				
			||||||
                        <ChevronRight
 | 
					                        <ChevronRight
 | 
				
			||||||
@@ -418,7 +478,7 @@ const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
				
			|||||||
                          :isActive="route.params.viewID == view.id"
 | 
					                          :isActive="route.params.viewID == view.id"
 | 
				
			||||||
                          asChild
 | 
					                          asChild
 | 
				
			||||||
                        >
 | 
					                        >
 | 
				
			||||||
                          <router-link :to="{ name: 'view-inbox', params: { viewID: view.id } }">
 | 
					                          <a href="#" @click.prevent="navigateToViewInbox(view.id)">
 | 
				
			||||||
                            <span class="break-words w-32 truncate">{{ view.name }}</span>
 | 
					                            <span class="break-words w-32 truncate">{{ view.name }}</span>
 | 
				
			||||||
                            <SidebarMenuAction :showOnHover="true" class="mr-3">
 | 
					                            <SidebarMenuAction :showOnHover="true" class="mr-3">
 | 
				
			||||||
                              <DropdownMenu>
 | 
					                              <DropdownMenu>
 | 
				
			||||||
@@ -427,15 +487,15 @@ const viewInboxOpen = useStorage('viewInboxOpen', true)
 | 
				
			|||||||
                                </DropdownMenuTrigger>
 | 
					                                </DropdownMenuTrigger>
 | 
				
			||||||
                                <DropdownMenuContent>
 | 
					                                <DropdownMenuContent>
 | 
				
			||||||
                                  <DropdownMenuItem @click="() => editView(view)">
 | 
					                                  <DropdownMenuItem @click="() => editView(view)">
 | 
				
			||||||
                                    <span>{{ t('globals.buttons.edit') }}</span>
 | 
					                                    <span>{{ t('globals.messages.edit') }}</span>
 | 
				
			||||||
                                  </DropdownMenuItem>
 | 
					                                  </DropdownMenuItem>
 | 
				
			||||||
                                  <DropdownMenuItem @click="() => deleteView(view)">
 | 
					                                  <DropdownMenuItem @click="() => deleteView(view)">
 | 
				
			||||||
                                    <span>{{ t('globals.buttons.delete') }}</span>
 | 
					                                    <span>{{ t('globals.messages.delete') }}</span>
 | 
				
			||||||
                                  </DropdownMenuItem>
 | 
					                                  </DropdownMenuItem>
 | 
				
			||||||
                                </DropdownMenuContent>
 | 
					                                </DropdownMenuContent>
 | 
				
			||||||
                              </DropdownMenu>
 | 
					                              </DropdownMenu>
 | 
				
			||||||
                            </SidebarMenuAction>
 | 
					                            </SidebarMenuAction>
 | 
				
			||||||
                          </router-link>
 | 
					                          </a>
 | 
				
			||||||
                        </SidebarMenuButton>
 | 
					                        </SidebarMenuButton>
 | 
				
			||||||
                      </SidebarMenuSubItem>
 | 
					                      </SidebarMenuSubItem>
 | 
				
			||||||
                    </SidebarMenuSub>
 | 
					                    </SidebarMenuSub>
 | 
				
			||||||
							
								
								
									
										139
									
								
								frontend/apps/main/src/components/sidebar/SidebarNavUser.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										139
									
								
								frontend/apps/main/src/components/sidebar/SidebarNavUser.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,139 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <DropdownMenu>
 | 
				
			||||||
 | 
					    <DropdownMenuTrigger as-child>
 | 
				
			||||||
 | 
					      <SidebarMenuButton
 | 
				
			||||||
 | 
					        size="md"
 | 
				
			||||||
 | 
					        class="p-0"
 | 
				
			||||||
 | 
					      >
 | 
				
			||||||
 | 
					        <Avatar class="h-8 w-8 rounded relative overflow-visible">
 | 
				
			||||||
 | 
					          <AvatarImage :src="userStore.avatar" alt="U" class="rounded" />
 | 
				
			||||||
 | 
					          <AvatarFallback class="rounded">
 | 
				
			||||||
 | 
					            {{ userStore.getInitials }}
 | 
				
			||||||
 | 
					          </AvatarFallback>
 | 
				
			||||||
 | 
					          <div
 | 
				
			||||||
 | 
					            class="absolute bottom-0 right-0 h-2.5 w-2.5 rounded-full border border-background"
 | 
				
			||||||
 | 
					            :class="{
 | 
				
			||||||
 | 
					              'bg-green-500': userStore.user.availability_status === 'online',
 | 
				
			||||||
 | 
					              'bg-amber-500':
 | 
				
			||||||
 | 
					                userStore.user.availability_status === 'away' ||
 | 
				
			||||||
 | 
					                userStore.user.availability_status === 'away_manual' ||
 | 
				
			||||||
 | 
					                userStore.user.availability_status === 'away_and_reassigning',
 | 
				
			||||||
 | 
					              'bg-gray-400': userStore.user.availability_status === 'offline'
 | 
				
			||||||
 | 
					            }"
 | 
				
			||||||
 | 
					          ></div>
 | 
				
			||||||
 | 
					        </Avatar>
 | 
				
			||||||
 | 
					        <div class="grid flex-1 text-left text-sm leading-tight">
 | 
				
			||||||
 | 
					          <span class="truncate font-semibold">{{ userStore.getFullName }}</span>
 | 
				
			||||||
 | 
					          <span class="truncate text-xs">{{ userStore.email }}</span>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <ChevronsUpDown class="ml-auto size-4" />
 | 
				
			||||||
 | 
					      </SidebarMenuButton>
 | 
				
			||||||
 | 
					    </DropdownMenuTrigger>
 | 
				
			||||||
 | 
					    <DropdownMenuContent
 | 
				
			||||||
 | 
					      class="w-[--radix-dropdown-menu-trigger-width] min-w-56"
 | 
				
			||||||
 | 
					      side="bottom"
 | 
				
			||||||
 | 
					      :side-offset="4"
 | 
				
			||||||
 | 
					    >
 | 
				
			||||||
 | 
					      <DropdownMenuLabel class="font-normal space-y-2 px-2">
 | 
				
			||||||
 | 
					        <!-- User header -->
 | 
				
			||||||
 | 
					        <div class="flex items-center gap-2 py-1.5 text-left text-sm">
 | 
				
			||||||
 | 
					          <Avatar class="h-8 w-8 rounded">
 | 
				
			||||||
 | 
					            <AvatarImage :src="userStore.avatar" alt="U" />
 | 
				
			||||||
 | 
					            <AvatarFallback class="rounded">
 | 
				
			||||||
 | 
					              {{ userStore.getInitials }}
 | 
				
			||||||
 | 
					            </AvatarFallback>
 | 
				
			||||||
 | 
					          </Avatar>
 | 
				
			||||||
 | 
					          <div class="flex-1 flex flex-col leading-tight">
 | 
				
			||||||
 | 
					            <span class="truncate font-semibold">{{ userStore.getFullName }}</span>
 | 
				
			||||||
 | 
					            <span class="truncate text-xs text-muted-foreground">{{ userStore.email }}</span>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <div class="space-y-2">
 | 
				
			||||||
 | 
					          <!-- Dark-mode toggle -->
 | 
				
			||||||
 | 
					          <div class="flex items-center justify-between text-sm">
 | 
				
			||||||
 | 
					            <div class="flex items-center gap-2">
 | 
				
			||||||
 | 
					              <Moon v-if="mode === 'dark'" size="16" class="text-muted-foreground" />
 | 
				
			||||||
 | 
					              <Sun v-else size="16" class="text-muted-foreground" />
 | 
				
			||||||
 | 
					              <span class="text-muted-foreground">{{ t('navigation.darkMode') }}</span>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <Switch
 | 
				
			||||||
 | 
					              :checked="mode === 'dark'"
 | 
				
			||||||
 | 
					              @update:checked="(val) => (mode = val ? 'dark' : 'light')"
 | 
				
			||||||
 | 
					            />
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          <div class="border-t border-gray-200 dark:border-gray-700 pt-3 space-y-3">
 | 
				
			||||||
 | 
					            <!-- Away toggle -->
 | 
				
			||||||
 | 
					            <div class="flex items-center justify-between text-sm">
 | 
				
			||||||
 | 
					              <span class="text-muted-foreground">{{ t('navigation.away') }}</span>
 | 
				
			||||||
 | 
					              <Switch
 | 
				
			||||||
 | 
					                :checked="
 | 
				
			||||||
 | 
					                  ['away_manual', 'away_and_reassigning'].includes(
 | 
				
			||||||
 | 
					                    userStore.user.availability_status
 | 
				
			||||||
 | 
					                  )
 | 
				
			||||||
 | 
					                "
 | 
				
			||||||
 | 
					                @update:checked="
 | 
				
			||||||
 | 
					                  (val) => userStore.updateUserAvailability(val ? 'away_manual' : 'online')
 | 
				
			||||||
 | 
					                "
 | 
				
			||||||
 | 
					              />
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <!-- Reassign toggle -->
 | 
				
			||||||
 | 
					            <div class="flex items-center justify-between text-sm">
 | 
				
			||||||
 | 
					              <span class="text-muted-foreground">{{ t('navigation.reassignReplies') }}</span>
 | 
				
			||||||
 | 
					              <Switch
 | 
				
			||||||
 | 
					                :checked="userStore.user.availability_status === 'away_and_reassigning'"
 | 
				
			||||||
 | 
					                @update:checked="
 | 
				
			||||||
 | 
					                  (val) =>
 | 
				
			||||||
 | 
					                    userStore.updateUserAvailability(val ? 'away_and_reassigning' : 'away_manual')
 | 
				
			||||||
 | 
					                "
 | 
				
			||||||
 | 
					              />
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					      </DropdownMenuLabel>
 | 
				
			||||||
 | 
					      <DropdownMenuSeparator />
 | 
				
			||||||
 | 
					      <DropdownMenuGroup>
 | 
				
			||||||
 | 
					        <DropdownMenuItem @click.prevent="router.push({ name: 'account' })">
 | 
				
			||||||
 | 
					          <CircleUserRound size="18" class="mr-2" />
 | 
				
			||||||
 | 
					          {{ t('globals.terms.account') }}
 | 
				
			||||||
 | 
					        </DropdownMenuItem>
 | 
				
			||||||
 | 
					      </DropdownMenuGroup>
 | 
				
			||||||
 | 
					      <DropdownMenuSeparator />
 | 
				
			||||||
 | 
					      <DropdownMenuItem @click="logout">
 | 
				
			||||||
 | 
					        <LogOut size="18" class="mr-2" />
 | 
				
			||||||
 | 
					        {{ t('navigation.logout') }}
 | 
				
			||||||
 | 
					      </DropdownMenuItem>
 | 
				
			||||||
 | 
					    </DropdownMenuContent>
 | 
				
			||||||
 | 
					  </DropdownMenu>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script setup>
 | 
				
			||||||
 | 
					import { useI18n } from 'vue-i18n'
 | 
				
			||||||
 | 
					import {
 | 
				
			||||||
 | 
					  DropdownMenu,
 | 
				
			||||||
 | 
					  DropdownMenuContent,
 | 
				
			||||||
 | 
					  DropdownMenuGroup,
 | 
				
			||||||
 | 
					  DropdownMenuItem,
 | 
				
			||||||
 | 
					  DropdownMenuLabel,
 | 
				
			||||||
 | 
					  DropdownMenuSeparator,
 | 
				
			||||||
 | 
					  DropdownMenuTrigger
 | 
				
			||||||
 | 
					} from '@shared-ui/components/ui/dropdown-menu'
 | 
				
			||||||
 | 
					import { SidebarMenuButton } from '@shared-ui/components/ui/sidebar'
 | 
				
			||||||
 | 
					import { Avatar, AvatarFallback, AvatarImage } from '@shared-ui/components/ui/avatar'
 | 
				
			||||||
 | 
					import { Switch } from '@shared-ui/components/ui/switch'
 | 
				
			||||||
 | 
					import { ChevronsUpDown, CircleUserRound, LogOut, Moon, Sun } from 'lucide-vue-next'
 | 
				
			||||||
 | 
					import { useUserStore } from '../../stores/user'
 | 
				
			||||||
 | 
					import { useRouter } from 'vue-router'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { useColorMode } from '@vueuse/core'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const mode = useColorMode()
 | 
				
			||||||
 | 
					const userStore = useUserStore()
 | 
				
			||||||
 | 
					const router = useRouter()
 | 
				
			||||||
 | 
					const { t } = useI18n()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const logout = () => {
 | 
				
			||||||
 | 
					  window.location.href = '/logout'
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
							
								
								
									
										112
									
								
								frontend/apps/main/src/components/table/SimpleTable.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										112
									
								
								frontend/apps/main/src/components/table/SimpleTable.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,112 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <table class="min-w-full table-fixed divide-y divide-border">
 | 
				
			||||||
 | 
					    <thead class="bg-muted">
 | 
				
			||||||
 | 
					      <tr>
 | 
				
			||||||
 | 
					        <th
 | 
				
			||||||
 | 
					          v-for="(header, index) in headers"
 | 
				
			||||||
 | 
					          :key="index"
 | 
				
			||||||
 | 
					          scope="col"
 | 
				
			||||||
 | 
					          class="px-6 py-3 text-left text-xs font-medium text-muted-foreground uppercase tracking-wider"
 | 
				
			||||||
 | 
					        >
 | 
				
			||||||
 | 
					          {{ header }}
 | 
				
			||||||
 | 
					        </th>
 | 
				
			||||||
 | 
					        <th v-if="showDelete" scope="col" class="relative px-6 py-3"></th>
 | 
				
			||||||
 | 
					      </tr>
 | 
				
			||||||
 | 
					    </thead>
 | 
				
			||||||
 | 
					    <tbody class="bg-background divide-y divide-border">
 | 
				
			||||||
 | 
					      <!-- Loading State -->
 | 
				
			||||||
 | 
					      <template v-if="loading">
 | 
				
			||||||
 | 
					        <tr v-for="i in skeletonRows" :key="`skeleton-${i}`" class="hover:bg-accent">
 | 
				
			||||||
 | 
					          <td
 | 
				
			||||||
 | 
					            v-for="(header, index) in headers"
 | 
				
			||||||
 | 
					            :key="`skeleton-cell-${index}`"
 | 
				
			||||||
 | 
					            class="px-6 py-3 text-sm font-medium text-foreground whitespace-normal break-words"
 | 
				
			||||||
 | 
					          >
 | 
				
			||||||
 | 
					            <Skeleton class="h-4 w-[85%]" />
 | 
				
			||||||
 | 
					          </td>
 | 
				
			||||||
 | 
					          <td v-if="showDelete" class="px-6 py-4 text-sm text-muted-foreground">
 | 
				
			||||||
 | 
					            <Skeleton class="h-8 w-8 rounded" />
 | 
				
			||||||
 | 
					          </td>
 | 
				
			||||||
 | 
					        </tr>
 | 
				
			||||||
 | 
					      </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <!-- No Results State -->
 | 
				
			||||||
 | 
					      <template v-else-if="data.length === 0">
 | 
				
			||||||
 | 
					        <tr>
 | 
				
			||||||
 | 
					          <td :colspan="headers.length + (showDelete ? 1 : 0)" class="px-6 py-12 text-center">
 | 
				
			||||||
 | 
					            <div class="flex flex-col items-center space-y-4">
 | 
				
			||||||
 | 
					              <span class="text-md text-muted-foreground">
 | 
				
			||||||
 | 
					                {{
 | 
				
			||||||
 | 
					                  $t('globals.messages.noResults', {
 | 
				
			||||||
 | 
					                    name: $t('globals.terms.result', 2).toLowerCase()
 | 
				
			||||||
 | 
					                  })
 | 
				
			||||||
 | 
					                }}
 | 
				
			||||||
 | 
					              </span>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					          </td>
 | 
				
			||||||
 | 
					        </tr>
 | 
				
			||||||
 | 
					      </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <!-- Data Rows -->
 | 
				
			||||||
 | 
					      <template v-else>
 | 
				
			||||||
 | 
					        <tr v-for="(item, index) in data" :key="index" class="hover:bg-accent">
 | 
				
			||||||
 | 
					          <td
 | 
				
			||||||
 | 
					            v-for="key in keys"
 | 
				
			||||||
 | 
					            :key="key"
 | 
				
			||||||
 | 
					            class="px-6 py-4 text-sm font-medium text-foreground whitespace-normal break-words"
 | 
				
			||||||
 | 
					          >
 | 
				
			||||||
 | 
					            {{ item[key] }}
 | 
				
			||||||
 | 
					          </td>
 | 
				
			||||||
 | 
					          <td v-if="showDelete" class="px-6 py-4 text-sm text-muted-foreground">
 | 
				
			||||||
 | 
					            <Button size="xs" variant="ghost" @click.prevent="deleteItem(item)">
 | 
				
			||||||
 | 
					              <Trash2 class="h-4 w-4" />
 | 
				
			||||||
 | 
					            </Button>
 | 
				
			||||||
 | 
					          </td>
 | 
				
			||||||
 | 
					        </tr>
 | 
				
			||||||
 | 
					      </template>
 | 
				
			||||||
 | 
					    </tbody>
 | 
				
			||||||
 | 
					  </table>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script setup>
 | 
				
			||||||
 | 
					import { Trash2 } from 'lucide-vue-next'
 | 
				
			||||||
 | 
					import { defineEmits } from 'vue'
 | 
				
			||||||
 | 
					import { Button } from '@shared-ui/components/ui/button'
 | 
				
			||||||
 | 
					import { Skeleton } from '@shared-ui/components/ui/skeleton'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					defineProps({
 | 
				
			||||||
 | 
					  headers: {
 | 
				
			||||||
 | 
					    type: Array,
 | 
				
			||||||
 | 
					    required: true,
 | 
				
			||||||
 | 
					    default: () => []
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  keys: {
 | 
				
			||||||
 | 
					    type: Array,
 | 
				
			||||||
 | 
					    required: true,
 | 
				
			||||||
 | 
					    default: () => []
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  data: {
 | 
				
			||||||
 | 
					    type: Array,
 | 
				
			||||||
 | 
					    required: true,
 | 
				
			||||||
 | 
					    default: () => []
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  showDelete: {
 | 
				
			||||||
 | 
					    type: Boolean,
 | 
				
			||||||
 | 
					    default: true
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  loading: {
 | 
				
			||||||
 | 
					    type: Boolean,
 | 
				
			||||||
 | 
					    default: false
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  skeletonRows: {
 | 
				
			||||||
 | 
					    type: Number,
 | 
				
			||||||
 | 
					    default: 5
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const emit = defineEmits(['deleteItem'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function deleteItem(item) {
 | 
				
			||||||
 | 
					  emit('deleteItem', item)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
@@ -20,6 +20,6 @@
 | 
				
			|||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script setup>
 | 
					<script setup>
 | 
				
			||||||
import { useAppSettingsStore } from '@/stores/appSettings'
 | 
					import { useAppSettingsStore } from '../../stores/appSettings'
 | 
				
			||||||
const appSettingsStore = useAppSettingsStore()
 | 
					const appSettingsStore = useAppSettingsStore()
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
@@ -1,18 +1,22 @@
 | 
				
			|||||||
import { computed } from 'vue'
 | 
					import { computed } from 'vue'
 | 
				
			||||||
import { useUsersStore } from '@/stores/users'
 | 
					import { useUsersStore } from '../stores/users'
 | 
				
			||||||
import { FIELD_TYPE, FIELD_OPERATORS } from '@/constants/filterConfig'
 | 
					import { FIELD_TYPE, FIELD_OPERATORS } from '../constants/filterConfig'
 | 
				
			||||||
 | 
					import { useI18n } from 'vue-i18n'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function useActivityLogFilters () {
 | 
					export function useActivityLogFilters () {
 | 
				
			||||||
    const uStore = useUsersStore()
 | 
					    const uStore = useUsersStore()
 | 
				
			||||||
 | 
					    const { t } = useI18n()
 | 
				
			||||||
    const activityLogListFilters = computed(() => ({
 | 
					    const activityLogListFilters = computed(() => ({
 | 
				
			||||||
        actor_id: {
 | 
					        actor_id: {
 | 
				
			||||||
            label: 'Actor',
 | 
					            label: t('globals.terms.actor'),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: uStore.options
 | 
					            options: uStore.options
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        activity_type: {
 | 
					        activity_type: {
 | 
				
			||||||
            label: 'Activity type',
 | 
					            label: t('globals.messages.type', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.activityLog')
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: [{
 | 
					            options: [{
 | 
				
			||||||
@@ -1,11 +1,12 @@
 | 
				
			|||||||
import { computed } from 'vue'
 | 
					import { computed } from 'vue'
 | 
				
			||||||
import { useConversationStore } from '@/stores/conversation'
 | 
					import { useConversationStore } from '../stores/conversation'
 | 
				
			||||||
import { useInboxStore } from '@/stores/inbox'
 | 
					import { useInboxStore } from '../stores/inbox'
 | 
				
			||||||
import { useUsersStore } from '@/stores/users'
 | 
					import { useUsersStore } from '../stores/users'
 | 
				
			||||||
import { useTeamStore } from '@/stores/team'
 | 
					import { useTeamStore } from '../stores/team'
 | 
				
			||||||
import { useSlaStore } from '@/stores/sla'
 | 
					import { useSlaStore } from '../stores/sla'
 | 
				
			||||||
import { useCustomAttributeStore } from '@/stores/customAttributes'
 | 
					import { useCustomAttributeStore } from '../stores/customAttributes'
 | 
				
			||||||
import { FIELD_TYPE, FIELD_OPERATORS } from '@/constants/filterConfig'
 | 
					import { FIELD_TYPE, FIELD_OPERATORS } from '../constants/filterConfig'
 | 
				
			||||||
 | 
					import { useI18n } from 'vue-i18n'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function useConversationFilters () {
 | 
					export function useConversationFilters () {
 | 
				
			||||||
    const cStore = useConversationStore()
 | 
					    const cStore = useConversationStore()
 | 
				
			||||||
@@ -14,6 +15,7 @@ export function useConversationFilters () {
 | 
				
			|||||||
    const tStore = useTeamStore()
 | 
					    const tStore = useTeamStore()
 | 
				
			||||||
    const slaStore = useSlaStore()
 | 
					    const slaStore = useSlaStore()
 | 
				
			||||||
    const customAttributeStore = useCustomAttributeStore()
 | 
					    const customAttributeStore = useCustomAttributeStore()
 | 
				
			||||||
 | 
					    const { t } = useI18n()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const customAttributeDataTypeToFieldType = {
 | 
					    const customAttributeDataTypeToFieldType = {
 | 
				
			||||||
        'text': FIELD_TYPE.TEXT,
 | 
					        'text': FIELD_TYPE.TEXT,
 | 
				
			||||||
@@ -35,31 +37,35 @@ export function useConversationFilters () {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const conversationsListFilters = computed(() => ({
 | 
					    const conversationsListFilters = computed(() => ({
 | 
				
			||||||
        status_id: {
 | 
					        status_id: {
 | 
				
			||||||
            label: 'Status',
 | 
					            label: t('globals.terms.status'),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: cStore.statusOptions
 | 
					            options: cStore.statusOptions
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        priority_id: {
 | 
					        priority_id: {
 | 
				
			||||||
            label: 'Priority',
 | 
					            label: t('globals.terms.priority'),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: cStore.priorityOptions
 | 
					            options: cStore.priorityOptions
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        assigned_team_id: {
 | 
					        assigned_team_id: {
 | 
				
			||||||
            label: 'Assigned team',
 | 
					            label: t('globals.messages.assign', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.team').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: tStore.options
 | 
					            options: tStore.options
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        assigned_user_id: {
 | 
					        assigned_user_id: {
 | 
				
			||||||
            label: 'Assigned user',
 | 
					            label: t('globals.messages.assign', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.agent').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: uStore.options
 | 
					            options: uStore.options
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        inbox_id: {
 | 
					        inbox_id: {
 | 
				
			||||||
            label: 'Inbox',
 | 
					            label: t('globals.terms.inbox'),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: iStore.options
 | 
					            options: iStore.options
 | 
				
			||||||
@@ -85,46 +91,50 @@ export function useConversationFilters () {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const newConversationFilters = computed(() => ({
 | 
					    const newConversationFilters = computed(() => ({
 | 
				
			||||||
        contact_email: {
 | 
					        contact_email: {
 | 
				
			||||||
            label: 'Email',
 | 
					            label: t('globals.terms.email'),
 | 
				
			||||||
            type: FIELD_TYPE.TEXT,
 | 
					            type: FIELD_TYPE.TEXT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.TEXT
 | 
					            operators: FIELD_OPERATORS.TEXT
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        content: {
 | 
					        content: {
 | 
				
			||||||
            label: 'Content',
 | 
					            label: t('globals.terms.content'),
 | 
				
			||||||
            type: FIELD_TYPE.TEXT,
 | 
					            type: FIELD_TYPE.TEXT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.TEXT
 | 
					            operators: FIELD_OPERATORS.TEXT
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        subject: {
 | 
					        subject: {
 | 
				
			||||||
            label: 'Subject',
 | 
					            label: t('globals.terms.subject'),
 | 
				
			||||||
            type: FIELD_TYPE.TEXT,
 | 
					            type: FIELD_TYPE.TEXT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.TEXT
 | 
					            operators: FIELD_OPERATORS.TEXT
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        status: {
 | 
					        status: {
 | 
				
			||||||
            label: 'Status',
 | 
					            label: t('globals.terms.status'),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: cStore.statusOptions
 | 
					            options: cStore.statusOptions
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        priority: {
 | 
					        priority: {
 | 
				
			||||||
            label: 'Priority',
 | 
					            label: t('globals.terms.priority'),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: cStore.priorityOptions
 | 
					            options: cStore.priorityOptions
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        assigned_team: {
 | 
					        assigned_team: {
 | 
				
			||||||
            label: 'Assigned team',
 | 
					            label: t('globals.messages.assign', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.team').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: tStore.options
 | 
					            options: tStore.options
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        assigned_user: {
 | 
					        assigned_user: {
 | 
				
			||||||
            label: 'Assigned agent',
 | 
					            label: t('globals.messages.assign', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.agent').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: uStore.options
 | 
					            options: uStore.options
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        inbox: {
 | 
					        inbox: {
 | 
				
			||||||
            label: 'Inbox',
 | 
					            label: t('globals.terms.inbox'),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: iStore.options
 | 
					            options: iStore.options
 | 
				
			||||||
@@ -133,51 +143,55 @@ export function useConversationFilters () {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const conversationFilters = computed(() => ({
 | 
					    const conversationFilters = computed(() => ({
 | 
				
			||||||
        status: {
 | 
					        status: {
 | 
				
			||||||
            label: 'Status',
 | 
					            label: t('globals.terms.status'),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: cStore.statusOptions
 | 
					            options: cStore.statusOptions
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        priority: {
 | 
					        priority: {
 | 
				
			||||||
            label: 'Priority',
 | 
					            label: t('globals.terms.priority'),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: cStore.priorityOptions
 | 
					            options: cStore.priorityOptions
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        assigned_team: {
 | 
					        assigned_team: {
 | 
				
			||||||
            label: 'Assigned team',
 | 
					            label: t('globals.messages.assign', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.team').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: tStore.options
 | 
					            options: tStore.options
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        assigned_user: {
 | 
					        assigned_user: {
 | 
				
			||||||
            label: 'Assigned agent',
 | 
					            label: t('globals.messages.assign', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.agent').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: uStore.options
 | 
					            options: uStore.options
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        hours_since_created: {
 | 
					        hours_since_created: {
 | 
				
			||||||
            label: 'Hours since created',
 | 
					            label: t('globals.messages.hoursSinceCreated'),
 | 
				
			||||||
            type: FIELD_TYPE.NUMBER,
 | 
					            type: FIELD_TYPE.NUMBER,
 | 
				
			||||||
            operators: FIELD_OPERATORS.NUMBER
 | 
					            operators: FIELD_OPERATORS.NUMBER
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        hours_since_first_reply: {
 | 
					        hours_since_first_reply: {
 | 
				
			||||||
            label: 'Hours since first reply',
 | 
					            label: t('globals.messages.hoursSinceFirstReply'),
 | 
				
			||||||
            type: FIELD_TYPE.NUMBER,
 | 
					            type: FIELD_TYPE.NUMBER,
 | 
				
			||||||
            operators: FIELD_OPERATORS.NUMBER
 | 
					            operators: FIELD_OPERATORS.NUMBER
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        hours_since_last_reply: {
 | 
					        hours_since_last_reply: {
 | 
				
			||||||
            label: 'Hours since last reply',
 | 
					            label: t('globals.messages.hoursSinceLastReply'),
 | 
				
			||||||
            type: FIELD_TYPE.NUMBER,
 | 
					            type: FIELD_TYPE.NUMBER,
 | 
				
			||||||
            operators: FIELD_OPERATORS.NUMBER
 | 
					            operators: FIELD_OPERATORS.NUMBER
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        hours_since_resolved: {
 | 
					        hours_since_resolved: {
 | 
				
			||||||
            label: 'Hours since resolved',
 | 
					            label: t('globals.messages.hoursSinceResolved'),
 | 
				
			||||||
            type: FIELD_TYPE.NUMBER,
 | 
					            type: FIELD_TYPE.NUMBER,
 | 
				
			||||||
            operators: FIELD_OPERATORS.NUMBER
 | 
					            operators: FIELD_OPERATORS.NUMBER
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        inbox: {
 | 
					        inbox: {
 | 
				
			||||||
            label: 'Inbox',
 | 
					            label: t('globals.terms.inbox'),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            operators: FIELD_OPERATORS.SELECT,
 | 
					            operators: FIELD_OPERATORS.SELECT,
 | 
				
			||||||
            options: iStore.options
 | 
					            options: iStore.options
 | 
				
			||||||
@@ -186,86 +200,122 @@ export function useConversationFilters () {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const conversationActions = computed(() => ({
 | 
					    const conversationActions = computed(() => ({
 | 
				
			||||||
        assign_team: {
 | 
					        assign_team: {
 | 
				
			||||||
            label: 'Assign to team',
 | 
					            label: t('globals.messages.assign', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.team').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            options: tStore.options
 | 
					            options: tStore.options
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        assign_user: {
 | 
					        assign_user: {
 | 
				
			||||||
            label: 'Assign to user',
 | 
					            label: t('globals.messages.assign', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.agent').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            options: uStore.options
 | 
					            options: uStore.options
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        set_status: {
 | 
					        set_status: {
 | 
				
			||||||
            label: 'Set status',
 | 
					            label: t('globals.messages.set', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.status').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            options: cStore.statusOptionsNoSnooze
 | 
					            options: cStore.statusOptionsNoSnooze
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        set_priority: {
 | 
					        set_priority: {
 | 
				
			||||||
            label: 'Set priority',
 | 
					            label: t('globals.messages.set', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.priority').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            options: cStore.priorityOptions
 | 
					            options: cStore.priorityOptions
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        send_private_note: {
 | 
					        send_private_note: {
 | 
				
			||||||
            label: 'Send private note',
 | 
					            label: t('globals.messages.send', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.privateNote').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.RICHTEXT
 | 
					            type: FIELD_TYPE.RICHTEXT
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        send_reply: {
 | 
					        send_reply: {
 | 
				
			||||||
            label: 'Send reply',
 | 
					            label: t('globals.messages.send', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.reply').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.RICHTEXT
 | 
					            type: FIELD_TYPE.RICHTEXT
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        send_csat: {
 | 
					        send_csat: {
 | 
				
			||||||
            label: 'Send CSAT',
 | 
					            label: t('globals.messages.send', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.csat').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        set_sla: {
 | 
					        set_sla: {
 | 
				
			||||||
            label: 'Set SLA',
 | 
					            label: t('globals.messages.set', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.sla').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            options: slaStore.options
 | 
					            options: slaStore.options
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        add_tags: {
 | 
					        add_tags: {
 | 
				
			||||||
            label: 'Add tags',
 | 
					            label: t('globals.messages.add', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.tag', 2).toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.TAG
 | 
					            type: FIELD_TYPE.TAG
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        set_tags: {
 | 
					        set_tags: {
 | 
				
			||||||
            label: 'Set tags',
 | 
					            label: t('globals.messages.set', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.tag', 2).toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.TAG
 | 
					            type: FIELD_TYPE.TAG
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        remove_tags: {
 | 
					        remove_tags: {
 | 
				
			||||||
            label: 'Remove tags',
 | 
					            label: t('globals.messages.remove', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.tag', 2).toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.TAG
 | 
					            type: FIELD_TYPE.TAG
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }))
 | 
					    }))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const macroActions = computed(() => ({
 | 
					    const macroActions = computed(() => ({
 | 
				
			||||||
        assign_team: {
 | 
					        assign_team: {
 | 
				
			||||||
            label: 'Assign to team',
 | 
					            label: t('globals.messages.assign', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.team').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            options: tStore.options
 | 
					            options: tStore.options
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        assign_user: {
 | 
					        assign_user: {
 | 
				
			||||||
            label: 'Assign to user',
 | 
					            label: t('globals.messages.assign', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.agent').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            options: uStore.options
 | 
					            options: uStore.options
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        set_status: {
 | 
					        set_status: {
 | 
				
			||||||
            label: 'Set status',
 | 
					            label: t('globals.messages.set', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.status').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            options: cStore.statusOptionsNoSnooze
 | 
					            options: cStore.statusOptionsNoSnooze
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        set_priority: {
 | 
					        set_priority: {
 | 
				
			||||||
            label: 'Set priority',
 | 
					            label: t('globals.messages.set', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.priority').toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.SELECT,
 | 
					            type: FIELD_TYPE.SELECT,
 | 
				
			||||||
            options: cStore.priorityOptions
 | 
					            options: cStore.priorityOptions
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        add_tags: {
 | 
					        add_tags: {
 | 
				
			||||||
            label: 'Add tags',
 | 
					            label: t('globals.messages.add', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.tag', 2).toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.TAG
 | 
					            type: FIELD_TYPE.TAG
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        set_tags: {
 | 
					        set_tags: {
 | 
				
			||||||
            label: 'Set tags',
 | 
					            label: t('globals.messages.set', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.tag', 2).toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.TAG
 | 
					            type: FIELD_TYPE.TAG
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        remove_tags: {
 | 
					        remove_tags: {
 | 
				
			||||||
            label: 'Remove tags',
 | 
					            label: t('globals.messages.remove', {
 | 
				
			||||||
 | 
					                name: t('globals.terms.tag', 2).toLowerCase()
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
            type: FIELD_TYPE.TAG
 | 
					            type: FIELD_TYPE.TAG
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }))
 | 
					    }))
 | 
				
			||||||
							
								
								
									
										142
									
								
								frontend/apps/main/src/composables/useFileUpload.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										142
									
								
								frontend/apps/main/src/composables/useFileUpload.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,142 @@
 | 
				
			|||||||
 | 
					import { ref, readonly } from 'vue'
 | 
				
			||||||
 | 
					import { useEmitter } from './useEmitter'
 | 
				
			||||||
 | 
					import { EMITTER_EVENTS } from '../constants/emitterEvents.js'
 | 
				
			||||||
 | 
					import { handleHTTPError } from '../utils/http'
 | 
				
			||||||
 | 
					import api from '../api'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Composable for handling file uploads
 | 
				
			||||||
 | 
					 * @param {Object} options - Configuration options
 | 
				
			||||||
 | 
					 * @param {Function} options.onFileUploadSuccess - Callback when file upload succeeds (uploadedFile)
 | 
				
			||||||
 | 
					 * @param {Function} options.onUploadError - Optional callback when file upload fails (file, error)
 | 
				
			||||||
 | 
					 * @param {string} options.linkedModel - The linked model for the upload
 | 
				
			||||||
 | 
					 * @param {Array} options.mediaFiles - Optional external array to manage files (if not provided, internal array is used)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export function useFileUpload (options = {}) {
 | 
				
			||||||
 | 
					    const {
 | 
				
			||||||
 | 
					        onFileUploadSuccess,
 | 
				
			||||||
 | 
					        onUploadError,
 | 
				
			||||||
 | 
					        linkedModel,
 | 
				
			||||||
 | 
					        mediaFiles: externalMediaFiles
 | 
				
			||||||
 | 
					    } = options
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const emitter = useEmitter()
 | 
				
			||||||
 | 
					    const uploadingFiles = ref([])
 | 
				
			||||||
 | 
					    const isUploading = ref(false)
 | 
				
			||||||
 | 
					    const internalMediaFiles = ref([])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Use external mediaFiles if provided, otherwise use internal
 | 
				
			||||||
 | 
					    const mediaFiles = externalMediaFiles || internalMediaFiles
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Handles the file upload process when files are selected.
 | 
				
			||||||
 | 
					     * Uploads each file to the server and adds them to the mediaFiles array.
 | 
				
			||||||
 | 
					     * @param {Event} event - The file input change event containing selected files
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    const handleFileUpload = (event) => {
 | 
				
			||||||
 | 
					        const files = Array.from(event.target.files)
 | 
				
			||||||
 | 
					        uploadingFiles.value = files
 | 
				
			||||||
 | 
					        isUploading.value = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (const file of files) {
 | 
				
			||||||
 | 
					            api
 | 
				
			||||||
 | 
					                .uploadMedia({
 | 
				
			||||||
 | 
					                    files: file,
 | 
				
			||||||
 | 
					                    inline: false,
 | 
				
			||||||
 | 
					                    linked_model: linkedModel
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					                .then((resp) => {
 | 
				
			||||||
 | 
					                    const uploadedFile = resp.data.data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    // Add to media files array
 | 
				
			||||||
 | 
					                    if (Array.isArray(mediaFiles.value)) {
 | 
				
			||||||
 | 
					                        mediaFiles.value.push(uploadedFile)
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        mediaFiles.push(uploadedFile)
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    // Remove from uploading list
 | 
				
			||||||
 | 
					                    uploadingFiles.value = uploadingFiles.value.filter((f) => f.name !== file.name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    // Call success callback
 | 
				
			||||||
 | 
					                    if (onFileUploadSuccess) {
 | 
				
			||||||
 | 
					                        onFileUploadSuccess(uploadedFile)
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    // Update uploading state
 | 
				
			||||||
 | 
					                    if (uploadingFiles.value.length === 0) {
 | 
				
			||||||
 | 
					                        isUploading.value = false
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					                .catch((error) => {
 | 
				
			||||||
 | 
					                    uploadingFiles.value = uploadingFiles.value.filter((f) => f.name !== file.name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    // Call error callback or show default toast
 | 
				
			||||||
 | 
					                    if (onUploadError) {
 | 
				
			||||||
 | 
					                        onUploadError(file, error)
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        emitter.emit(EMITTER_EVENTS.SHOW_TOAST, {
 | 
				
			||||||
 | 
					                            variant: 'destructive',
 | 
				
			||||||
 | 
					                            description: handleHTTPError(error).message
 | 
				
			||||||
 | 
					                        })
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    // Update uploading state
 | 
				
			||||||
 | 
					                    if (uploadingFiles.value.length === 0) {
 | 
				
			||||||
 | 
					                        isUploading.value = false
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Handles the file delete event.
 | 
				
			||||||
 | 
					     * Removes the file from the mediaFiles array.
 | 
				
			||||||
 | 
					     * @param {String} uuid - The UUID of the file to delete
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    const handleFileDelete = (uuid) => {
 | 
				
			||||||
 | 
					        if (Array.isArray(mediaFiles.value)) {
 | 
				
			||||||
 | 
					            mediaFiles.value = [
 | 
				
			||||||
 | 
					                ...mediaFiles.value.filter((item) => item.uuid !== uuid)
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            const index = mediaFiles.findIndex((item) => item.uuid === uuid)
 | 
				
			||||||
 | 
					            if (index > -1) {
 | 
				
			||||||
 | 
					                mediaFiles.splice(index, 1)
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Upload files programmatically (without event)
 | 
				
			||||||
 | 
					     * @param {File[]} files - Array of files to upload
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    const uploadFiles = (files) => {
 | 
				
			||||||
 | 
					        const mockEvent = { target: { files } }
 | 
				
			||||||
 | 
					        handleFileUpload(mockEvent)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Clear all media files
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    const clearMediaFiles = () => {
 | 
				
			||||||
 | 
					        if (Array.isArray(mediaFiles.value)) {
 | 
				
			||||||
 | 
					            mediaFiles.value = []
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            mediaFiles.length = 0
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					        // State
 | 
				
			||||||
 | 
					        uploadingFiles: readonly(uploadingFiles),
 | 
				
			||||||
 | 
					        isUploading: readonly(isUploading),
 | 
				
			||||||
 | 
					        mediaFiles: externalMediaFiles ? readonly(mediaFiles) : readonly(internalMediaFiles),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Methods
 | 
				
			||||||
 | 
					        handleFileUpload,
 | 
				
			||||||
 | 
					        handleFileDelete,
 | 
				
			||||||
 | 
					        uploadFiles,
 | 
				
			||||||
 | 
					        clearMediaFiles
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
import { ref, onMounted, onBeforeUnmount, watch } from 'vue'
 | 
					import { ref, onMounted, onBeforeUnmount, watch } from 'vue'
 | 
				
			||||||
import { useUserStore } from '@/stores/user'
 | 
					import { useUserStore } from '../stores/user'
 | 
				
			||||||
import { debounce } from '@/utils/debounce'
 | 
					import { debounce } from '../utils/debounce'
 | 
				
			||||||
import { useStorage } from '@vueuse/core'
 | 
					import { useStorage } from '@vueuse/core'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function useIdleDetection () {
 | 
					export function useIdleDetection () {
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
import { ref, onMounted, onUnmounted } from 'vue'
 | 
					import { ref, onMounted, onUnmounted } from 'vue'
 | 
				
			||||||
import { calculateSla } from '@/utils/sla'
 | 
					import { calculateSla } from '../utils/sla'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function useSla (dueAt, actualAt) {
 | 
					export function useSla (dueAt, actualAt) {
 | 
				
			||||||
    const sla = ref(null)
 | 
					    const sla = ref(null)
 | 
				
			||||||
							
								
								
									
										187
									
								
								frontend/apps/main/src/constants/navigation.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										187
									
								
								frontend/apps/main/src/constants/navigation.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,187 @@
 | 
				
			|||||||
 | 
					export const reportsNavItems = [
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.overview',
 | 
				
			||||||
 | 
					    href: '/reports/overview',
 | 
				
			||||||
 | 
					    permission: 'reports:manage'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const adminNavItems = [
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.workspace',
 | 
				
			||||||
 | 
					    children: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.general',
 | 
				
			||||||
 | 
					        href: '/admin/general',
 | 
				
			||||||
 | 
					        permission: 'general_settings:manage'
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.businessHour',
 | 
				
			||||||
 | 
					        href: '/admin/business-hours',
 | 
				
			||||||
 | 
					        permission: 'business_hours:manage'
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.slaPolicy',
 | 
				
			||||||
 | 
					        href: '/admin/sla',
 | 
				
			||||||
 | 
					        permission: 'sla:manage'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.conversation',
 | 
				
			||||||
 | 
					    children: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.tag',
 | 
				
			||||||
 | 
					        href: '/admin/conversations/tags',
 | 
				
			||||||
 | 
					        permission: 'tags:manage'
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.macro',
 | 
				
			||||||
 | 
					        href: '/admin/conversations/macros',
 | 
				
			||||||
 | 
					        permission: 'macros:manage'
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.status',
 | 
				
			||||||
 | 
					        href: '/admin/conversations/statuses',
 | 
				
			||||||
 | 
					        permission: 'status:manage'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.inbox',
 | 
				
			||||||
 | 
					    children: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.inbox',
 | 
				
			||||||
 | 
					        href: '/admin/inboxes',
 | 
				
			||||||
 | 
					        permission: 'inboxes:manage'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.teammate',
 | 
				
			||||||
 | 
					    children: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.agent',
 | 
				
			||||||
 | 
					        href: '/admin/teams/agents',
 | 
				
			||||||
 | 
					        permission: 'users:manage'
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.team',
 | 
				
			||||||
 | 
					        href: '/admin/teams/teams',
 | 
				
			||||||
 | 
					        permission: 'teams:manage'
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.role',
 | 
				
			||||||
 | 
					        href: '/admin/teams/roles',
 | 
				
			||||||
 | 
					        permission: 'roles:manage'
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.activityLog',
 | 
				
			||||||
 | 
					        href: '/admin/teams/activity-log',
 | 
				
			||||||
 | 
					        permission: 'activity_logs:manage'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.ai',
 | 
				
			||||||
 | 
					    children: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.aiAssistant',
 | 
				
			||||||
 | 
					        isTitleKeyPlural: true,
 | 
				
			||||||
 | 
					        href: '/admin/ai/assistants',
 | 
				
			||||||
 | 
					        permission: 'ai:manage'
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.snippet',
 | 
				
			||||||
 | 
					        isTitleKeyPlural: true,
 | 
				
			||||||
 | 
					        href: '/admin/ai/snippets',
 | 
				
			||||||
 | 
					        permission: 'ai:manage'
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.automation',
 | 
				
			||||||
 | 
					    children: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.automation',
 | 
				
			||||||
 | 
					        href: '/admin/automations',
 | 
				
			||||||
 | 
					        permission: 'automations:manage'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.customAttribute',
 | 
				
			||||||
 | 
					    children: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.customAttribute',
 | 
				
			||||||
 | 
					        href: '/admin/custom-attributes',
 | 
				
			||||||
 | 
					        permission: 'custom_attributes:manage'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.notification',
 | 
				
			||||||
 | 
					    children: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.email',
 | 
				
			||||||
 | 
					        href: '/admin/notification',
 | 
				
			||||||
 | 
					        permission: 'notification_settings:manage'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.template',
 | 
				
			||||||
 | 
					    children: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.template',
 | 
				
			||||||
 | 
					        href: '/admin/templates',
 | 
				
			||||||
 | 
					        permission: 'templates:manage'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.security',
 | 
				
			||||||
 | 
					    children: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.sso',
 | 
				
			||||||
 | 
					        href: '/admin/sso',
 | 
				
			||||||
 | 
					        permission: 'oidc:manage'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.integration',
 | 
				
			||||||
 | 
					    isTitleKeyPlural: true,
 | 
				
			||||||
 | 
					    children: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.webhook',
 | 
				
			||||||
 | 
					        href: '/admin/webhooks',
 | 
				
			||||||
 | 
					        permission: 'webhooks:manage'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.helpCenter',
 | 
				
			||||||
 | 
					    children: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        titleKey: 'globals.terms.helpCenter',
 | 
				
			||||||
 | 
					        href: '/admin/help-center',
 | 
				
			||||||
 | 
					        permission: 'help_center:manage'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const accountNavItems = [
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.profile',
 | 
				
			||||||
 | 
					    href: '/account/profile'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const contactNavItems = [
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    titleKey: 'globals.terms.contact',
 | 
				
			||||||
 | 
					    href: '/contacts'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
							
								
								
									
										42
									
								
								frontend/apps/main/src/constants/permissions.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								frontend/apps/main/src/constants/permissions.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
				
			|||||||
 | 
					export const permissions = {
 | 
				
			||||||
 | 
					  CONVERSATIONS_READ: 'conversations:read',
 | 
				
			||||||
 | 
					  CONVERSATIONS_WRITE: 'conversations:write',
 | 
				
			||||||
 | 
					  CONVERSATIONS_READ_ASSIGNED: 'conversations:read_assigned',
 | 
				
			||||||
 | 
					  CONVERSATIONS_READ_ALL: 'conversations:read_all',
 | 
				
			||||||
 | 
					  CONVERSATIONS_READ_UNASSIGNED: 'conversations:read_unassigned',
 | 
				
			||||||
 | 
					  CONVERSATIONS_READ_TEAM_INBOX: 'conversations:read_team_inbox',
 | 
				
			||||||
 | 
					  CONVERSATIONS_UPDATE_USER_ASSIGNEE: 'conversations:update_user_assignee',
 | 
				
			||||||
 | 
					  CONVERSATIONS_UPDATE_TEAM_ASSIGNEE: 'conversations:update_team_assignee',
 | 
				
			||||||
 | 
					  CONVERSATIONS_UPDATE_PRIORITY: 'conversations:update_priority',
 | 
				
			||||||
 | 
					  CONVERSATIONS_UPDATE_STATUS: 'conversations:update_status',
 | 
				
			||||||
 | 
					  CONVERSATIONS_UPDATE_TAGS: 'conversations:update_tags',
 | 
				
			||||||
 | 
					  MESSAGES_READ: 'messages:read',
 | 
				
			||||||
 | 
					  MESSAGES_WRITE: 'messages:write',
 | 
				
			||||||
 | 
					  VIEW_MANAGE: 'view:manage',
 | 
				
			||||||
 | 
					  GENERAL_SETTINGS_MANAGE: 'general_settings:manage',
 | 
				
			||||||
 | 
					  NOTIFICATION_SETTINGS_MANAGE: 'notification_settings:manage',
 | 
				
			||||||
 | 
					  STATUS_MANAGE: 'status:manage',
 | 
				
			||||||
 | 
					  OIDC_MANAGE: 'oidc:manage',
 | 
				
			||||||
 | 
					  TAGS_MANAGE: 'tags:manage',
 | 
				
			||||||
 | 
					  MACROS_MANAGE: 'macros:manage',
 | 
				
			||||||
 | 
					  USERS_MANAGE: 'users:manage',
 | 
				
			||||||
 | 
					  TEAMS_MANAGE: 'teams:manage',
 | 
				
			||||||
 | 
					  AUTOMATIONS_MANAGE: 'automations:manage',
 | 
				
			||||||
 | 
					  INBOXES_MANAGE: 'inboxes:manage',
 | 
				
			||||||
 | 
					  ROLES_MANAGE: 'roles:manage',
 | 
				
			||||||
 | 
					  TEMPLATES_MANAGE: 'templates:manage',
 | 
				
			||||||
 | 
					  REPORTS_MANAGE: 'reports:manage',
 | 
				
			||||||
 | 
					  BUSINESS_HOURS_MANAGE: 'business_hours:manage',
 | 
				
			||||||
 | 
					  SLA_MANAGE: 'sla:manage',
 | 
				
			||||||
 | 
					  AI_MANAGE: 'ai:manage',
 | 
				
			||||||
 | 
					  CUSTOM_ATTRIBUTES_MANAGE: 'custom_attributes:manage',
 | 
				
			||||||
 | 
					  CONTACTS_READ_ALL: 'contacts:read_all',
 | 
				
			||||||
 | 
					  CONTACTS_READ: 'contacts:read',
 | 
				
			||||||
 | 
					  CONTACTS_WRITE: 'contacts:write',
 | 
				
			||||||
 | 
					  CONTACTS_BLOCK: 'contacts:block',
 | 
				
			||||||
 | 
					  CONTACT_NOTES_READ: 'contact_notes:read',
 | 
				
			||||||
 | 
					  CONTACT_NOTES_WRITE: 'contact_notes:write',
 | 
				
			||||||
 | 
					  CONTACT_NOTES_DELETE: 'contact_notes:delete',
 | 
				
			||||||
 | 
					  ACTIVITY_LOGS_MANAGE: 'activity_logs:manage',
 | 
				
			||||||
 | 
					  WEBHOOKS_MANAGE: 'webhooks:manage'
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										13
									
								
								frontend/apps/main/src/constants/websocket.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								frontend/apps/main/src/constants/websocket.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					export const WS_EVENT = {
 | 
				
			||||||
 | 
					    NEW_MESSAGE: 'new_message',
 | 
				
			||||||
 | 
					    MESSAGE_PROP_UPDATE: 'message_prop_update',
 | 
				
			||||||
 | 
					    CONVERSATION_PROP_UPDATE: 'conversation_prop_update',
 | 
				
			||||||
 | 
					    CONVERSATION_SUBSCRIBE: 'conversation_subscribe',
 | 
				
			||||||
 | 
					    CONVERSATION_SUBSCRIBED: 'conversation_subscribed',
 | 
				
			||||||
 | 
					    TYPING: 'typing',
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Message types that should not be queued because they become stale quickly
 | 
				
			||||||
 | 
					export const WS_EPHEMERAL_TYPES = [
 | 
				
			||||||
 | 
					    WS_EVENT.TYPING,
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
@@ -44,7 +44,7 @@
 | 
				
			|||||||
              </SelectTrigger>
 | 
					              </SelectTrigger>
 | 
				
			||||||
              <SelectContent>
 | 
					              <SelectContent>
 | 
				
			||||||
                <SelectItem :value="'activity_logs.created_at'">
 | 
					                <SelectItem :value="'activity_logs.created_at'">
 | 
				
			||||||
                  {{ t('form.field.createdAt') }}
 | 
					                  {{ t('globals.terms.createdAt') }}
 | 
				
			||||||
                </SelectItem>
 | 
					                </SelectItem>
 | 
				
			||||||
              </SelectContent>
 | 
					              </SelectContent>
 | 
				
			||||||
            </Select>
 | 
					            </Select>
 | 
				
			||||||
@@ -63,35 +63,20 @@
 | 
				
			|||||||
        </Popover>
 | 
					        </Popover>
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      <div v-if="loading" class="w-full">
 | 
					 | 
				
			||||||
        <div class="flex border-b border-border p-4 font-medium bg-gray-50">
 | 
					 | 
				
			||||||
          <div class="flex-1 text-muted-foreground">{{ t('form.field.name') }}</div>
 | 
					 | 
				
			||||||
          <div class="w-[200px] text-muted-foreground">{{ t('form.field.date') }}</div>
 | 
					 | 
				
			||||||
          <div class="w-[150px] text-muted-foreground">{{ t('globals.terms.ipAddress') }}</div>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <div v-for="i in perPage" :key="i" class="flex border-b border-border py-3 px-4">
 | 
					 | 
				
			||||||
          <div class="flex-1">
 | 
					 | 
				
			||||||
            <Skeleton class="h-4 w-[90%]" />
 | 
					 | 
				
			||||||
          </div>
 | 
					 | 
				
			||||||
          <div class="w-[200px]">
 | 
					 | 
				
			||||||
            <Skeleton class="h-4 w-[120px]" />
 | 
					 | 
				
			||||||
          </div>
 | 
					 | 
				
			||||||
          <div class="w-[150px]">
 | 
					 | 
				
			||||||
            <Skeleton class="h-4 w-[100px]" />
 | 
					 | 
				
			||||||
          </div>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
      </div>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      <template v-else>
 | 
					 | 
				
			||||||
      <div class="w-full overflow-x-auto">
 | 
					      <div class="w-full overflow-x-auto">
 | 
				
			||||||
        <SimpleTable
 | 
					        <SimpleTable
 | 
				
			||||||
            :headers="[t('form.field.name'), t('form.field.timestamp'), t('globals.terms.ipAddress')]"
 | 
					          :headers="[
 | 
				
			||||||
 | 
					            t('globals.terms.name'),
 | 
				
			||||||
 | 
					            t('globals.terms.timestamp'),
 | 
				
			||||||
 | 
					            t('globals.terms.ipAddress')
 | 
				
			||||||
 | 
					          ]"
 | 
				
			||||||
          :keys="['activity_description', 'created_at', 'ip']"
 | 
					          :keys="['activity_description', 'created_at', 'ip']"
 | 
				
			||||||
          :data="activityLogs"
 | 
					          :data="activityLogs"
 | 
				
			||||||
          :showDelete="false"
 | 
					          :showDelete="false"
 | 
				
			||||||
 | 
					          :loading="loading"
 | 
				
			||||||
 | 
					          :skeletonRows="15"
 | 
				
			||||||
        />
 | 
					        />
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
      </template>
 | 
					 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <!-- TODO: deduplicate this code, copied from contacts list -->
 | 
					    <!-- TODO: deduplicate this code, copied from contacts list -->
 | 
				
			||||||
@@ -163,8 +148,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
<script setup>
 | 
					<script setup>
 | 
				
			||||||
import { ref, computed, onMounted, watch } from 'vue'
 | 
					import { ref, computed, onMounted, watch } from 'vue'
 | 
				
			||||||
import { Skeleton } from '@/components/ui/skeleton'
 | 
					import SimpleTable from '@main/components/table/SimpleTable.vue'
 | 
				
			||||||
import SimpleTable from '@/components/table/SimpleTable.vue'
 | 
					 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  Pagination,
 | 
					  Pagination,
 | 
				
			||||||
  PaginationEllipsis,
 | 
					  PaginationEllipsis,
 | 
				
			||||||
@@ -174,23 +158,23 @@ import {
 | 
				
			|||||||
  PaginationListItem,
 | 
					  PaginationListItem,
 | 
				
			||||||
  PaginationNext,
 | 
					  PaginationNext,
 | 
				
			||||||
  PaginationPrev
 | 
					  PaginationPrev
 | 
				
			||||||
} from '@/components/ui/pagination'
 | 
					} from '@shared-ui/components/ui/pagination'
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  Select,
 | 
					  Select,
 | 
				
			||||||
  SelectContent,
 | 
					  SelectContent,
 | 
				
			||||||
  SelectItem,
 | 
					  SelectItem,
 | 
				
			||||||
  SelectTrigger,
 | 
					  SelectTrigger,
 | 
				
			||||||
  SelectValue
 | 
					  SelectValue
 | 
				
			||||||
} from '@/components/ui/select'
 | 
					} from '@shared-ui/components/ui/select'
 | 
				
			||||||
import FilterBuilder from '@/components/filter/FilterBuilder.vue'
 | 
					import FilterBuilder from '@main/components/filter/FilterBuilder.vue'
 | 
				
			||||||
import { Button } from '@/components/ui/button'
 | 
					import { Button } from '@shared-ui/components/ui/button'
 | 
				
			||||||
import { ListFilter, ArrowDownWideNarrow } from 'lucide-vue-next'
 | 
					import { ListFilter, ArrowDownWideNarrow } from 'lucide-vue-next'
 | 
				
			||||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
 | 
					import { Popover, PopoverContent, PopoverTrigger } from '@shared-ui/components/ui/popover'
 | 
				
			||||||
import { useActivityLogFilters } from '@/composables/useActivityLogFilters'
 | 
					import { useActivityLogFilters } from '../../../composables/useActivityLogFilters'
 | 
				
			||||||
import { useI18n } from 'vue-i18n'
 | 
					import { useI18n } from 'vue-i18n'
 | 
				
			||||||
import { format } from 'date-fns'
 | 
					import { format } from 'date-fns'
 | 
				
			||||||
import { getVisiblePages } from '@/utils/pagination'
 | 
					import { getVisiblePages } from '../../../utils/pagination'
 | 
				
			||||||
import api from '@/api'
 | 
					import api from '../../../api'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const activityLogs = ref([])
 | 
					const activityLogs = ref([])
 | 
				
			||||||
const { t } = useI18n()
 | 
					const { t } = useI18n()
 | 
				
			||||||
							
								
								
									
										540
									
								
								frontend/apps/main/src/features/admin/agents/AgentForm.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										540
									
								
								frontend/apps/main/src/features/admin/agents/AgentForm.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,540 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <form @submit.prevent="onSubmit" class="space-y-8">
 | 
				
			||||||
 | 
					    <!-- Summary Section -->
 | 
				
			||||||
 | 
					    <div class="bg-muted/30 box py-6 px-3" v-if="!isNewForm">
 | 
				
			||||||
 | 
					      <div class="flex items-start gap-6">
 | 
				
			||||||
 | 
					        <Avatar class="w-20 h-20">
 | 
				
			||||||
 | 
					          <AvatarImage :src="props.initialValues.avatar_url || ''" :alt="Avatar" />
 | 
				
			||||||
 | 
					          <AvatarFallback>
 | 
				
			||||||
 | 
					            {{ getInitials(props.initialValues.first_name, props.initialValues.last_name) }}
 | 
				
			||||||
 | 
					          </AvatarFallback>
 | 
				
			||||||
 | 
					        </Avatar>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <div class="space-y-4 flex-2">
 | 
				
			||||||
 | 
					          <div class="flex items-center gap-3">
 | 
				
			||||||
 | 
					            <h3 class="text-lg font-semibold text-gray-900 dark:text-foreground">
 | 
				
			||||||
 | 
					              {{ props.initialValues.first_name }} {{ props.initialValues.last_name }}
 | 
				
			||||||
 | 
					            </h3>
 | 
				
			||||||
 | 
					            <Badge :class="['px-2 rounded-full text-xs font-medium', availabilityStatus.color]">
 | 
				
			||||||
 | 
					              {{ availabilityStatus.text }}
 | 
				
			||||||
 | 
					            </Badge>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          <div class="flex flex-wrap items-center gap-6">
 | 
				
			||||||
 | 
					            <div class="flex items-center gap-2">
 | 
				
			||||||
 | 
					              <Clock class="w-5 h-5 text-gray-400" />
 | 
				
			||||||
 | 
					              <div>
 | 
				
			||||||
 | 
					                <p class="text-sm text-gray-500">{{ $t('globals.terms.lastActive') }}</p>
 | 
				
			||||||
 | 
					                <p class="text-sm font-medium text-gray-700 dark:text-foreground">
 | 
				
			||||||
 | 
					                  {{
 | 
				
			||||||
 | 
					                    props.initialValues.last_active_at
 | 
				
			||||||
 | 
					                      ? format(new Date(props.initialValues.last_active_at), 'PPpp')
 | 
				
			||||||
 | 
					                      : 'N/A'
 | 
				
			||||||
 | 
					                  }}
 | 
				
			||||||
 | 
					                </p>
 | 
				
			||||||
 | 
					              </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <div class="flex items-center gap-2">
 | 
				
			||||||
 | 
					              <LogIn class="w-5 h-5 text-gray-400" />
 | 
				
			||||||
 | 
					              <div>
 | 
				
			||||||
 | 
					                <p class="text-sm text-gray-500">{{ $t('globals.terms.lastLogin') }}</p>
 | 
				
			||||||
 | 
					                <p class="text-sm font-medium text-gray-700 dark:text-foreground">
 | 
				
			||||||
 | 
					                  {{
 | 
				
			||||||
 | 
					                    props.initialValues.last_login_at
 | 
				
			||||||
 | 
					                      ? format(new Date(props.initialValues.last_login_at), 'PPpp')
 | 
				
			||||||
 | 
					                      : 'N/A'
 | 
				
			||||||
 | 
					                  }}
 | 
				
			||||||
 | 
					                </p>
 | 
				
			||||||
 | 
					              </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- API Key Management Section -->
 | 
				
			||||||
 | 
					    <div class="bg-muted/30 box p-4 space-y-4" v-if="!isNewForm">
 | 
				
			||||||
 | 
					      <!-- Header -->
 | 
				
			||||||
 | 
					      <div class="flex items-center justify-between">
 | 
				
			||||||
 | 
					        <div>
 | 
				
			||||||
 | 
					          <p class="text-base font-semibold text-gray-900 dark:text-foreground">
 | 
				
			||||||
 | 
					            {{ $t('globals.terms.apiKey', 2) }}
 | 
				
			||||||
 | 
					          </p>
 | 
				
			||||||
 | 
					          <p class="text-sm text-gray-500">
 | 
				
			||||||
 | 
					            {{ $t('admin.agent.apiKey.description') }}
 | 
				
			||||||
 | 
					          </p>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <!-- API Key Display -->
 | 
				
			||||||
 | 
					      <div v-if="apiKeyData.api_key" class="space-y-3">
 | 
				
			||||||
 | 
					        <div class="flex items-center justify-between p-3 bg-background border rounded-md">
 | 
				
			||||||
 | 
					          <div class="flex items-center gap-3">
 | 
				
			||||||
 | 
					            <Key class="w-4 h-4 text-gray-400" />
 | 
				
			||||||
 | 
					            <div>
 | 
				
			||||||
 | 
					              <p class="text-sm font-medium">{{ $t('globals.terms.apiKey') }}</p>
 | 
				
			||||||
 | 
					              <p class="text-xs text-gray-500 font-mono">{{ apiKeyData.api_key }}</p>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					          <div class="flex gap-2">
 | 
				
			||||||
 | 
					            <Button
 | 
				
			||||||
 | 
					              type="button"
 | 
				
			||||||
 | 
					              variant="outline"
 | 
				
			||||||
 | 
					              size="sm"
 | 
				
			||||||
 | 
					              @click="regenerateAPIKey"
 | 
				
			||||||
 | 
					              :disabled="isAPIKeyLoading"
 | 
				
			||||||
 | 
					            >
 | 
				
			||||||
 | 
					              <RotateCcw class="w-4 h-4 mr-1" />
 | 
				
			||||||
 | 
					              {{ $t('globals.messages.regenerate') }}
 | 
				
			||||||
 | 
					            </Button>
 | 
				
			||||||
 | 
					            <Button
 | 
				
			||||||
 | 
					              type="button"
 | 
				
			||||||
 | 
					              variant="destructive"
 | 
				
			||||||
 | 
					              size="sm"
 | 
				
			||||||
 | 
					              @click="revokeAPIKey"
 | 
				
			||||||
 | 
					              :disabled="isAPIKeyLoading"
 | 
				
			||||||
 | 
					            >
 | 
				
			||||||
 | 
					              <Trash2 class="w-4 h-4 mr-1" />
 | 
				
			||||||
 | 
					              {{ $t('globals.messages.revoke') }}
 | 
				
			||||||
 | 
					            </Button>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <!-- Last Used Info -->
 | 
				
			||||||
 | 
					        <div v-if="apiKeyLastUsedAt" class="text-xs text-gray-500">
 | 
				
			||||||
 | 
					          {{ $t('globals.messages.lastUsed') }}:
 | 
				
			||||||
 | 
					          {{ format(new Date(apiKeyLastUsedAt), 'PPpp') }}
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <!-- No API Key State -->
 | 
				
			||||||
 | 
					      <div v-else class="text-center py-6">
 | 
				
			||||||
 | 
					        <Key class="w-8 h-8 text-gray-400 mx-auto mb-2" />
 | 
				
			||||||
 | 
					        <p class="text-sm text-gray-500 mb-3">{{ $t('admin.agent.apiKey.noKey') }}</p>
 | 
				
			||||||
 | 
					        <Button type="button" @click="generateAPIKey" :disabled="isAPIKeyLoading">
 | 
				
			||||||
 | 
					          <Plus class="w-4 h-4 mr-1" />
 | 
				
			||||||
 | 
					          {{ $t('globals.messages.generate', { name: $t('globals.terms.apiKey') }) }}
 | 
				
			||||||
 | 
					        </Button>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- API Key Display Dialog -->
 | 
				
			||||||
 | 
					    <Dialog v-model:open="showAPIKeyDialog">
 | 
				
			||||||
 | 
					      <DialogContent class="sm:max-w-md">
 | 
				
			||||||
 | 
					        <DialogHeader>
 | 
				
			||||||
 | 
					          <DialogTitle>
 | 
				
			||||||
 | 
					            {{ $t('globals.messages.generated', { name: $t('globals.terms.apiKey') }) }}
 | 
				
			||||||
 | 
					          </DialogTitle>
 | 
				
			||||||
 | 
					          <DialogDescription> </DialogDescription>
 | 
				
			||||||
 | 
					        </DialogHeader>
 | 
				
			||||||
 | 
					        <div class="space-y-4">
 | 
				
			||||||
 | 
					          <div>
 | 
				
			||||||
 | 
					            <Label class="text-sm font-medium">{{ $t('globals.terms.apiKey') }}</Label>
 | 
				
			||||||
 | 
					            <div class="flex items-center gap-2 mt-1">
 | 
				
			||||||
 | 
					              <Input v-model="newAPIKeyData.api_key" readonly class="font-mono text-sm" />
 | 
				
			||||||
 | 
					              <Button
 | 
				
			||||||
 | 
					                type="button"
 | 
				
			||||||
 | 
					                variant="outline"
 | 
				
			||||||
 | 
					                size="sm"
 | 
				
			||||||
 | 
					                @click="copyToClipboard(newAPIKeyData.api_key)"
 | 
				
			||||||
 | 
					              >
 | 
				
			||||||
 | 
					                <Copy class="w-4 h-4" />
 | 
				
			||||||
 | 
					              </Button>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					          <div>
 | 
				
			||||||
 | 
					            <Label class="text-sm font-medium">{{ $t('globals.terms.secret') }}</Label>
 | 
				
			||||||
 | 
					            <div class="flex items-center gap-2 mt-1">
 | 
				
			||||||
 | 
					              <Input v-model="newAPIKeyData.api_secret" readonly class="font-mono text-sm" />
 | 
				
			||||||
 | 
					              <Button
 | 
				
			||||||
 | 
					                type="button"
 | 
				
			||||||
 | 
					                variant="outline"
 | 
				
			||||||
 | 
					                size="sm"
 | 
				
			||||||
 | 
					                @click="copyToClipboard(newAPIKeyData.api_secret)"
 | 
				
			||||||
 | 
					              >
 | 
				
			||||||
 | 
					                <Copy class="w-4 h-4" />
 | 
				
			||||||
 | 
					              </Button>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					          <Alert>
 | 
				
			||||||
 | 
					            <AlertTriangle class="h-4 w-4" />
 | 
				
			||||||
 | 
					            <AlertTitle>{{ $t('globals.terms.warning') }}</AlertTitle>
 | 
				
			||||||
 | 
					            <AlertDescription>
 | 
				
			||||||
 | 
					              {{ $t('admin.agent.apiKey.warningMessage') }}
 | 
				
			||||||
 | 
					            </AlertDescription>
 | 
				
			||||||
 | 
					          </Alert>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <DialogFooter>
 | 
				
			||||||
 | 
					          <Button @click="closeAPIKeyModal">{{ $t('globals.messages.close') }}</Button>
 | 
				
			||||||
 | 
					        </DialogFooter>
 | 
				
			||||||
 | 
					      </DialogContent>
 | 
				
			||||||
 | 
					    </Dialog>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- Form Fields -->
 | 
				
			||||||
 | 
					    <FormField v-slot="{ field }" name="first_name">
 | 
				
			||||||
 | 
					      <FormItem v-auto-animate>
 | 
				
			||||||
 | 
					        <FormLabel>{{ $t('globals.terms.firstName') }}</FormLabel>
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <Input type="text" placeholder="" v-bind="field" />
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					        <FormMessage />
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <FormField v-slot="{ field }" name="last_name">
 | 
				
			||||||
 | 
					      <FormItem>
 | 
				
			||||||
 | 
					        <FormLabel>{{ $t('globals.terms.lastName') }}</FormLabel>
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <Input type="text" placeholder="" v-bind="field" />
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					        <FormMessage />
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <FormField v-slot="{ field }" name="email">
 | 
				
			||||||
 | 
					      <FormItem v-auto-animate>
 | 
				
			||||||
 | 
					        <FormLabel>{{ $t('globals.terms.email') }}</FormLabel>
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <Input type="email" placeholder="" v-bind="field" />
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					        <FormMessage />
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <FormField v-slot="{ componentField, handleChange }" name="teams">
 | 
				
			||||||
 | 
					      <FormItem v-auto-animate>
 | 
				
			||||||
 | 
					        <FormLabel>{{ $t('globals.terms.team', 2) }}</FormLabel>
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <SelectTag
 | 
				
			||||||
 | 
					            :items="teamOptions"
 | 
				
			||||||
 | 
					            :placeholder="t('globals.messages.select', { name: t('globals.terms.team', 2) })"
 | 
				
			||||||
 | 
					            v-model="componentField.modelValue"
 | 
				
			||||||
 | 
					            @update:modelValue="handleChange"
 | 
				
			||||||
 | 
					          />
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					        <FormMessage />
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <FormField v-slot="{ componentField, handleChange }" name="roles">
 | 
				
			||||||
 | 
					      <FormItem v-auto-animate>
 | 
				
			||||||
 | 
					        <FormLabel>{{ $t('globals.terms.role', 2) }}</FormLabel>
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <SelectTag
 | 
				
			||||||
 | 
					            :items="roleOptions"
 | 
				
			||||||
 | 
					            :placeholder="
 | 
				
			||||||
 | 
					              t('globals.messages.select', {
 | 
				
			||||||
 | 
					                name: $t('globals.terms.role', 2)
 | 
				
			||||||
 | 
					              })
 | 
				
			||||||
 | 
					            "
 | 
				
			||||||
 | 
					            v-model="componentField.modelValue"
 | 
				
			||||||
 | 
					            @update:modelValue="handleChange"
 | 
				
			||||||
 | 
					          />
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					        <FormMessage />
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <FormField v-slot="{ componentField }" name="availability_status" v-if="!isNewForm">
 | 
				
			||||||
 | 
					      <FormItem>
 | 
				
			||||||
 | 
					        <FormLabel>{{ t('globals.terms.availabilityStatus') }}</FormLabel>
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <Select v-bind="componentField" v-model="componentField.modelValue">
 | 
				
			||||||
 | 
					            <SelectTrigger>
 | 
				
			||||||
 | 
					              <SelectValue
 | 
				
			||||||
 | 
					                :placeholder="
 | 
				
			||||||
 | 
					                  t('globals.messages.select', {
 | 
				
			||||||
 | 
					                    name: t('globals.terms.availabilityStatus')
 | 
				
			||||||
 | 
					                  })
 | 
				
			||||||
 | 
					                "
 | 
				
			||||||
 | 
					              />
 | 
				
			||||||
 | 
					            </SelectTrigger>
 | 
				
			||||||
 | 
					            <SelectContent>
 | 
				
			||||||
 | 
					              <SelectGroup>
 | 
				
			||||||
 | 
					                <SelectItem value="active_group">{{ t('globals.terms.active') }}</SelectItem>
 | 
				
			||||||
 | 
					                <SelectItem value="away_manual">{{ t('globals.terms.away') }}</SelectItem>
 | 
				
			||||||
 | 
					                <SelectItem value="away_and_reassigning">
 | 
				
			||||||
 | 
					                  {{ t('globals.terms.awayReassigning') }}
 | 
				
			||||||
 | 
					                </SelectItem>
 | 
				
			||||||
 | 
					              </SelectGroup>
 | 
				
			||||||
 | 
					            </SelectContent>
 | 
				
			||||||
 | 
					          </Select>
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					        <FormMessage />
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <FormField v-slot="{ field }" name="new_password" v-if="!isNewForm">
 | 
				
			||||||
 | 
					      <FormItem v-auto-animate>
 | 
				
			||||||
 | 
					        <FormLabel>{{ t('globals.terms.setPassword') }}</FormLabel>
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <Input type="password" placeholder="" v-bind="field" />
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					        <FormMessage />
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <FormField name="send_welcome_email" v-slot="{ value, handleChange }" v-if="isNewForm">
 | 
				
			||||||
 | 
					      <FormItem>
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <div class="flex items-center space-x-2">
 | 
				
			||||||
 | 
					            <Checkbox :checked="value" @update:checked="handleChange" />
 | 
				
			||||||
 | 
					            <Label>{{ $t('globals.terms.sendWelcomeEmail') }}</Label>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					        <FormMessage />
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <FormField v-slot="{ value, handleChange }" type="checkbox" name="enabled" v-if="!isNewForm">
 | 
				
			||||||
 | 
					      <FormItem class="flex flex-row items-start gap-x-3 space-y-0">
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <Checkbox :checked="value" @update:checked="handleChange" />
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					        <div class="space-y-1 leading-none">
 | 
				
			||||||
 | 
					          <FormLabel> {{ $t('globals.terms.enabled') }} </FormLabel>
 | 
				
			||||||
 | 
					          <FormMessage />
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <Button type="submit" :isLoading="isLoading"> {{ submitLabel }} </Button>
 | 
				
			||||||
 | 
					  </form>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script setup>
 | 
				
			||||||
 | 
					import { watch, onMounted, ref, computed } from 'vue'
 | 
				
			||||||
 | 
					import { Button } from '@shared-ui/components/ui/button/index.js'
 | 
				
			||||||
 | 
					import { useForm } from 'vee-validate'
 | 
				
			||||||
 | 
					import { toTypedSchema } from '@vee-validate/zod'
 | 
				
			||||||
 | 
					import { createFormSchema } from './formSchema.js'
 | 
				
			||||||
 | 
					import { Checkbox } from '@shared-ui/components/ui/checkbox/index.js'
 | 
				
			||||||
 | 
					import { Label } from '@shared-ui/components/ui/label/index.js'
 | 
				
			||||||
 | 
					import { vAutoAnimate } from '@formkit/auto-animate/vue'
 | 
				
			||||||
 | 
					import { Badge } from '@shared-ui/components/ui/badge/index.js'
 | 
				
			||||||
 | 
					import { Clock, LogIn, Key, RotateCcw, Trash2, Plus, Copy, AlertTriangle } from 'lucide-vue-next'
 | 
				
			||||||
 | 
					import { FormControl, FormField, FormItem, FormLabel, FormMessage } from '@shared-ui/components/ui/form/index.js'
 | 
				
			||||||
 | 
					import { Avatar, AvatarFallback, AvatarImage } from '@shared-ui/components/ui/avatar/index.js'
 | 
				
			||||||
 | 
					import {
 | 
				
			||||||
 | 
					  Select,
 | 
				
			||||||
 | 
					  SelectContent,
 | 
				
			||||||
 | 
					  SelectGroup,
 | 
				
			||||||
 | 
					  SelectItem,
 | 
				
			||||||
 | 
					  SelectTrigger,
 | 
				
			||||||
 | 
					  SelectValue
 | 
				
			||||||
 | 
					} from '@shared-ui/components/ui/select/index.js'
 | 
				
			||||||
 | 
					import { SelectTag } from '@shared-ui/components/ui/select/index.js'
 | 
				
			||||||
 | 
					import { Input } from '@shared-ui/components/ui/input/index.js'
 | 
				
			||||||
 | 
					import {
 | 
				
			||||||
 | 
					  Dialog,
 | 
				
			||||||
 | 
					  DialogContent,
 | 
				
			||||||
 | 
					  DialogDescription,
 | 
				
			||||||
 | 
					  DialogFooter,
 | 
				
			||||||
 | 
					  DialogHeader,
 | 
				
			||||||
 | 
					  DialogTitle
 | 
				
			||||||
 | 
					} from '@shared-ui/components/ui/dialog/index.js'
 | 
				
			||||||
 | 
					import { Alert, AlertDescription, AlertTitle } from '@shared-ui/components/ui/alert/index.js'
 | 
				
			||||||
 | 
					import { useI18n } from 'vue-i18n'
 | 
				
			||||||
 | 
					import { useEmitter } from '../../../composables/useEmitter.js'
 | 
				
			||||||
 | 
					import { EMITTER_EVENTS } from '../../../constants/emitterEvents.js'
 | 
				
			||||||
 | 
					import { format } from 'date-fns'
 | 
				
			||||||
 | 
					import api from '../../../api/index.js'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const props = defineProps({
 | 
				
			||||||
 | 
					  initialValues: {
 | 
				
			||||||
 | 
					    type: Object,
 | 
				
			||||||
 | 
					    required: false
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  submitForm: {
 | 
				
			||||||
 | 
					    type: Function,
 | 
				
			||||||
 | 
					    required: true
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  submitLabel: {
 | 
				
			||||||
 | 
					    type: String,
 | 
				
			||||||
 | 
					    required: false,
 | 
				
			||||||
 | 
					    default: 'Submit'
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  isNewForm: {
 | 
				
			||||||
 | 
					    type: Boolean,
 | 
				
			||||||
 | 
					    required: false,
 | 
				
			||||||
 | 
					    default: false
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  isLoading: {
 | 
				
			||||||
 | 
					    Type: Boolean,
 | 
				
			||||||
 | 
					    required: false
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					const { t } = useI18n()
 | 
				
			||||||
 | 
					const teams = ref([])
 | 
				
			||||||
 | 
					const roles = ref([])
 | 
				
			||||||
 | 
					const emitter = useEmitter()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const apiKeyData = ref({
 | 
				
			||||||
 | 
					  api_key: props.initialValues?.api_key || '',
 | 
				
			||||||
 | 
					  api_secret: ''
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					const apiKeyLastUsedAt = ref(props.initialValues?.api_key_last_used_at || null)
 | 
				
			||||||
 | 
					const newAPIKeyData = ref({
 | 
				
			||||||
 | 
					  api_key: '',
 | 
				
			||||||
 | 
					  api_secret: ''
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					const showAPIKeyDialog = ref(false)
 | 
				
			||||||
 | 
					const isAPIKeyLoading = ref(false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					onMounted(async () => {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    const [teamsResp, rolesResp] = await Promise.allSettled([api.getTeams(), api.getRoles()])
 | 
				
			||||||
 | 
					    teams.value = teamsResp.value.data.data
 | 
				
			||||||
 | 
					    roles.value = rolesResp.value.data.data
 | 
				
			||||||
 | 
					  } catch (err) {
 | 
				
			||||||
 | 
					    emitter.emit(EMITTER_EVENTS.SHOW_TOAST, {
 | 
				
			||||||
 | 
					      variant: 'destructive',
 | 
				
			||||||
 | 
					      description: t('globals.messages.errorFetching')
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const availabilityStatus = computed(() => {
 | 
				
			||||||
 | 
					  const status = form.values.availability_status
 | 
				
			||||||
 | 
					  if (status === 'active_group') return { text: t('globals.terms.active'), color: 'bg-green-500' }
 | 
				
			||||||
 | 
					  if (status === 'away_manual') return { text: t('globals.terms.away'), color: 'bg-yellow-500' }
 | 
				
			||||||
 | 
					  if (status === 'away_and_reassigning')
 | 
				
			||||||
 | 
					    return { text: t('globals.terms.awayReassigning'), color: 'bg-orange-500' }
 | 
				
			||||||
 | 
					  return { text: t('globals.terms.offline'), color: 'bg-gray-400' }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const teamOptions = computed(() =>
 | 
				
			||||||
 | 
					  teams.value.map((team) => ({ label: team.name, value: team.name }))
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					const roleOptions = computed(() =>
 | 
				
			||||||
 | 
					  roles.value.map((role) => ({ label: role.name, value: role.name }))
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const form = useForm({
 | 
				
			||||||
 | 
					  validationSchema: toTypedSchema(createFormSchema(t))
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const onSubmit = form.handleSubmit((values) => {
 | 
				
			||||||
 | 
					  if (values.availability_status === 'active_group') {
 | 
				
			||||||
 | 
					    values.availability_status = 'online'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  values.teams = values.teams.map((team) => ({ name: team }))
 | 
				
			||||||
 | 
					  props.submitForm(values)
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const getInitials = (firstName, lastName) => {
 | 
				
			||||||
 | 
					  if (!firstName && !lastName) return ''
 | 
				
			||||||
 | 
					  if (!firstName) return lastName.charAt(0).toUpperCase()
 | 
				
			||||||
 | 
					  if (!lastName) return firstName.charAt(0).toUpperCase()
 | 
				
			||||||
 | 
					  return `${firstName.charAt(0).toUpperCase()}${lastName.charAt(0).toUpperCase()}`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const generateAPIKey = async () => {
 | 
				
			||||||
 | 
					  if (!props.initialValues?.id) return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    isAPIKeyLoading.value = true
 | 
				
			||||||
 | 
					    const response = await api.generateAPIKey(props.initialValues.id)
 | 
				
			||||||
 | 
					    if (response.data) {
 | 
				
			||||||
 | 
					      const responseData = response.data.data
 | 
				
			||||||
 | 
					      newAPIKeyData.value = {
 | 
				
			||||||
 | 
					        api_key: responseData.api_key,
 | 
				
			||||||
 | 
					        api_secret: responseData.api_secret
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      apiKeyData.value.api_key = responseData.api_key
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // Clear the last used timestamp since this is a new API key
 | 
				
			||||||
 | 
					      apiKeyLastUsedAt.value = null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      showAPIKeyDialog.value = true
 | 
				
			||||||
 | 
					      emitter.emit(EMITTER_EVENTS.SHOW_TOAST, {
 | 
				
			||||||
 | 
					        description: t('globals.messages.generatedSuccessfully', {
 | 
				
			||||||
 | 
					          name: t('globals.terms.apiKey')
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    emitter.emit(EMITTER_EVENTS.SHOW_TOAST, {
 | 
				
			||||||
 | 
					      variant: 'destructive',
 | 
				
			||||||
 | 
					      description: t('globals.messages.errorGenerating', {
 | 
				
			||||||
 | 
					        name: t('globals.terms.apiKey')
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  } finally {
 | 
				
			||||||
 | 
					    isAPIKeyLoading.value = false
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const regenerateAPIKey = async () => {
 | 
				
			||||||
 | 
					  await generateAPIKey()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const revokeAPIKey = async () => {
 | 
				
			||||||
 | 
					  if (!props.initialValues?.id) return
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    isAPIKeyLoading.value = true
 | 
				
			||||||
 | 
					    await api.revokeAPIKey(props.initialValues.id)
 | 
				
			||||||
 | 
					    apiKeyData.value.api_key = ''
 | 
				
			||||||
 | 
					    apiKeyData.value.api_secret = ''
 | 
				
			||||||
 | 
					    apiKeyLastUsedAt.value = null
 | 
				
			||||||
 | 
					    emitter.emit(EMITTER_EVENTS.SHOW_TOAST, {
 | 
				
			||||||
 | 
					      description: t('globals.messages.revokedSuccessfully', {
 | 
				
			||||||
 | 
					        name: t('globals.terms.apiKey')
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    emitter.emit(EMITTER_EVENTS.SHOW_TOAST, {
 | 
				
			||||||
 | 
					      variant: 'destructive',
 | 
				
			||||||
 | 
					      description: t('globals.messages.errorRevoking', {
 | 
				
			||||||
 | 
					        name: t('globals.terms.apiKey')
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  } finally {
 | 
				
			||||||
 | 
					    isAPIKeyLoading.value = false
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const copyToClipboard = async (text) => {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    await navigator.clipboard.writeText(text)
 | 
				
			||||||
 | 
					    emitter.emit(EMITTER_EVENTS.SHOW_TOAST, {
 | 
				
			||||||
 | 
					      description: t('globals.messages.copied')
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    console.error('Error copying to clipboard:', error)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const closeAPIKeyModal = () => {
 | 
				
			||||||
 | 
					  showAPIKeyDialog.value = false
 | 
				
			||||||
 | 
					  newAPIKeyData.value = { api_key: '', api_secret: '' }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					watch(
 | 
				
			||||||
 | 
					  () => props.initialValues,
 | 
				
			||||||
 | 
					  (newValues) => {
 | 
				
			||||||
 | 
					    // Hack.
 | 
				
			||||||
 | 
					    if (Object.keys(newValues).length > 0) {
 | 
				
			||||||
 | 
					      setTimeout(() => {
 | 
				
			||||||
 | 
					        if (
 | 
				
			||||||
 | 
					          newValues.availability_status === 'away' ||
 | 
				
			||||||
 | 
					          newValues.availability_status === 'offline' ||
 | 
				
			||||||
 | 
					          newValues.availability_status === 'online'
 | 
				
			||||||
 | 
					        ) {
 | 
				
			||||||
 | 
					          newValues.availability_status = 'active_group'
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        form.setValues(newValues)
 | 
				
			||||||
 | 
					        form.setFieldValue(
 | 
				
			||||||
 | 
					          'teams',
 | 
				
			||||||
 | 
					          newValues.teams.map((team) => team.name)
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Update API key data
 | 
				
			||||||
 | 
					        apiKeyData.value.api_key = newValues.api_key || ''
 | 
				
			||||||
 | 
					        apiKeyLastUsedAt.value = newValues.api_key_last_used_at || null
 | 
				
			||||||
 | 
					      }, 0)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  { deep: true, immediate: true }
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
@@ -6,7 +6,7 @@ export const createColumns = (t) => [
 | 
				
			|||||||
  {
 | 
					  {
 | 
				
			||||||
    accessorKey: 'first_name',
 | 
					    accessorKey: 'first_name',
 | 
				
			||||||
    header: function () {
 | 
					    header: function () {
 | 
				
			||||||
      return h('div', { class: 'text-center' }, t('form.field.firstName'))
 | 
					      return h('div', { class: 'text-center' }, t('globals.terms.firstName'))
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    cell: function ({ row }) {
 | 
					    cell: function ({ row }) {
 | 
				
			||||||
      return h('div', { class: 'text-center font-medium' }, row.getValue('first_name'))
 | 
					      return h('div', { class: 'text-center font-medium' }, row.getValue('first_name'))
 | 
				
			||||||
@@ -15,7 +15,7 @@ export const createColumns = (t) => [
 | 
				
			|||||||
  {
 | 
					  {
 | 
				
			||||||
    accessorKey: 'last_name',
 | 
					    accessorKey: 'last_name',
 | 
				
			||||||
    header: function () {
 | 
					    header: function () {
 | 
				
			||||||
      return h('div', { class: 'text-center' }, t('form.field.lastName'))
 | 
					      return h('div', { class: 'text-center' }, t('globals.terms.lastName'))
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    cell: function ({ row }) {
 | 
					    cell: function ({ row }) {
 | 
				
			||||||
      return h('div', { class: 'text-center font-medium' }, row.getValue('last_name'))
 | 
					      return h('div', { class: 'text-center font-medium' }, row.getValue('last_name'))
 | 
				
			||||||
@@ -24,7 +24,7 @@ export const createColumns = (t) => [
 | 
				
			|||||||
  {
 | 
					  {
 | 
				
			||||||
    accessorKey: 'enabled',
 | 
					    accessorKey: 'enabled',
 | 
				
			||||||
    header: function () {
 | 
					    header: function () {
 | 
				
			||||||
      return h('div', { class: 'text-center' }, t('form.field.enabled'))
 | 
					      return h('div', { class: 'text-center' }, t('globals.terms.enabled'))
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    cell: function ({ row }) {
 | 
					    cell: function ({ row }) {
 | 
				
			||||||
      return h('div', { class: 'text-center font-medium' }, row.getValue('enabled') ? t('globals.messages.yes') : t('globals.messages.no'))
 | 
					      return h('div', { class: 'text-center font-medium' }, row.getValue('enabled') ? t('globals.messages.yes') : t('globals.messages.no'))
 | 
				
			||||||
@@ -33,7 +33,7 @@ export const createColumns = (t) => [
 | 
				
			|||||||
  {
 | 
					  {
 | 
				
			||||||
    accessorKey: 'email',
 | 
					    accessorKey: 'email',
 | 
				
			||||||
    header: function () {
 | 
					    header: function () {
 | 
				
			||||||
      return h('div', { class: 'text-center' }, t('form.field.email'))
 | 
					      return h('div', { class: 'text-center' }, t('globals.terms.email'))
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    cell: function ({ row }) {
 | 
					    cell: function ({ row }) {
 | 
				
			||||||
      return h('div', { class: 'text-center font-medium' }, row.getValue('email'))
 | 
					      return h('div', { class: 'text-center font-medium' }, row.getValue('email'))
 | 
				
			||||||
@@ -42,7 +42,7 @@ export const createColumns = (t) => [
 | 
				
			|||||||
  {
 | 
					  {
 | 
				
			||||||
    accessorKey: 'created_at',
 | 
					    accessorKey: 'created_at',
 | 
				
			||||||
    header: function () {
 | 
					    header: function () {
 | 
				
			||||||
      return h('div', { class: 'text-center' }, t('form.field.createdAt'))
 | 
					      return h('div', { class: 'text-center' }, t('globals.terms.createdAt'))
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    cell: function ({ row }) {
 | 
					    cell: function ({ row }) {
 | 
				
			||||||
      return h(
 | 
					      return h(
 | 
				
			||||||
@@ -55,7 +55,7 @@ export const createColumns = (t) => [
 | 
				
			|||||||
  {
 | 
					  {
 | 
				
			||||||
    accessorKey: 'updated_at',
 | 
					    accessorKey: 'updated_at',
 | 
				
			||||||
    header: function () {
 | 
					    header: function () {
 | 
				
			||||||
      return h('div', { class: 'text-center' }, t('form.field.updatedAt'))
 | 
					      return h('div', { class: 'text-center' }, t('globals.terms.updatedAt'))
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    cell: function ({ row }) {
 | 
					    cell: function ({ row }) {
 | 
				
			||||||
      return h(
 | 
					      return h(
 | 
				
			||||||
@@ -8,10 +8,10 @@
 | 
				
			|||||||
    </DropdownMenuTrigger>
 | 
					    </DropdownMenuTrigger>
 | 
				
			||||||
    <DropdownMenuContent>
 | 
					    <DropdownMenuContent>
 | 
				
			||||||
      <DropdownMenuItem @click="editUser(props.user.id)">{{
 | 
					      <DropdownMenuItem @click="editUser(props.user.id)">{{
 | 
				
			||||||
        $t('globals.buttons.edit')
 | 
					        $t('globals.messages.edit')
 | 
				
			||||||
      }}</DropdownMenuItem>
 | 
					      }}</DropdownMenuItem>
 | 
				
			||||||
      <DropdownMenuItem @click="() => (alertOpen = true)">{{
 | 
					      <DropdownMenuItem @click="() => (alertOpen = true)">{{
 | 
				
			||||||
        $t('globals.buttons.delete')
 | 
					        $t('globals.messages.delete')
 | 
				
			||||||
      }}</DropdownMenuItem>
 | 
					      }}</DropdownMenuItem>
 | 
				
			||||||
    </DropdownMenuContent>
 | 
					    </DropdownMenuContent>
 | 
				
			||||||
  </DropdownMenu>
 | 
					  </DropdownMenu>
 | 
				
			||||||
@@ -20,12 +20,12 @@
 | 
				
			|||||||
    <AlertDialogContent>
 | 
					    <AlertDialogContent>
 | 
				
			||||||
      <AlertDialogHeader>
 | 
					      <AlertDialogHeader>
 | 
				
			||||||
        <AlertDialogTitle>{{ $t('globals.messages.areYouAbsolutelySure') }}</AlertDialogTitle>
 | 
					        <AlertDialogTitle>{{ $t('globals.messages.areYouAbsolutelySure') }}</AlertDialogTitle>
 | 
				
			||||||
        <AlertDialogDescription>{{ $t('admin.user.deleteConfirmation') }}</AlertDialogDescription>
 | 
					        <AlertDialogDescription>{{ $t('admin.agent.deleteConfirmation') }}</AlertDialogDescription>
 | 
				
			||||||
      </AlertDialogHeader>
 | 
					      </AlertDialogHeader>
 | 
				
			||||||
      <AlertDialogFooter>
 | 
					      <AlertDialogFooter>
 | 
				
			||||||
        <AlertDialogCancel>{{ $t('globals.buttons.cancel') }}</AlertDialogCancel>
 | 
					        <AlertDialogCancel>{{ $t('globals.messages.cancel') }}</AlertDialogCancel>
 | 
				
			||||||
        <AlertDialogAction @click="handleDelete">{{
 | 
					        <AlertDialogAction @click="handleDelete">{{
 | 
				
			||||||
          $t('globals.buttons.delete')
 | 
					          $t('globals.messages.delete')
 | 
				
			||||||
        }}</AlertDialogAction>
 | 
					        }}</AlertDialogAction>
 | 
				
			||||||
      </AlertDialogFooter>
 | 
					      </AlertDialogFooter>
 | 
				
			||||||
    </AlertDialogContent>
 | 
					    </AlertDialogContent>
 | 
				
			||||||
@@ -40,7 +40,7 @@ import {
 | 
				
			|||||||
  DropdownMenuContent,
 | 
					  DropdownMenuContent,
 | 
				
			||||||
  DropdownMenuItem,
 | 
					  DropdownMenuItem,
 | 
				
			||||||
  DropdownMenuTrigger
 | 
					  DropdownMenuTrigger
 | 
				
			||||||
} from '@/components/ui/dropdown-menu'
 | 
					} from '@shared-ui/components/ui/dropdown-menu'
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  AlertDialog,
 | 
					  AlertDialog,
 | 
				
			||||||
  AlertDialogAction,
 | 
					  AlertDialogAction,
 | 
				
			||||||
@@ -50,13 +50,13 @@ import {
 | 
				
			|||||||
  AlertDialogFooter,
 | 
					  AlertDialogFooter,
 | 
				
			||||||
  AlertDialogHeader,
 | 
					  AlertDialogHeader,
 | 
				
			||||||
  AlertDialogTitle
 | 
					  AlertDialogTitle
 | 
				
			||||||
} from '@/components/ui/alert-dialog'
 | 
					} from '@shared-ui/components/ui/alert-dialog'
 | 
				
			||||||
import { Button } from '@/components/ui/button'
 | 
					import { Button } from '@shared-ui/components/ui/button'
 | 
				
			||||||
import { useRouter } from 'vue-router'
 | 
					import { useRouter } from 'vue-router'
 | 
				
			||||||
import { useEmitter } from '@/composables/useEmitter'
 | 
					import { useEmitter } from '../../../composables/useEmitter'
 | 
				
			||||||
import { handleHTTPError } from '@/utils/http'
 | 
					import { handleHTTPError } from '../../../utils/http'
 | 
				
			||||||
import { EMITTER_EVENTS } from '@/constants/emitterEvents.js'
 | 
					import { EMITTER_EVENTS } from '../../../constants/emitterEvents.js'
 | 
				
			||||||
import api from '@/api'
 | 
					import api from '../../../api'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const alertOpen = ref(false)
 | 
					const alertOpen = ref(false)
 | 
				
			||||||
const emit = useEmitter()
 | 
					const emit = useEmitter()
 | 
				
			||||||
@@ -32,18 +32,22 @@ export const createFormSchema = (t) => z.object({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  teams: z.array(z.string()).default([]),
 | 
					  teams: z.array(z.string()).default([]),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  roles: z.array(z.string()).min(1, t('globals.messages.pleaseSelectAtLeastOne', {
 | 
					  roles: z.array(z.string()).min(1, t('globals.messages.selectAtLeastOne', {
 | 
				
			||||||
    name: t('globals.terms.role')
 | 
					    name: t('globals.terms.role')
 | 
				
			||||||
  })),
 | 
					  })),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  new_password: z
 | 
					  new_password: z
 | 
				
			||||||
    .string()
 | 
					    .string()
 | 
				
			||||||
    .regex(/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[\W_]).{10,72}$/, {
 | 
					    .min(10, {
 | 
				
			||||||
      message: t('globals.messages.strongPassword', {
 | 
					      message: t('globals.messages.strongPassword', { min: 10, max: 72 })
 | 
				
			||||||
        min: 10,
 | 
					 | 
				
			||||||
        max: 72,
 | 
					 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
 | 
					    .max(72, {
 | 
				
			||||||
 | 
					      message: t('globals.messages.strongPassword', { min: 10, max: 72 })
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
 | 
					    .refine(val => /[a-z]/.test(val), t('globals.messages.strongPassword', { min: 10, max: 72 }))
 | 
				
			||||||
 | 
					    .refine(val => /[A-Z]/.test(val), t('globals.messages.strongPassword', { min: 10, max: 72 }))
 | 
				
			||||||
 | 
					    .refine(val => /\d/.test(val), t('globals.messages.strongPassword', { min: 10, max: 72 }))
 | 
				
			||||||
 | 
					    .refine(val => /[\W_]/.test(val), t('globals.messages.strongPassword', { min: 10, max: 72 }))
 | 
				
			||||||
    .optional(),
 | 
					    .optional(),
 | 
				
			||||||
  enabled: z.boolean().optional().default(true),
 | 
					  enabled: z.boolean().optional().default(true),
 | 
				
			||||||
  availability_status: z.string().optional().default('offline'),
 | 
					  availability_status: z.string().optional().default('offline'),
 | 
				
			||||||
							
								
								
									
										378
									
								
								frontend/apps/main/src/features/admin/agents/schema.test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										378
									
								
								frontend/apps/main/src/features/admin/agents/schema.test.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,378 @@
 | 
				
			|||||||
 | 
					import { describe, test, expect } from 'vitest'
 | 
				
			||||||
 | 
					import { createFormSchema } from './formSchema'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const mockT = (key, params) => `${key} ${JSON.stringify(params || {})}`
 | 
				
			||||||
 | 
					const schema = createFormSchema(mockT)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const validForm = {
 | 
				
			||||||
 | 
					    first_name: 'John',
 | 
				
			||||||
 | 
					    email: 'test@test.com',
 | 
				
			||||||
 | 
					    roles: ['admin'],
 | 
				
			||||||
 | 
					    new_password: 'Password123!'
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					describe('Form Schema', () => {
 | 
				
			||||||
 | 
					    // Valid cases
 | 
				
			||||||
 | 
					    test('valid complete form', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse(validForm)).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('valid minimal form', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({
 | 
				
			||||||
 | 
					            first_name: 'Jo',
 | 
				
			||||||
 | 
					            email: 'a@b.co',
 | 
				
			||||||
 | 
					            roles: ['user']
 | 
				
			||||||
 | 
					        })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // First name tests
 | 
				
			||||||
 | 
					    test('first_name too short', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, first_name: 'J' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('first_name too long', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, first_name: 'a'.repeat(51) })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('first_name missing', () => {
 | 
				
			||||||
 | 
					        const { first_name, ...form } = validForm
 | 
				
			||||||
 | 
					        expect(() => schema.parse(form)).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('first_name empty string', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, first_name: '' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('first_name null', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, first_name: null })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Email tests
 | 
				
			||||||
 | 
					    test('invalid email format', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, email: 'invalid' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('email missing @', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, email: 'test.com' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('email missing domain', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, email: 'test@' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('email empty', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, email: '' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('email missing', () => {
 | 
				
			||||||
 | 
					        const { email, ...form } = validForm
 | 
				
			||||||
 | 
					        expect(() => schema.parse(form)).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Roles tests
 | 
				
			||||||
 | 
					    test('roles empty array', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, roles: [] })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('roles missing', () => {
 | 
				
			||||||
 | 
					        const { roles, ...form } = validForm
 | 
				
			||||||
 | 
					        expect(() => schema.parse(form)).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('roles multiple values', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, roles: ['admin', 'user', 'moderator'] })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Password tests
 | 
				
			||||||
 | 
					    test('password too short', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Pass1!' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('password too long', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'P'.repeat(73) + 'a1!' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('password missing uppercase', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'password123!' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('password missing lowercase', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'PASSWORD123!' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('password missing number', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password!@#$' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('password missing special char', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('password only special chars', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: '!@#$%^&*()' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('password unicode special chars', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123ñ' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('password underscore as special char', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123_' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('password exactly 10 chars', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password1!' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('password exactly 72 chars', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'P'.repeat(69) + 'a1!' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Optional fields
 | 
				
			||||||
 | 
					    test('last_name optional', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse(validForm)).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, last_name: 'Doe' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, last_name: '' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('send_welcome_email optional', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, send_welcome_email: true })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, send_welcome_email: false })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('enabled defaults to true', () => {
 | 
				
			||||||
 | 
					        const result = schema.parse(validForm)
 | 
				
			||||||
 | 
					        expect(result.enabled).toBe(true)
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('availability_status defaults to offline', () => {
 | 
				
			||||||
 | 
					        const result = schema.parse(validForm)
 | 
				
			||||||
 | 
					        expect(result.availability_status).toBe('offline')
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('teams defaults to empty array', () => {
 | 
				
			||||||
 | 
					        const result = schema.parse(validForm)
 | 
				
			||||||
 | 
					        expect(result.teams).toEqual([])
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('teams with values', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, teams: ['team1', 'team2'] })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Edge cases
 | 
				
			||||||
 | 
					    test('undefined values', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({
 | 
				
			||||||
 | 
					            first_name: undefined,
 | 
				
			||||||
 | 
					            email: 'test@test.com',
 | 
				
			||||||
 | 
					            roles: ['admin']
 | 
				
			||||||
 | 
					        })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('null values', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({
 | 
				
			||||||
 | 
					            first_name: null,
 | 
				
			||||||
 | 
					            email: 'test@test.com',
 | 
				
			||||||
 | 
					            roles: ['admin']
 | 
				
			||||||
 | 
					        })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('number as string field', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, first_name: 123 })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('string as boolean field', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, enabled: 'true' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('string as array field', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, roles: 'admin' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('empty object', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({})).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('extra unknown fields ignored', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({
 | 
				
			||||||
 | 
					            ...validForm,
 | 
				
			||||||
 | 
					            unknown_field: 'value',
 | 
				
			||||||
 | 
					            another_field: 123
 | 
				
			||||||
 | 
					        })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Password regex validation tests
 | 
				
			||||||
 | 
					describe('Password Regex Validation', () => {
 | 
				
			||||||
 | 
					    // Lowercase tests
 | 
				
			||||||
 | 
					    test('lowercase - single letter', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'PASSWORD123!a' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('lowercase - multiple letters', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'PASSWORDabc123!' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('lowercase - accented characters', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'PASSWORD123!ñ' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('lowercase - none', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'PASSWORD123!' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Uppercase tests
 | 
				
			||||||
 | 
					    test('uppercase - single letter', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'passwordA123!' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('uppercase - multiple letters', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'passwordABC123!' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('uppercase - accented characters', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'passwordÑ123!' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('uppercase - none', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'password123!' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Digit tests
 | 
				
			||||||
 | 
					    test('digit - single number', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password1!' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('digit - multiple numbers', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123!' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('digit - zero', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password0!' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('digit - none', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password!' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Special character tests
 | 
				
			||||||
 | 
					    test('special - common symbols', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123!' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123@' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123#' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123$' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123%' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123^' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123&' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123*' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('special - brackets and parentheses', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123(' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123)' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123[' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123]' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123{' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123}' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('special - punctuation', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123.' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123,' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123;' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123:' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123?' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123/' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('special - quotes and backslash', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: "Password123'" })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123"' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123\\' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123|' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('special - math symbols', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123+' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123-' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123=' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123<' })).not.toThrow()
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123>' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('special - underscore', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123_' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('special - space', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123 ' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('special - none', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Combination edge cases
 | 
				
			||||||
 | 
					    test('only uppercase and special', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'PASSWORD!@#$%^&*()' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('only lowercase and digits', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'password123456' })).toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('whitespace only special char', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123   ' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('tab as special char', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123\t' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('newline as special char', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password123\n' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Password validation - passing cases
 | 
				
			||||||
 | 
					describe('Password Valid Cases', () => {
 | 
				
			||||||
 | 
					    test('exact minimum length with all requirements', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Password1!' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('exact maximum length with all requirements', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'P'.repeat(67) + 'ass1!' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('multiple of each requirement', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'PASSWORDpassword123456!@#$%^&*()' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('mixed case throughout', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'PaSSwoRD123!@#' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('numbers at start', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: '123Password!' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('special chars at start', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: '!@#Password123' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('all character types mixed', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'P@ssw0rd123!' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('unicode characters', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Påssw0rd123!' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('long valid password', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'ThisIsAVeryLongPasswordWith123!SpecialChars' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('password with spaces', () => {
 | 
				
			||||||
 | 
					        expect(() => schema.parse({ ...validForm, new_password: 'Pass Word 123!' })).not.toThrow()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
@@ -0,0 +1,305 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <Spinner v-if="formLoading"></Spinner>
 | 
				
			||||||
 | 
					  <form @submit="onSubmit" class="space-y-6 w-full" :class="{ 'opacity-50': formLoading }">
 | 
				
			||||||
 | 
					    <!-- Enabled Field -->
 | 
				
			||||||
 | 
					    <FormField v-slot="{ componentField, handleChange }" name="enabled" v-if="!isNewForm">
 | 
				
			||||||
 | 
					      <FormItem class="flex flex-row items-center justify-between rounded-lg border p-4">
 | 
				
			||||||
 | 
					        <div class="space-y-0.5">
 | 
				
			||||||
 | 
					          <FormLabel class="text-base">{{ t('globals.terms.enabled') }}</FormLabel>
 | 
				
			||||||
 | 
					          <FormDescription>{{ t('ai.assistant.enabledDescription') }}</FormDescription>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <Switch :checked="componentField.modelValue" @update:checked="handleChange" />
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- Name Field -->
 | 
				
			||||||
 | 
					    <FormField v-slot="{ componentField }" name="first_name">
 | 
				
			||||||
 | 
					      <FormItem>
 | 
				
			||||||
 | 
					        <FormLabel>{{ t('globals.terms.name') }} <span class="text-red-500">*</span></FormLabel>
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <Input
 | 
				
			||||||
 | 
					            type="text"
 | 
				
			||||||
 | 
					            :placeholder="t('ai.assistant.namePlaceholder')"
 | 
				
			||||||
 | 
					            v-bind="componentField"
 | 
				
			||||||
 | 
					          />
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					        <FormDescription>{{ t('ai.assistant.nameDescription') }}</FormDescription>
 | 
				
			||||||
 | 
					        <FormMessage />
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- Avatar url -->
 | 
				
			||||||
 | 
					    <FormField v-slot="{ componentField }" name="avatar_url">
 | 
				
			||||||
 | 
					      <FormItem>
 | 
				
			||||||
 | 
					        <FormLabel>{{ t('globals.terms.avatar') }} {{ t('globals.terms.url') }}</FormLabel>
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <Input
 | 
				
			||||||
 | 
					            type="url"
 | 
				
			||||||
 | 
					            v-bind="componentField"
 | 
				
			||||||
 | 
					          />
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					        <FormMessage></FormMessage>
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- Product Name Field -->
 | 
				
			||||||
 | 
					    <FormField v-slot="{ componentField }" name="product_name">
 | 
				
			||||||
 | 
					      <FormItem>
 | 
				
			||||||
 | 
					        <FormLabel
 | 
				
			||||||
 | 
					          >{{ t('ai.assistant.productName') }} <span class="text-red-500">*</span></FormLabel
 | 
				
			||||||
 | 
					        >
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <Input
 | 
				
			||||||
 | 
					            type="text"
 | 
				
			||||||
 | 
					            :placeholder="t('ai.assistant.productNamePlaceholder')"
 | 
				
			||||||
 | 
					            v-bind="componentField"
 | 
				
			||||||
 | 
					          />
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					        <FormDescription>{{ t('ai.assistant.productNameDescription') }}</FormDescription>
 | 
				
			||||||
 | 
					        <FormMessage />
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- Product Description Field -->
 | 
				
			||||||
 | 
					    <FormField v-slot="{ componentField }" name="product_description">
 | 
				
			||||||
 | 
					      <FormItem>
 | 
				
			||||||
 | 
					        <FormLabel
 | 
				
			||||||
 | 
					          >{{ t('ai.assistant.productDescription') }} <span class="text-red-500">*</span></FormLabel
 | 
				
			||||||
 | 
					        >
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <Textarea
 | 
				
			||||||
 | 
					            :placeholder="t('ai.assistant.productDescriptionPlaceholder')"
 | 
				
			||||||
 | 
					            v-bind="componentField"
 | 
				
			||||||
 | 
					            rows="4"
 | 
				
			||||||
 | 
					          />
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					        <FormDescription>{{ t('ai.assistant.productDescriptionDescription') }}</FormDescription>
 | 
				
			||||||
 | 
					        <FormMessage />
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- Answer Length Field -->
 | 
				
			||||||
 | 
					    <FormField v-slot="{ componentField }" name="answer_length">
 | 
				
			||||||
 | 
					      <FormItem>
 | 
				
			||||||
 | 
					        <FormLabel
 | 
				
			||||||
 | 
					          >{{ t('ai.assistant.answerLength') }} <span class="text-red-500">*</span></FormLabel
 | 
				
			||||||
 | 
					        >
 | 
				
			||||||
 | 
					        <Select v-bind="componentField">
 | 
				
			||||||
 | 
					          <FormControl>
 | 
				
			||||||
 | 
					            <SelectTrigger>
 | 
				
			||||||
 | 
					              <SelectValue :placeholder="t('ai.assistant.selectAnswerLength')" />
 | 
				
			||||||
 | 
					            </SelectTrigger>
 | 
				
			||||||
 | 
					          </FormControl>
 | 
				
			||||||
 | 
					          <SelectContent>
 | 
				
			||||||
 | 
					            <SelectItem value="concise">{{ t('ai.assistant.answerLengthConcise') }}</SelectItem>
 | 
				
			||||||
 | 
					            <SelectItem value="medium">{{ t('ai.assistant.answerLengthMedium') }}</SelectItem>
 | 
				
			||||||
 | 
					            <SelectItem value="long">{{ t('ai.assistant.answerLengthLong') }}</SelectItem>
 | 
				
			||||||
 | 
					          </SelectContent>
 | 
				
			||||||
 | 
					        </Select>
 | 
				
			||||||
 | 
					        <FormDescription>{{ t('ai.assistant.answerLengthDescription') }}</FormDescription>
 | 
				
			||||||
 | 
					        <FormMessage />
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- Answer Tone Field -->
 | 
				
			||||||
 | 
					    <FormField v-slot="{ componentField }" name="answer_tone">
 | 
				
			||||||
 | 
					      <FormItem>
 | 
				
			||||||
 | 
					        <FormLabel
 | 
				
			||||||
 | 
					          >{{ t('ai.assistant.answerTone') }} <span class="text-red-500">*</span></FormLabel
 | 
				
			||||||
 | 
					        >
 | 
				
			||||||
 | 
					        <Select v-bind="componentField">
 | 
				
			||||||
 | 
					          <FormControl>
 | 
				
			||||||
 | 
					            <SelectTrigger>
 | 
				
			||||||
 | 
					              <SelectValue :placeholder="t('ai.assistant.selectAnswerTone')" />
 | 
				
			||||||
 | 
					            </SelectTrigger>
 | 
				
			||||||
 | 
					          </FormControl>
 | 
				
			||||||
 | 
					          <SelectContent>
 | 
				
			||||||
 | 
					            <SelectItem value="neutral">{{ t('ai.assistant.answerToneNeutral') }}</SelectItem>
 | 
				
			||||||
 | 
					            <SelectItem value="friendly">{{ t('ai.assistant.answerToneFriendly') }}</SelectItem>
 | 
				
			||||||
 | 
					            <SelectItem value="professional">{{
 | 
				
			||||||
 | 
					              t('ai.assistant.answerToneProfessional')
 | 
				
			||||||
 | 
					            }}</SelectItem>
 | 
				
			||||||
 | 
					            <SelectItem value="humorous">{{ t('ai.assistant.answerToneHumorous') }}</SelectItem>
 | 
				
			||||||
 | 
					          </SelectContent>
 | 
				
			||||||
 | 
					        </Select>
 | 
				
			||||||
 | 
					        <FormDescription>{{ t('ai.assistant.answerToneDescription') }}</FormDescription>
 | 
				
			||||||
 | 
					        <FormMessage />
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- Enable Handoff Checkbox -->
 | 
				
			||||||
 | 
					    <FormField v-slot="{ componentField, handleChange }" name="hand_off">
 | 
				
			||||||
 | 
					      <FormItem class="flex flex-row items-center justify-between rounded-lg border p-4">
 | 
				
			||||||
 | 
					        <div class="space-y-0.5">
 | 
				
			||||||
 | 
					          <FormLabel class="text-base">{{ t('ai.assistant.enableHandoff') }}</FormLabel>
 | 
				
			||||||
 | 
					          <FormDescription>{{ t('ai.assistant.enableHandoffDescription') }}</FormDescription>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <Switch :checked="componentField.modelValue" @update:checked="handleChange" />
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- Hand off team (conditional) -->
 | 
				
			||||||
 | 
					    <FormField v-slot="{ componentField }" name="hand_off_team" v-if="form.values.hand_off">
 | 
				
			||||||
 | 
					      <FormItem>
 | 
				
			||||||
 | 
					        <FormLabel>{{ t('ai.assistant.conversationHandoffTeam') }}</FormLabel>
 | 
				
			||||||
 | 
					        <FormControl>
 | 
				
			||||||
 | 
					          <Select v-bind="componentField">
 | 
				
			||||||
 | 
					            <FormControl>
 | 
				
			||||||
 | 
					              <SelectTrigger>
 | 
				
			||||||
 | 
					                <SelectValue
 | 
				
			||||||
 | 
					                  :placeholder="
 | 
				
			||||||
 | 
					                    t('globals.messages.select', { name: t('globals.terms.team').toLowerCase() })
 | 
				
			||||||
 | 
					                  "
 | 
				
			||||||
 | 
					                />
 | 
				
			||||||
 | 
					              </SelectTrigger>
 | 
				
			||||||
 | 
					            </FormControl>
 | 
				
			||||||
 | 
					            <SelectContent>
 | 
				
			||||||
 | 
					              <SelectItem
 | 
				
			||||||
 | 
					                v-for="opt in teamStore.options"
 | 
				
			||||||
 | 
					                :key="opt.value"
 | 
				
			||||||
 | 
					                :value="parseInt(opt.value)"
 | 
				
			||||||
 | 
					              >
 | 
				
			||||||
 | 
					                {{ opt.label }}
 | 
				
			||||||
 | 
					              </SelectItem>
 | 
				
			||||||
 | 
					            </SelectContent>
 | 
				
			||||||
 | 
					          </Select>
 | 
				
			||||||
 | 
					        </FormControl>
 | 
				
			||||||
 | 
					        <FormMessage />
 | 
				
			||||||
 | 
					      </FormItem>
 | 
				
			||||||
 | 
					    </FormField>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- Submit Button -->
 | 
				
			||||||
 | 
					    <div class="flex justify-end">
 | 
				
			||||||
 | 
					      <Button type="submit" :disabled="formLoading">
 | 
				
			||||||
 | 
					        <template v-if="formLoading">
 | 
				
			||||||
 | 
					          <LoaderCircle class="w-4 h-4 mr-2 animate-spin" />
 | 
				
			||||||
 | 
					        </template>
 | 
				
			||||||
 | 
					        {{ isNewForm ? t('globals.messages.create') : t('globals.messages.update') }}
 | 
				
			||||||
 | 
					      </Button>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					  </form>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script setup>
 | 
				
			||||||
 | 
					import { computed, onMounted, watch } from 'vue'
 | 
				
			||||||
 | 
					import { toTypedSchema } from '@vee-validate/zod'
 | 
				
			||||||
 | 
					import { useForm } from 'vee-validate'
 | 
				
			||||||
 | 
					import { useI18n } from 'vue-i18n'
 | 
				
			||||||
 | 
					import { Button } from '@shared-ui/components/ui/button'
 | 
				
			||||||
 | 
					import { Input } from '@shared-ui/components/ui/input'
 | 
				
			||||||
 | 
					import { Textarea } from '@shared-ui/components/ui/textarea'
 | 
				
			||||||
 | 
					import { Switch } from '@shared-ui/components/ui/switch'
 | 
				
			||||||
 | 
					import {
 | 
				
			||||||
 | 
					  FormControl,
 | 
				
			||||||
 | 
					  FormDescription,
 | 
				
			||||||
 | 
					  FormField,
 | 
				
			||||||
 | 
					  FormItem,
 | 
				
			||||||
 | 
					  FormLabel,
 | 
				
			||||||
 | 
					  FormMessage
 | 
				
			||||||
 | 
					} from '@shared-ui/components/ui/form'
 | 
				
			||||||
 | 
					import {
 | 
				
			||||||
 | 
					  Select,
 | 
				
			||||||
 | 
					  SelectContent,
 | 
				
			||||||
 | 
					  SelectItem,
 | 
				
			||||||
 | 
					  SelectTrigger,
 | 
				
			||||||
 | 
					  SelectValue
 | 
				
			||||||
 | 
					} from '@shared-ui/components/ui/select'
 | 
				
			||||||
 | 
					import { Spinner } from '@shared-ui/components/ui/spinner'
 | 
				
			||||||
 | 
					import { LoaderCircle } from 'lucide-vue-next'
 | 
				
			||||||
 | 
					import { createFormSchema } from './formSchema.js'
 | 
				
			||||||
 | 
					import { useTeamStore } from '@/stores/team'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const { t } = useI18n()
 | 
				
			||||||
 | 
					const teamStore = useTeamStore()
 | 
				
			||||||
 | 
					const props = defineProps({
 | 
				
			||||||
 | 
					  initialValues: {
 | 
				
			||||||
 | 
					    type: Object,
 | 
				
			||||||
 | 
					    default: () => ({})
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  submitForm: {
 | 
				
			||||||
 | 
					    type: Function,
 | 
				
			||||||
 | 
					    required: true
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  isNewForm: {
 | 
				
			||||||
 | 
					    type: Boolean,
 | 
				
			||||||
 | 
					    default: false
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  isLoading: {
 | 
				
			||||||
 | 
					    type: Boolean,
 | 
				
			||||||
 | 
					    default: false
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const formLoading = computed(() => props.isLoading)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const formSchema = toTypedSchema(createFormSchema(t))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const form = useForm({
 | 
				
			||||||
 | 
					  validationSchema: formSchema,
 | 
				
			||||||
 | 
					  initialValues: {
 | 
				
			||||||
 | 
					    first_name: '',
 | 
				
			||||||
 | 
					    last_name: '',
 | 
				
			||||||
 | 
					    avatar_url: '',
 | 
				
			||||||
 | 
					    product_name: '',
 | 
				
			||||||
 | 
					    product_description: '',
 | 
				
			||||||
 | 
					    answer_length: 'medium',
 | 
				
			||||||
 | 
					    answer_tone: 'friendly',
 | 
				
			||||||
 | 
					    hand_off: false,
 | 
				
			||||||
 | 
					    hand_off_team: null,
 | 
				
			||||||
 | 
					    enabled: true,
 | 
				
			||||||
 | 
					    ...props.initialValues
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const onSubmit = form.handleSubmit((values) => {
 | 
				
			||||||
 | 
					  props.submitForm(values)
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Parse meta fields if editing an existing assistant
 | 
				
			||||||
 | 
					onMounted(() => {
 | 
				
			||||||
 | 
					  if (!props.isNewForm && props.initialValues?.meta) {
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      const meta =
 | 
				
			||||||
 | 
					        typeof props.initialValues.meta === 'string'
 | 
				
			||||||
 | 
					          ? JSON.parse(props.initialValues.meta)
 | 
				
			||||||
 | 
					          : props.initialValues.meta
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (meta) {
 | 
				
			||||||
 | 
					        form.setFieldValue('product_name', meta.product_name || '')
 | 
				
			||||||
 | 
					        form.setFieldValue('product_description', meta.product_description || '')
 | 
				
			||||||
 | 
					        form.setFieldValue('answer_length', meta.answer_length || 'medium')
 | 
				
			||||||
 | 
					        form.setFieldValue('answer_tone', meta.answer_tone || 'friendly')
 | 
				
			||||||
 | 
					        form.setFieldValue('hand_off', meta.hand_off || false)
 | 
				
			||||||
 | 
					        form.setFieldValue('hand_off_team', meta.hand_off_team || null)
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    } catch (e) {
 | 
				
			||||||
 | 
					      console.warn('Failed to parse AI assistant meta:', e)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Watch for changes in initialValues (for edit mode)
 | 
				
			||||||
 | 
					watch(
 | 
				
			||||||
 | 
					  () => props.initialValues,
 | 
				
			||||||
 | 
					  (newValues) => {
 | 
				
			||||||
 | 
					    if (newValues && Object.keys(newValues).length > 0) {
 | 
				
			||||||
 | 
					      form.resetForm({
 | 
				
			||||||
 | 
					        values: {
 | 
				
			||||||
 | 
					          first_name: newValues.first_name || '',
 | 
				
			||||||
 | 
					          last_name: newValues.last_name || '',
 | 
				
			||||||
 | 
					          avatar_url: newValues.avatar_url || '',
 | 
				
			||||||
 | 
					          hand_off: newValues.hand_off ?? false,
 | 
				
			||||||
 | 
					          hand_off_team: newValues.hand_off_team || null,
 | 
				
			||||||
 | 
					          enabled: newValues.enabled ?? true,
 | 
				
			||||||
 | 
					          ...newValues
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  { deep: true, immediate: true }
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
@@ -0,0 +1,81 @@
 | 
				
			|||||||
 | 
					import { h } from 'vue'
 | 
				
			||||||
 | 
					import AIAssistantDataTableDropDown from '@/features/admin/ai-assistants/dataTableDropdown.vue'
 | 
				
			||||||
 | 
					import { format } from 'date-fns'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const createColumns = (t) => [
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    accessorKey: 'first_name',
 | 
				
			||||||
 | 
					    header: function () {
 | 
				
			||||||
 | 
					      return h('div', { class: 'text-center' }, t('globals.terms.name'))
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    cell: function ({ row }) {
 | 
				
			||||||
 | 
					      return h('div', { class: 'text-center font-medium' }, row.getValue('first_name'))
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    accessorKey: 'meta',
 | 
				
			||||||
 | 
					    header: function () {
 | 
				
			||||||
 | 
					      return h('div', { class: 'text-center' }, t('globals.terms.product'))
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    cell: function ({ row }) {
 | 
				
			||||||
 | 
					      const meta = row.getValue('meta')
 | 
				
			||||||
 | 
					      let productName = ''
 | 
				
			||||||
 | 
					      try {
 | 
				
			||||||
 | 
					        const parsedMeta = typeof meta === 'string' ? JSON.parse(meta) : meta
 | 
				
			||||||
 | 
					        productName = parsedMeta?.product_name || ''
 | 
				
			||||||
 | 
					      } catch (e) {
 | 
				
			||||||
 | 
					        productName = ''
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      return h('div', { class: 'text-center font-medium' }, productName)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    accessorKey: 'enabled',
 | 
				
			||||||
 | 
					    header: function () {
 | 
				
			||||||
 | 
					      return h('div', { class: 'text-center' }, t('globals.terms.enabled'))
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    cell: function ({ row }) {
 | 
				
			||||||
 | 
					      return h('div', { class: 'text-center font-medium' }, row.getValue('enabled') ? t('globals.messages.yes') : t('globals.messages.no'))
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    accessorKey: 'created_at',
 | 
				
			||||||
 | 
					    header: function () {
 | 
				
			||||||
 | 
					      return h('div', { class: 'text-center' }, t('globals.terms.createdAt'))
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    cell: function ({ row }) {
 | 
				
			||||||
 | 
					      return h(
 | 
				
			||||||
 | 
					        'div',
 | 
				
			||||||
 | 
					        { class: 'text-center font-medium' },
 | 
				
			||||||
 | 
					        format(row.getValue('created_at'), 'PPpp')
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    accessorKey: 'updated_at',
 | 
				
			||||||
 | 
					    header: function () {
 | 
				
			||||||
 | 
					      return h('div', { class: 'text-center' }, t('globals.terms.updatedAt'))
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    cell: function ({ row }) {
 | 
				
			||||||
 | 
					      return h(
 | 
				
			||||||
 | 
					        'div',
 | 
				
			||||||
 | 
					        { class: 'text-center font-medium' },
 | 
				
			||||||
 | 
					        format(row.getValue('updated_at'), 'PPpp')
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    id: 'actions',
 | 
				
			||||||
 | 
					    enableHiding: false,
 | 
				
			||||||
 | 
					    cell: ({ row }) => {
 | 
				
			||||||
 | 
					      const assistant = row.original
 | 
				
			||||||
 | 
					      return h(
 | 
				
			||||||
 | 
					        'div',
 | 
				
			||||||
 | 
					        { class: 'relative' },
 | 
				
			||||||
 | 
					        h(AIAssistantDataTableDropDown, {
 | 
				
			||||||
 | 
					          assistant
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
@@ -0,0 +1,97 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <DropdownMenu>
 | 
				
			||||||
 | 
					    <DropdownMenuTrigger as-child>
 | 
				
			||||||
 | 
					      <Button variant="ghost" class="w-8 h-8 p-0">
 | 
				
			||||||
 | 
					        <span class="sr-only"></span>
 | 
				
			||||||
 | 
					        <MoreHorizontal class="w-4 h-4" />
 | 
				
			||||||
 | 
					      </Button>
 | 
				
			||||||
 | 
					    </DropdownMenuTrigger>
 | 
				
			||||||
 | 
					    <DropdownMenuContent>
 | 
				
			||||||
 | 
					      <DropdownMenuItem @click="editAIAssistant(props.assistant.id)">{{
 | 
				
			||||||
 | 
					        $t('globals.messages.edit')
 | 
				
			||||||
 | 
					      }}</DropdownMenuItem>
 | 
				
			||||||
 | 
					      <DropdownMenuItem @click="() => (alertOpen = true)">{{
 | 
				
			||||||
 | 
					        $t('globals.messages.delete')
 | 
				
			||||||
 | 
					      }}</DropdownMenuItem>
 | 
				
			||||||
 | 
					    </DropdownMenuContent>
 | 
				
			||||||
 | 
					  </DropdownMenu>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <AlertDialog :open="alertOpen" @update:open="alertOpen = $event">
 | 
				
			||||||
 | 
					    <AlertDialogContent>
 | 
				
			||||||
 | 
					      <AlertDialogHeader>
 | 
				
			||||||
 | 
					        <AlertDialogTitle>{{ $t('globals.messages.areYouAbsolutelySure') }}</AlertDialogTitle>
 | 
				
			||||||
 | 
					        <AlertDialogDescription>{{ $t('ai.assistant.deleteConfirmation') }}</AlertDialogDescription>
 | 
				
			||||||
 | 
					      </AlertDialogHeader>
 | 
				
			||||||
 | 
					      <AlertDialogFooter>
 | 
				
			||||||
 | 
					        <AlertDialogCancel>{{ $t('globals.messages.cancel') }}</AlertDialogCancel>
 | 
				
			||||||
 | 
					        <AlertDialogAction @click="handleDelete">{{
 | 
				
			||||||
 | 
					          $t('globals.messages.delete')
 | 
				
			||||||
 | 
					        }}</AlertDialogAction>
 | 
				
			||||||
 | 
					      </AlertDialogFooter>
 | 
				
			||||||
 | 
					    </AlertDialogContent>
 | 
				
			||||||
 | 
					  </AlertDialog>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script setup>
 | 
				
			||||||
 | 
					import { ref } from 'vue'
 | 
				
			||||||
 | 
					import { MoreHorizontal } from 'lucide-vue-next'
 | 
				
			||||||
 | 
					import {
 | 
				
			||||||
 | 
					  DropdownMenu,
 | 
				
			||||||
 | 
					  DropdownMenuContent,
 | 
				
			||||||
 | 
					  DropdownMenuItem,
 | 
				
			||||||
 | 
					  DropdownMenuTrigger
 | 
				
			||||||
 | 
					} from '@shared-ui/components/ui/dropdown-menu'
 | 
				
			||||||
 | 
					import {
 | 
				
			||||||
 | 
					  AlertDialog,
 | 
				
			||||||
 | 
					  AlertDialogAction,
 | 
				
			||||||
 | 
					  AlertDialogCancel,
 | 
				
			||||||
 | 
					  AlertDialogContent,
 | 
				
			||||||
 | 
					  AlertDialogDescription,
 | 
				
			||||||
 | 
					  AlertDialogFooter,
 | 
				
			||||||
 | 
					  AlertDialogHeader,
 | 
				
			||||||
 | 
					  AlertDialogTitle
 | 
				
			||||||
 | 
					} from '@shared-ui/components/ui/alert-dialog'
 | 
				
			||||||
 | 
					import { Button } from '@shared-ui/components/ui/button'
 | 
				
			||||||
 | 
					import { useRouter } from 'vue-router'
 | 
				
			||||||
 | 
					import { useEmitter } from '../../../composables/useEmitter'
 | 
				
			||||||
 | 
					import { handleHTTPError } from '../../../utils/http'
 | 
				
			||||||
 | 
					import { EMITTER_EVENTS } from '../../../constants/emitterEvents.js'
 | 
				
			||||||
 | 
					import api from '../../../api'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const alertOpen = ref(false)
 | 
				
			||||||
 | 
					const emit = useEmitter()
 | 
				
			||||||
 | 
					const router = useRouter()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const props = defineProps({
 | 
				
			||||||
 | 
					  assistant: {
 | 
				
			||||||
 | 
					    type: Object,
 | 
				
			||||||
 | 
					    required: true,
 | 
				
			||||||
 | 
					    default: () => ({
 | 
				
			||||||
 | 
					      id: ''
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function editAIAssistant(id) {
 | 
				
			||||||
 | 
					  router.push({ path: `/admin/ai/assistants/${id}/edit` })
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async function handleDelete() {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    await api.deleteAIAssistant(props.assistant.id)
 | 
				
			||||||
 | 
					    alertOpen.value = false
 | 
				
			||||||
 | 
					    emitRefreshAssistantList()
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    emit.emit(EMITTER_EVENTS.SHOW_TOAST, {
 | 
				
			||||||
 | 
					      variant: 'destructive',
 | 
				
			||||||
 | 
					      description: handleHTTPError(error).message
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const emitRefreshAssistantList = () => {
 | 
				
			||||||
 | 
					  emit.emit(EMITTER_EVENTS.REFRESH_LIST, {
 | 
				
			||||||
 | 
					    model: 'ai_assistant'
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
@@ -0,0 +1,89 @@
 | 
				
			|||||||
 | 
					import * as z from 'zod'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const createFormSchema = (t) => z.object({
 | 
				
			||||||
 | 
					  first_name: z
 | 
				
			||||||
 | 
					    .string({
 | 
				
			||||||
 | 
					      required_error: t('globals.messages.required'),
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    .min(2, {
 | 
				
			||||||
 | 
					      message: t('form.error.minmax', {
 | 
				
			||||||
 | 
					        min: 2,
 | 
				
			||||||
 | 
					        max: 100,
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    .max(100, {
 | 
				
			||||||
 | 
					      message: t('form.error.minmax', {
 | 
				
			||||||
 | 
					        min: 2,
 | 
				
			||||||
 | 
					        max: 100,
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    }),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  last_name: z.string().optional(),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  avatar_url: z
 | 
				
			||||||
 | 
					    .string()
 | 
				
			||||||
 | 
					    .url({
 | 
				
			||||||
 | 
					      message: t('globals.messages.invalidUrl'),
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    .optional()
 | 
				
			||||||
 | 
					    .or(z.literal('')),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  product_name: z
 | 
				
			||||||
 | 
					    .string({
 | 
				
			||||||
 | 
					      required_error: t('globals.messages.required'),
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    .min(2, {
 | 
				
			||||||
 | 
					      message: t('form.error.minmax', {
 | 
				
			||||||
 | 
					        min: 2,
 | 
				
			||||||
 | 
					        max: 255,
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    .max(255, {
 | 
				
			||||||
 | 
					      message: t('form.error.minmax', {
 | 
				
			||||||
 | 
					        min: 2,
 | 
				
			||||||
 | 
					        max: 255,
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    }),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  product_description: z
 | 
				
			||||||
 | 
					    .string({
 | 
				
			||||||
 | 
					      required_error: t('globals.messages.required'),
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    .min(10, {
 | 
				
			||||||
 | 
					      message: t('form.error.minmax', {
 | 
				
			||||||
 | 
					        min: 10,
 | 
				
			||||||
 | 
					        max: 1000,
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    .max(1000, {
 | 
				
			||||||
 | 
					      message: t('form.error.minmax', {
 | 
				
			||||||
 | 
					        min: 10,
 | 
				
			||||||
 | 
					        max: 1000,
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    }),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  answer_length: z
 | 
				
			||||||
 | 
					    .enum(['concise', 'medium', 'long'], {
 | 
				
			||||||
 | 
					      required_error: t('globals.messages.required'),
 | 
				
			||||||
 | 
					      invalid_type_error: t('globals.messages.invalid', { name: t('ai.assistant.answerLength') })
 | 
				
			||||||
 | 
					    }),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  answer_tone: z
 | 
				
			||||||
 | 
					    .enum(['neutral', 'friendly', 'professional', 'humorous'], {
 | 
				
			||||||
 | 
					      required_error: t('globals.messages.required'),
 | 
				
			||||||
 | 
					      invalid_type_error: t('globals.messages.invalid', { name: t('ai.assistant.answerTone') })
 | 
				
			||||||
 | 
					    }),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  enabled: z.boolean().optional().default(true),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  hand_off: z.boolean().optional().default(false),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  hand_off_team: z
 | 
				
			||||||
 | 
					    .number()
 | 
				
			||||||
 | 
					    .int({
 | 
				
			||||||
 | 
					      message: t('globals.messages.invalid', { name: t('globals.terms.team') })
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    .optional()
 | 
				
			||||||
 | 
					    .nullable()
 | 
				
			||||||
 | 
					    .default(null),
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <div class="space-y-5 rounded-lg" :class="{ 'box p-5': actions.length > 0 }">
 | 
					  <div class="space-y-5 rounded" :class="{ 'box p-5': actions.length > 0 }">
 | 
				
			||||||
    <div class="space-y-5">
 | 
					    <div class="space-y-5">
 | 
				
			||||||
      <div v-for="(action, index) in actions" :key="index" class="space-y-5">
 | 
					      <div v-for="(action, index) in actions" :key="index" class="space-y-5">
 | 
				
			||||||
        <div v-if="index > 0">
 | 
					        <div v-if="index > 0">
 | 
				
			||||||
@@ -16,7 +16,7 @@
 | 
				
			|||||||
                  @update:modelValue="(value) => handleFieldChange(value, index)"
 | 
					                  @update:modelValue="(value) => handleFieldChange(value, index)"
 | 
				
			||||||
                >
 | 
					                >
 | 
				
			||||||
                  <SelectTrigger class="m-auto">
 | 
					                  <SelectTrigger class="m-auto">
 | 
				
			||||||
                    <SelectValue :placeholder="t('form.field.selectAction')" />
 | 
					                    <SelectValue :placeholder="t('globals.messages.select', { name: t('globals.terms.action').toLowerCase() })" />
 | 
				
			||||||
                  </SelectTrigger>
 | 
					                  </SelectTrigger>
 | 
				
			||||||
                  <SelectContent>
 | 
					                  <SelectContent>
 | 
				
			||||||
                    <SelectGroup>
 | 
					                    <SelectGroup>
 | 
				
			||||||
@@ -40,7 +40,7 @@
 | 
				
			|||||||
                <SelectTag
 | 
					                <SelectTag
 | 
				
			||||||
                  v-model="action.value"
 | 
					                  v-model="action.value"
 | 
				
			||||||
                  :items="tagsStore.tagNames.map((tag) => ({ label: tag, value: tag }))"
 | 
					                  :items="tagsStore.tagNames.map((tag) => ({ label: tag, value: tag }))"
 | 
				
			||||||
                  :placeholder="t('form.field.selectTag')"
 | 
					                  :placeholder="t('globals.messages.select', { name: t('globals.terms.tag', 2).toLowerCase() })"
 | 
				
			||||||
                />
 | 
					                />
 | 
				
			||||||
              </div>
 | 
					              </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -48,63 +48,17 @@
 | 
				
			|||||||
                class="w-48"
 | 
					                class="w-48"
 | 
				
			||||||
                v-if="action.type && conversationActions[action.type]?.type === 'select'"
 | 
					                v-if="action.type && conversationActions[action.type]?.type === 'select'"
 | 
				
			||||||
              >
 | 
					              >
 | 
				
			||||||
                <ComboBox
 | 
					                <SelectComboBox
 | 
				
			||||||
                  v-model="action.value[0]"
 | 
					                  v-model="action.value[0]"
 | 
				
			||||||
                  :items="conversationActions[action.type]?.options"
 | 
					                  :items="conversationActions[action.type]?.options"
 | 
				
			||||||
                  :placeholder="t('form.field.select')"
 | 
					                  :placeholder="t('globals.messages.select', { name: '' })"
 | 
				
			||||||
                  @select="handleValueChange($event, index)"
 | 
					                  @select="handleValueChange($event, index)"
 | 
				
			||||||
                >
 | 
					                  :type="action.type === 'assign_team' ? 'team' : 'user'"
 | 
				
			||||||
                  <template #item="{ item }">
 | 
					 | 
				
			||||||
                    <div class="flex items-center gap-2 ml-2">
 | 
					 | 
				
			||||||
                      <Avatar v-if="action.type === 'assign_user'" class="w-7 h-7">
 | 
					 | 
				
			||||||
                        <AvatarImage :src="item.avatar_url || ''" :alt="item.label.slice(0, 2)" />
 | 
					 | 
				
			||||||
                        <AvatarFallback>
 | 
					 | 
				
			||||||
                          {{ item.label.slice(0, 2).toUpperCase() }}
 | 
					 | 
				
			||||||
                        </AvatarFallback>
 | 
					 | 
				
			||||||
                      </Avatar>
 | 
					 | 
				
			||||||
                      <span v-if="action.type === 'assign_team'">
 | 
					 | 
				
			||||||
                        {{ item.emoji }}
 | 
					 | 
				
			||||||
                      </span>
 | 
					 | 
				
			||||||
                      <span>{{ item.label }}</span>
 | 
					 | 
				
			||||||
                    </div>
 | 
					 | 
				
			||||||
                  </template>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                  <template #selected="{ selected }">
 | 
					 | 
				
			||||||
                    <div v-if="action.type === 'assign_team'">
 | 
					 | 
				
			||||||
                      <div v-if="selected" class="flex items-center gap-2">
 | 
					 | 
				
			||||||
                        {{ selected.emoji }}
 | 
					 | 
				
			||||||
                        <span>{{ selected.label }}</span>
 | 
					 | 
				
			||||||
                      </div>
 | 
					 | 
				
			||||||
                      <span v-else>{{ $t('form.field.selectTeam') }}</span>
 | 
					 | 
				
			||||||
                    </div>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    <div v-else-if="action.type === 'assign_user'" class="flex items-center gap-2">
 | 
					 | 
				
			||||||
                      <div v-if="selected" class="flex items-center gap-2">
 | 
					 | 
				
			||||||
                        <Avatar class="w-7 h-7">
 | 
					 | 
				
			||||||
                          <AvatarImage
 | 
					 | 
				
			||||||
                            :src="selected.avatar_url ?? ''"
 | 
					 | 
				
			||||||
                            :alt="selected.label.slice(0, 2)"
 | 
					 | 
				
			||||||
                />
 | 
					                />
 | 
				
			||||||
                          <AvatarFallback>
 | 
					 | 
				
			||||||
                            {{ selected.label.slice(0, 2).toUpperCase() }}
 | 
					 | 
				
			||||||
                          </AvatarFallback>
 | 
					 | 
				
			||||||
                        </Avatar>
 | 
					 | 
				
			||||||
                        <span>{{ selected.label }}</span>
 | 
					 | 
				
			||||||
                      </div>
 | 
					 | 
				
			||||||
                      <span v-else>{{ $t('form.field.selectUser') }}</span>
 | 
					 | 
				
			||||||
                    </div>
 | 
					 | 
				
			||||||
                    <span v-else>
 | 
					 | 
				
			||||||
                      <span v-if="!selected"> {{ $t('form.field.select') }}</span>
 | 
					 | 
				
			||||||
                      <span v-else>{{ selected.label }} </span>
 | 
					 | 
				
			||||||
                    </span>
 | 
					 | 
				
			||||||
                  </template>
 | 
					 | 
				
			||||||
                </ComboBox>
 | 
					 | 
				
			||||||
              </div>
 | 
					              </div>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <div class="cursor-pointer" @click.prevent="removeAction(index)">
 | 
					            <CloseButton :onClose="() => removeAction(index)" />
 | 
				
			||||||
              <X size="16" />
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          <div
 | 
					          <div
 | 
				
			||||||
@@ -112,9 +66,10 @@
 | 
				
			|||||||
            v-if="action.type && conversationActions[action.type]?.type === 'richtext'"
 | 
					            v-if="action.type && conversationActions[action.type]?.type === 'richtext'"
 | 
				
			||||||
          >
 | 
					          >
 | 
				
			||||||
            <Editor
 | 
					            <Editor
 | 
				
			||||||
 | 
					              :autoFocus="false"
 | 
				
			||||||
              v-model:htmlContent="action.value[0]"
 | 
					              v-model:htmlContent="action.value[0]"
 | 
				
			||||||
              @update:htmlContent="(value) => handleEditorChange(value, index)"
 | 
					              @update:htmlContent="(value) => handleEditorChange(value, index)"
 | 
				
			||||||
              :placeholder="t('editor.placeholder')"
 | 
					              :placeholder="t('editor.newLine') + t('editor.send') + t('editor.ctrlK')"
 | 
				
			||||||
            />
 | 
					            />
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
@@ -132,9 +87,9 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
<script setup>
 | 
					<script setup>
 | 
				
			||||||
import { toRefs } from 'vue'
 | 
					import { toRefs } from 'vue'
 | 
				
			||||||
import { Button } from '@/components/ui/button'
 | 
					import { Button } from '@shared-ui/components/ui/button'
 | 
				
			||||||
import { X } from 'lucide-vue-next'
 | 
					import CloseButton from '@main/components/button/CloseButton.vue'
 | 
				
			||||||
import { useTagStore } from '@/stores/tag'
 | 
					import { useTagStore } from '../../../stores/tag'
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  Select,
 | 
					  Select,
 | 
				
			||||||
  SelectContent,
 | 
					  SelectContent,
 | 
				
			||||||
@@ -142,14 +97,13 @@ import {
 | 
				
			|||||||
  SelectItem,
 | 
					  SelectItem,
 | 
				
			||||||
  SelectTrigger,
 | 
					  SelectTrigger,
 | 
				
			||||||
  SelectValue
 | 
					  SelectValue
 | 
				
			||||||
} from '@/components/ui/select'
 | 
					} from '@shared-ui/components/ui/select'
 | 
				
			||||||
import ComboBox from '@/components/ui/combobox/ComboBox.vue'
 | 
					import { SelectTag } from '@shared-ui/components/ui/select'
 | 
				
			||||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
 | 
					import { useConversationFilters } from '../../../composables/useConversationFilters'
 | 
				
			||||||
import { SelectTag } from '@/components/ui/select'
 | 
					import { getTextFromHTML } from '../../../utils/strings.js'
 | 
				
			||||||
import { useConversationFilters } from '@/composables/useConversationFilters'
 | 
					 | 
				
			||||||
import { getTextFromHTML } from '@/utils/strings.js'
 | 
					 | 
				
			||||||
import { useI18n } from 'vue-i18n'
 | 
					import { useI18n } from 'vue-i18n'
 | 
				
			||||||
import Editor from '@/features/conversation/ConversationTextEditor.vue'
 | 
					import Editor from '@main/components/editor/TextEditor.vue'
 | 
				
			||||||
 | 
					import SelectComboBox from '@main/components/combobox/SelectCombobox.vue'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const props = defineProps({
 | 
					const props = defineProps({
 | 
				
			||||||
  actions: {
 | 
					  actions: {
 | 
				
			||||||
@@ -34,7 +34,7 @@
 | 
				
			|||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script setup>
 | 
					<script setup>
 | 
				
			||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
 | 
					import { Tabs, TabsContent, TabsList, TabsTrigger } from '@shared-ui/components/ui/tabs'
 | 
				
			||||||
import { useI18n } from 'vue-i18n'
 | 
					import { useI18n } from 'vue-i18n'
 | 
				
			||||||
import RuleTab from './RuleTab.vue'
 | 
					import RuleTab from './RuleTab.vue'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -23,7 +23,7 @@
 | 
				
			|||||||
      </RadioGroup>
 | 
					      </RadioGroup>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <div class="space-y-5 rounded-lg" :class="{ 'box p-5': ruleGroup.rules?.length > 0 }">
 | 
					    <div class="space-y-5 rounded" :class="{ 'box p-5': ruleGroup.rules?.length > 0 }">
 | 
				
			||||||
      <div class="space-y-5">
 | 
					      <div class="space-y-5">
 | 
				
			||||||
        <div v-for="(rule, index) in ruleGroup.rules" :key="rule" class="space-y-5">
 | 
					        <div v-for="(rule, index) in ruleGroup.rules" :key="rule" class="space-y-5">
 | 
				
			||||||
          <div v-if="index > 0">
 | 
					          <div v-if="index > 0">
 | 
				
			||||||
@@ -37,7 +37,7 @@
 | 
				
			|||||||
              @update:modelValue="(value) => handleFieldChange(value, index)"
 | 
					              @update:modelValue="(value) => handleFieldChange(value, index)"
 | 
				
			||||||
            >
 | 
					            >
 | 
				
			||||||
              <SelectTrigger class="w-56">
 | 
					              <SelectTrigger class="w-56">
 | 
				
			||||||
                <SelectValue :placeholder="t('form.field.selectField')" />
 | 
					                <SelectValue :placeholder="t('globals.messages.select', { name: t('globals.terms.field').toLowerCase() })" />
 | 
				
			||||||
              </SelectTrigger>
 | 
					              </SelectTrigger>
 | 
				
			||||||
              <SelectContent>
 | 
					              <SelectContent>
 | 
				
			||||||
                <SelectGroup>
 | 
					                <SelectGroup>
 | 
				
			||||||
@@ -65,7 +65,7 @@
 | 
				
			|||||||
              @update:modelValue="(value) => handleOperatorChange(value, index)"
 | 
					              @update:modelValue="(value) => handleOperatorChange(value, index)"
 | 
				
			||||||
            >
 | 
					            >
 | 
				
			||||||
              <SelectTrigger class="w-56">
 | 
					              <SelectTrigger class="w-56">
 | 
				
			||||||
                <SelectValue :placeholder="t('form.field.selectOperator')" />
 | 
					                <SelectValue :placeholder="t('globals.messages.select', { name: t('globals.terms.operator').toLowerCase() })" />
 | 
				
			||||||
              </SelectTrigger>
 | 
					              </SelectTrigger>
 | 
				
			||||||
              <SelectContent>
 | 
					              <SelectContent>
 | 
				
			||||||
                <SelectGroup>
 | 
					                <SelectGroup>
 | 
				
			||||||
@@ -85,7 +85,7 @@
 | 
				
			|||||||
              <!-- Plain text input -->
 | 
					              <!-- Plain text input -->
 | 
				
			||||||
              <Input
 | 
					              <Input
 | 
				
			||||||
                type="text"
 | 
					                type="text"
 | 
				
			||||||
                :placeholder="t('form.field.setValue')"
 | 
					                :placeholder="t('globals.messages.set', { name: t('globals.terms.value').toLowerCase() })"
 | 
				
			||||||
                v-if="inputType(index) === 'text'"
 | 
					                v-if="inputType(index) === 'text'"
 | 
				
			||||||
                v-model="rule.value"
 | 
					                v-model="rule.value"
 | 
				
			||||||
                @update:modelValue="(value) => handleValueChange(value, index)"
 | 
					                @update:modelValue="(value) => handleValueChange(value, index)"
 | 
				
			||||||
@@ -94,7 +94,7 @@
 | 
				
			|||||||
              <!-- Number input -->
 | 
					              <!-- Number input -->
 | 
				
			||||||
              <Input
 | 
					              <Input
 | 
				
			||||||
                type="number"
 | 
					                type="number"
 | 
				
			||||||
                :placeholder="t('form.field.setValue')"
 | 
					                :placeholder="t('globals.messages.set', { name: t('globals.terms.value').toLowerCase() })"
 | 
				
			||||||
                v-if="inputType(index) === 'number'"
 | 
					                v-if="inputType(index) === 'number'"
 | 
				
			||||||
                v-model="rule.value"
 | 
					                v-model="rule.value"
 | 
				
			||||||
                @update:modelValue="(value) => handleValueChange(value, index)"
 | 
					                @update:modelValue="(value) => handleValueChange(value, index)"
 | 
				
			||||||
@@ -102,59 +102,12 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
              <!-- Select input -->
 | 
					              <!-- Select input -->
 | 
				
			||||||
              <div v-if="inputType(index) === 'select'">
 | 
					              <div v-if="inputType(index) === 'select'">
 | 
				
			||||||
                <ComboBox
 | 
					                <SelectComboBox
 | 
				
			||||||
                  v-model="rule.value"
 | 
					                  v-model="rule.value"
 | 
				
			||||||
                  :items="getFieldOptions(rule.field, rule.field_type)"
 | 
					                  :items="getFieldOptions(rule.field, rule.field_type)"
 | 
				
			||||||
                  @select="handleValueChange($event, index)"
 | 
					                  @select="handleValueChange($event, index)"
 | 
				
			||||||
                >
 | 
					                  :type="rule.field === 'assigned_user' ? 'user' : 'team'"
 | 
				
			||||||
                  <template #item="{ item }">
 | 
					 | 
				
			||||||
                    <div class="flex items-center gap-2 ml-2">
 | 
					 | 
				
			||||||
                      <Avatar v-if="rule.field === 'assigned_user'" class="w-7 h-7">
 | 
					 | 
				
			||||||
                        <AvatarImage :src="item.avatar_url || ''" :alt="item.label.slice(0, 2)" />
 | 
					 | 
				
			||||||
                        <AvatarFallback>
 | 
					 | 
				
			||||||
                          {{ item.label.slice(0, 2).toUpperCase() }}
 | 
					 | 
				
			||||||
                        </AvatarFallback>
 | 
					 | 
				
			||||||
                      </Avatar>
 | 
					 | 
				
			||||||
                      <span v-if="rule.field === 'assigned_team'">
 | 
					 | 
				
			||||||
                        {{ item.emoji }}
 | 
					 | 
				
			||||||
                      </span>
 | 
					 | 
				
			||||||
                      <span>{{ item.label }}</span>
 | 
					 | 
				
			||||||
                    </div>
 | 
					 | 
				
			||||||
                  </template>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                  <template #selected="{ selected }">
 | 
					 | 
				
			||||||
                    <div v-if="rule?.field === 'assigned_team'">
 | 
					 | 
				
			||||||
                      <div v-if="selected" class="flex items-center gap-2">
 | 
					 | 
				
			||||||
                        {{ selected.emoji }}
 | 
					 | 
				
			||||||
                        <span>{{ selected.label }}</span>
 | 
					 | 
				
			||||||
                      </div>
 | 
					 | 
				
			||||||
                      <span v-else>{{ $t('form.field.selectTeam') }}</span>
 | 
					 | 
				
			||||||
                    </div>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    <div
 | 
					 | 
				
			||||||
                      v-else-if="rule?.field === 'assigned_user'"
 | 
					 | 
				
			||||||
                      class="flex items-center gap-2"
 | 
					 | 
				
			||||||
                    >
 | 
					 | 
				
			||||||
                      <div v-if="selected" class="flex items-center gap-2">
 | 
					 | 
				
			||||||
                        <Avatar class="w-7 h-7">
 | 
					 | 
				
			||||||
                          <AvatarImage
 | 
					 | 
				
			||||||
                            :src="selected.avatar_url || ''"
 | 
					 | 
				
			||||||
                            :alt="selected.label.slice(0, 2)"
 | 
					 | 
				
			||||||
                />
 | 
					                />
 | 
				
			||||||
                          <AvatarFallback>
 | 
					 | 
				
			||||||
                            {{ selected.label.slice(0, 2).toUpperCase() }}
 | 
					 | 
				
			||||||
                          </AvatarFallback>
 | 
					 | 
				
			||||||
                        </Avatar>
 | 
					 | 
				
			||||||
                        <span>{{ selected.label }}</span>
 | 
					 | 
				
			||||||
                      </div>
 | 
					 | 
				
			||||||
                      <span v-else>{{ $t('form.field.selectUser') }}</span>
 | 
					 | 
				
			||||||
                    </div>
 | 
					 | 
				
			||||||
                    <span v-else>
 | 
					 | 
				
			||||||
                      <span v-if="!selected"> {{ $t('form.field.select') }}</span>
 | 
					 | 
				
			||||||
                      <span v-else>{{ selected.label }} </span>
 | 
					 | 
				
			||||||
                    </span>
 | 
					 | 
				
			||||||
                  </template>
 | 
					 | 
				
			||||||
                </ComboBox>
 | 
					 | 
				
			||||||
              </div>
 | 
					              </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              <!-- Tag input -->
 | 
					              <!-- Tag input -->
 | 
				
			||||||
@@ -171,7 +124,7 @@
 | 
				
			|||||||
                    <TagsInputItemText />
 | 
					                    <TagsInputItemText />
 | 
				
			||||||
                    <TagsInputItemDelete />
 | 
					                    <TagsInputItemDelete />
 | 
				
			||||||
                  </TagsInputItem>
 | 
					                  </TagsInputItem>
 | 
				
			||||||
                  <TagsInputInput :placeholder="t('form.field.selectValue')" />
 | 
					                  <TagsInputInput :placeholder="t('globals.messages.select', { name: t('globals.terms.value').toLowerCase() })" />
 | 
				
			||||||
                </TagsInput>
 | 
					                </TagsInput>
 | 
				
			||||||
                <p class="text-xs text-gray-500 mt-1">
 | 
					                <p class="text-xs text-gray-500 mt-1">
 | 
				
			||||||
                  {{ $t('globals.messages.pressEnterToSelectAValue') }}
 | 
					                  {{ $t('globals.messages.pressEnterToSelectAValue') }}
 | 
				
			||||||
@@ -181,7 +134,7 @@
 | 
				
			|||||||
              <!-- Date input -->
 | 
					              <!-- Date input -->
 | 
				
			||||||
              <Input
 | 
					              <Input
 | 
				
			||||||
                type="date"
 | 
					                type="date"
 | 
				
			||||||
                :placeholder="t('form.field.setValue')"
 | 
					                :placeholder="t('globals.messages.set', { name: t('globals.terms.value').toLowerCase() })"
 | 
				
			||||||
                v-if="inputType(index) === 'date'"
 | 
					                v-if="inputType(index) === 'date'"
 | 
				
			||||||
                v-model="rule.value"
 | 
					                v-model="rule.value"
 | 
				
			||||||
                @update:modelValue="(value) => handleValueChange(value, index)"
 | 
					                @update:modelValue="(value) => handleValueChange(value, index)"
 | 
				
			||||||
@@ -194,7 +147,7 @@
 | 
				
			|||||||
                v-if="inputType(index) === 'boolean'"
 | 
					                v-if="inputType(index) === 'boolean'"
 | 
				
			||||||
              >
 | 
					              >
 | 
				
			||||||
                <SelectTrigger>
 | 
					                <SelectTrigger>
 | 
				
			||||||
                  <SelectValue :placeholder="t('form.field.selectValue')" />
 | 
					                  <SelectValue :placeholder="t('globals.messages.select', { name: t('globals.terms.value').toLowerCase() })" />
 | 
				
			||||||
                </SelectTrigger>
 | 
					                </SelectTrigger>
 | 
				
			||||||
                <SelectContent>
 | 
					                <SelectContent>
 | 
				
			||||||
                  <SelectGroup>
 | 
					                  <SelectGroup>
 | 
				
			||||||
@@ -209,9 +162,7 @@
 | 
				
			|||||||
            <div v-else class="flex-1"></div>
 | 
					            <div v-else class="flex-1"></div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <!-- Remove condition -->
 | 
					            <!-- Remove condition -->
 | 
				
			||||||
            <div class="cursor-pointer mt-2" @click.prevent="removeCondition(index)">
 | 
					            <CloseButton :onClose="() => removeCondition(index)" />
 | 
				
			||||||
              <X size="16" />
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          <div class="flex items-center space-x-2">
 | 
					          <div class="flex items-center space-x-2">
 | 
				
			||||||
@@ -239,9 +190,10 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
<script setup>
 | 
					<script setup>
 | 
				
			||||||
import { toRefs, computed, watch } from 'vue'
 | 
					import { toRefs, computed, watch } from 'vue'
 | 
				
			||||||
import { Checkbox } from '@/components/ui/checkbox'
 | 
					import { Checkbox } from '@shared-ui/components/ui/checkbox'
 | 
				
			||||||
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
 | 
					import { RadioGroup, RadioGroupItem } from '@shared-ui/components/ui/radio-group'
 | 
				
			||||||
import { Button } from '@/components/ui/button'
 | 
					import { Button } from '@shared-ui/components/ui/button'
 | 
				
			||||||
 | 
					import CloseButton from '@main/components/button/CloseButton.vue'
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  Select,
 | 
					  Select,
 | 
				
			||||||
  SelectContent,
 | 
					  SelectContent,
 | 
				
			||||||
@@ -250,21 +202,19 @@ import {
 | 
				
			|||||||
  SelectLabel,
 | 
					  SelectLabel,
 | 
				
			||||||
  SelectTrigger,
 | 
					  SelectTrigger,
 | 
				
			||||||
  SelectValue
 | 
					  SelectValue
 | 
				
			||||||
} from '@/components/ui/select'
 | 
					} from '@shared-ui/components/ui/select'
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  TagsInput,
 | 
					  TagsInput,
 | 
				
			||||||
  TagsInputInput,
 | 
					  TagsInputInput,
 | 
				
			||||||
  TagsInputItem,
 | 
					  TagsInputItem,
 | 
				
			||||||
  TagsInputItemDelete,
 | 
					  TagsInputItemDelete,
 | 
				
			||||||
  TagsInputItemText
 | 
					  TagsInputItemText
 | 
				
			||||||
} from '@/components/ui/tags-input'
 | 
					} from '@shared-ui/components/ui/tags-input'
 | 
				
			||||||
import { X } from 'lucide-vue-next'
 | 
					import { Label } from '@shared-ui/components/ui/label'
 | 
				
			||||||
import { Label } from '@/components/ui/label'
 | 
					import { Input } from '@shared-ui/components/ui/input'
 | 
				
			||||||
import { Input } from '@/components/ui/input'
 | 
					 | 
				
			||||||
import ComboBox from '@/components/ui/combobox/ComboBox.vue'
 | 
					 | 
				
			||||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
 | 
					 | 
				
			||||||
import { useI18n } from 'vue-i18n'
 | 
					import { useI18n } from 'vue-i18n'
 | 
				
			||||||
import { useConversationFilters } from '@/composables/useConversationFilters'
 | 
					import { useConversationFilters } from '../../../composables/useConversationFilters'
 | 
				
			||||||
 | 
					import SelectComboBox from '@main/components/combobox/SelectCombobox.vue'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const props = defineProps({
 | 
					const props = defineProps({
 | 
				
			||||||
  ruleGroup: {
 | 
					  ruleGroup: {
 | 
				
			||||||
@@ -7,8 +7,8 @@
 | 
				
			|||||||
            {{ rule.name }}
 | 
					            {{ rule.name }}
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
          <div class="mb-1">
 | 
					          <div class="mb-1">
 | 
				
			||||||
            <Badge v-if="rule.enabled" class="text-[9px]">{{ $t('form.field.enabled') }}</Badge>
 | 
					            <Badge v-if="rule.enabled" class="text-[9px]">{{ $t('globals.terms.enabled') }}</Badge>
 | 
				
			||||||
            <Badge v-else variant="secondary">{{ $t('form.field.disabled') }}</Badge>
 | 
					            <Badge v-else variant="secondary">{{ $t('globals.terms.disabled') }}</Badge>
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
        </span>
 | 
					        </span>
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
@@ -21,16 +21,16 @@
 | 
				
			|||||||
          </DropdownMenuTrigger>
 | 
					          </DropdownMenuTrigger>
 | 
				
			||||||
          <DropdownMenuContent>
 | 
					          <DropdownMenuContent>
 | 
				
			||||||
            <DropdownMenuItem @click="navigateToEditRule(rule.id)">
 | 
					            <DropdownMenuItem @click="navigateToEditRule(rule.id)">
 | 
				
			||||||
              <span>{{ $t('globals.buttons.edit') }}</span>
 | 
					              <span>{{ $t('globals.messages.edit') }}</span>
 | 
				
			||||||
            </DropdownMenuItem>
 | 
					            </DropdownMenuItem>
 | 
				
			||||||
            <DropdownMenuItem @click="() => (alertOpen = true)">
 | 
					            <DropdownMenuItem @click="() => (alertOpen = true)">
 | 
				
			||||||
              <span>{{ $t('globals.buttons.delete') }}</span>
 | 
					              <span>{{ $t('globals.messages.delete') }}</span>
 | 
				
			||||||
            </DropdownMenuItem>
 | 
					            </DropdownMenuItem>
 | 
				
			||||||
            <DropdownMenuItem @click="$emit('toggle-rule', rule.id)" v-if="rule.enabled">
 | 
					            <DropdownMenuItem @click="$emit('toggle-rule', rule.id)" v-if="rule.enabled">
 | 
				
			||||||
              <span>{{ $t('globals.buttons.disable') }}</span>
 | 
					              <span>{{ $t('globals.messages.disable') }}</span>
 | 
				
			||||||
            </DropdownMenuItem>
 | 
					            </DropdownMenuItem>
 | 
				
			||||||
            <DropdownMenuItem @click="$emit('toggle-rule', rule.id)" v-else>
 | 
					            <DropdownMenuItem @click="$emit('toggle-rule', rule.id)" v-else>
 | 
				
			||||||
              <span>{{ $t('globals.buttons.enable') }}</span>
 | 
					              <span>{{ $t('globals.messages.enable') }}</span>
 | 
				
			||||||
            </DropdownMenuItem>
 | 
					            </DropdownMenuItem>
 | 
				
			||||||
          </DropdownMenuContent>
 | 
					          </DropdownMenuContent>
 | 
				
			||||||
        </DropdownMenu>
 | 
					        </DropdownMenu>
 | 
				
			||||||
@@ -44,13 +44,17 @@
 | 
				
			|||||||
      <AlertDialogHeader>
 | 
					      <AlertDialogHeader>
 | 
				
			||||||
        <AlertDialogTitle>{{ $t('globals.messages.areYouAbsolutelySure') }}</AlertDialogTitle>
 | 
					        <AlertDialogTitle>{{ $t('globals.messages.areYouAbsolutelySure') }}</AlertDialogTitle>
 | 
				
			||||||
        <AlertDialogDescription>
 | 
					        <AlertDialogDescription>
 | 
				
			||||||
          {{ $t('admin.automation.deleteConfirmation') }}
 | 
					          {{
 | 
				
			||||||
 | 
					            $t('globals.messages.deletionConfirmation', {
 | 
				
			||||||
 | 
					              name: $t('globals.terms.automationRule').toLowerCase()
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					          }}
 | 
				
			||||||
        </AlertDialogDescription>
 | 
					        </AlertDialogDescription>
 | 
				
			||||||
      </AlertDialogHeader>
 | 
					      </AlertDialogHeader>
 | 
				
			||||||
      <AlertDialogFooter>
 | 
					      <AlertDialogFooter>
 | 
				
			||||||
        <AlertDialogCancel>{{ $t('globals.buttons.cancel') }}</AlertDialogCancel>
 | 
					        <AlertDialogCancel>{{ $t('globals.messages.cancel') }}</AlertDialogCancel>
 | 
				
			||||||
        <AlertDialogAction @click="handleDelete">{{
 | 
					        <AlertDialogAction @click="handleDelete">{{
 | 
				
			||||||
          $t('globals.buttons.delete')
 | 
					          $t('globals.messages.delete')
 | 
				
			||||||
        }}</AlertDialogAction>
 | 
					        }}</AlertDialogAction>
 | 
				
			||||||
      </AlertDialogFooter>
 | 
					      </AlertDialogFooter>
 | 
				
			||||||
    </AlertDialogContent>
 | 
					    </AlertDialogContent>
 | 
				
			||||||
@@ -64,7 +68,7 @@ import {
 | 
				
			|||||||
  DropdownMenuContent,
 | 
					  DropdownMenuContent,
 | 
				
			||||||
  DropdownMenuItem,
 | 
					  DropdownMenuItem,
 | 
				
			||||||
  DropdownMenuTrigger
 | 
					  DropdownMenuTrigger
 | 
				
			||||||
} from '@/components/ui/dropdown-menu'
 | 
					} from '@shared-ui/components/ui/dropdown-menu'
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  AlertDialog,
 | 
					  AlertDialog,
 | 
				
			||||||
  AlertDialogAction,
 | 
					  AlertDialogAction,
 | 
				
			||||||
@@ -74,10 +78,10 @@ import {
 | 
				
			|||||||
  AlertDialogFooter,
 | 
					  AlertDialogFooter,
 | 
				
			||||||
  AlertDialogHeader,
 | 
					  AlertDialogHeader,
 | 
				
			||||||
  AlertDialogTitle
 | 
					  AlertDialogTitle
 | 
				
			||||||
} from '@/components/ui/alert-dialog'
 | 
					} from '@shared-ui/components/ui/alert-dialog'
 | 
				
			||||||
import { EllipsisVertical } from 'lucide-vue-next'
 | 
					import { EllipsisVertical } from 'lucide-vue-next'
 | 
				
			||||||
import { useRouter } from 'vue-router'
 | 
					import { useRouter } from 'vue-router'
 | 
				
			||||||
import { Badge } from '@/components/ui/badge'
 | 
					import { Badge } from '@shared-ui/components/ui/badge'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const router = useRouter()
 | 
					const router = useRouter()
 | 
				
			||||||
const alertOpen = ref(false)
 | 
					const alertOpen = ref(false)
 | 
				
			||||||
@@ -23,6 +23,21 @@
 | 
				
			|||||||
      </Select>
 | 
					      </Select>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <div
 | 
				
			||||||
 | 
					      v-if="!isLoading && rules.length === 0"
 | 
				
			||||||
 | 
					      class="flex flex-col items-center justify-center py-12 px-4"
 | 
				
			||||||
 | 
					    >
 | 
				
			||||||
 | 
					      <div class="text-center space-y-2">
 | 
				
			||||||
 | 
					        <p class="text-muted-foreground">
 | 
				
			||||||
 | 
					          {{
 | 
				
			||||||
 | 
					            $t('globals.messages.noResults', {
 | 
				
			||||||
 | 
					              name: $t('globals.terms.rule', 2).toLowerCase()
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					          }}
 | 
				
			||||||
 | 
					        </p>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <div class="space-y-4">
 | 
					    <div class="space-y-4">
 | 
				
			||||||
      <div v-if="type === 'new_conversation'">
 | 
					      <div v-if="type === 'new_conversation'">
 | 
				
			||||||
        <draggable v-model="rules" class="space-y-5" item-key="id" @end="onDragEnd">
 | 
					        <draggable v-model="rules" class="space-y-5" item-key="id" @end="onDragEnd">
 | 
				
			||||||
@@ -49,17 +64,17 @@
 | 
				
			|||||||
<script setup>
 | 
					<script setup>
 | 
				
			||||||
import { ref, onMounted, watch } from 'vue'
 | 
					import { ref, onMounted, watch } from 'vue'
 | 
				
			||||||
import RuleList from './RuleList.vue'
 | 
					import RuleList from './RuleList.vue'
 | 
				
			||||||
import { Spinner } from '@/components/ui/spinner'
 | 
					import { Spinner } from '@shared-ui/components/ui/spinner'
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  Select,
 | 
					  Select,
 | 
				
			||||||
  SelectContent,
 | 
					  SelectContent,
 | 
				
			||||||
  SelectItem,
 | 
					  SelectItem,
 | 
				
			||||||
  SelectTrigger,
 | 
					  SelectTrigger,
 | 
				
			||||||
  SelectValue
 | 
					  SelectValue
 | 
				
			||||||
} from '@/components/ui/select'
 | 
					} from '@shared-ui/components/ui/select'
 | 
				
			||||||
import { Settings } from 'lucide-vue-next'
 | 
					import { Settings } from 'lucide-vue-next'
 | 
				
			||||||
import draggable from 'vuedraggable'
 | 
					import draggable from 'vuedraggable'
 | 
				
			||||||
import api from '@/api'
 | 
					import api from '../../../api'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const isLoading = ref(false)
 | 
					const isLoading = ref(false)
 | 
				
			||||||
const rules = ref([])
 | 
					const rules = ref([])
 | 
				
			||||||
@@ -18,7 +18,7 @@ export const createFormSchema = (t) => z
 | 
				
			|||||||
        if (data.type === 'conversation_update' && (!data.events || data.events.length === 0)) {
 | 
					        if (data.type === 'conversation_update' && (!data.events || data.events.length === 0)) {
 | 
				
			||||||
            ctx.addIssue({
 | 
					            ctx.addIssue({
 | 
				
			||||||
                path: ['events'],
 | 
					                path: ['events'],
 | 
				
			||||||
                message: t('globals.messages.pleaseSelectAtLeastOne', {
 | 
					                message: t('globals.messages.selectAtLeastOne', {
 | 
				
			||||||
                    name: t('globals.terms.event')
 | 
					                    name: t('globals.terms.event')
 | 
				
			||||||
                }),
 | 
					                }),
 | 
				
			||||||
                code: z.ZodIssueCode.custom,
 | 
					                code: z.ZodIssueCode.custom,
 | 
				
			||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user