elevenlabs-webhook-nodejs 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +27 -0
- package/.dockerignore +6 -0
- package/.env.example +43 -0
- package/BEFORE-PRODUCTION.md +32 -0
- package/Dockerfile +23 -0
- package/SYSTEM_OVERVIEW.md +942 -0
- package/SYSTEM_STATUS.md +332 -0
- package/backup_script/main.py +146 -0
- package/baileys/.dockerignore +7 -0
- package/baileys/Dockerfile +13 -0
- package/baileys/README.md +412 -0
- package/baileys/index.js +499 -0
- package/baileys/package-lock.json +2532 -0
- package/baileys/package.json +25 -0
- package/baileys/server.js +96 -0
- package/baileys/src/config.js +55 -0
- package/baileys/src/middleware/api-key.js +16 -0
- package/baileys/src/routes/accounts.js +51 -0
- package/baileys/src/routes/chats.js +103 -0
- package/baileys/src/routes/webhooks.js +34 -0
- package/baileys/src/services/account-store.js +259 -0
- package/baileys/src/services/webhook-dispatcher.js +161 -0
- package/baileys/src/services/worker-manager.js +597 -0
- package/baileys/src/utils/jid.js +79 -0
- package/baileys/src/utils/logger.js +16 -0
- package/baileys/src/utils/use-mongodb-auth-state.js +122 -0
- package/baileys/worker.js +721 -0
- package/dist/app.d.ts +1 -0
- package/dist/app.js +84 -0
- package/dist/app.js.map +1 -0
- package/dist/config/agentPrompts.json +19 -0
- package/dist/config/database.d.ts +1 -0
- package/dist/config/database.js +26 -0
- package/dist/config/database.js.map +1 -0
- package/dist/config/env.d.ts +41 -0
- package/dist/config/env.js +81 -0
- package/dist/config/env.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +73 -0
- package/dist/config/index.js.map +1 -0
- package/dist/controllers/webhook.controller.d.ts +10 -0
- package/dist/controllers/webhook.controller.js +128 -0
- package/dist/controllers/webhook.controller.js.map +1 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.js +13 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/hooks/webhookValidator.d.ts +2 -0
- package/dist/hooks/webhookValidator.js +47 -0
- package/dist/hooks/webhookValidator.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations/001_session-architecture.d.ts +3 -0
- package/dist/migrations/001_session-architecture.js +119 -0
- package/dist/migrations/001_session-architecture.js.map +1 -0
- package/dist/migrations/002_agent-ref.d.ts +3 -0
- package/dist/migrations/002_agent-ref.js +55 -0
- package/dist/migrations/002_agent-ref.js.map +1 -0
- package/dist/migrations/003_shift-schedule.d.ts +3 -0
- package/dist/migrations/003_shift-schedule.js +48 -0
- package/dist/migrations/003_shift-schedule.js.map +1 -0
- package/dist/migrations/004_invert-shift-to-clinic-hours.d.ts +3 -0
- package/dist/migrations/004_invert-shift-to-clinic-hours.js +27 -0
- package/dist/migrations/004_invert-shift-to-clinic-hours.js.map +1 -0
- package/dist/migrations/005_composite-baileys-chat-ids.d.ts +3 -0
- package/dist/migrations/005_composite-baileys-chat-ids.js +47 -0
- package/dist/migrations/005_composite-baileys-chat-ids.js.map +1 -0
- package/dist/migrations/migration.model.d.ts +18 -0
- package/dist/migrations/migration.model.js +45 -0
- package/dist/migrations/migration.model.js.map +1 -0
- package/dist/migrations/migration.routes.d.ts +2 -0
- package/dist/migrations/migration.routes.js +37 -0
- package/dist/migrations/migration.routes.js.map +1 -0
- package/dist/migrations/migration.runner.d.ts +19 -0
- package/dist/migrations/migration.runner.js +74 -0
- package/dist/migrations/migration.runner.js.map +1 -0
- package/dist/models/ConversationClaim.d.ts +13 -0
- package/dist/models/ConversationClaim.js +44 -0
- package/dist/models/ConversationClaim.js.map +1 -0
- package/dist/models/ConversationEvaluation.d.ts +23 -0
- package/dist/models/ConversationEvaluation.js +92 -0
- package/dist/models/ConversationEvaluation.js.map +1 -0
- package/dist/models/Summary.d.ts +37 -0
- package/dist/models/Summary.js +78 -0
- package/dist/models/Summary.js.map +1 -0
- package/dist/models/Transcription.d.ts +34 -0
- package/dist/models/Transcription.js +71 -0
- package/dist/models/Transcription.js.map +1 -0
- package/dist/models/WhatsAppRecipient.d.ts +23 -0
- package/dist/models/WhatsAppRecipient.js +53 -0
- package/dist/models/WhatsAppRecipient.js.map +1 -0
- package/dist/modules/admin/admin.routes.d.ts +2 -0
- package/dist/modules/admin/admin.routes.js +1966 -0
- package/dist/modules/admin/admin.routes.js.map +1 -0
- package/dist/modules/admin/elevenlabs-test-chat.routes.d.ts +2 -0
- package/dist/modules/admin/elevenlabs-test-chat.routes.js +158 -0
- package/dist/modules/admin/elevenlabs-test-chat.routes.js.map +1 -0
- package/dist/modules/admin/whatsapp-test-chat.routes.d.ts +2 -0
- package/dist/modules/admin/whatsapp-test-chat.routes.js +204 -0
- package/dist/modules/admin/whatsapp-test-chat.routes.js.map +1 -0
- package/dist/modules/agents/agent.model.d.ts +38 -0
- package/dist/modules/agents/agent.model.js +92 -0
- package/dist/modules/agents/agent.model.js.map +1 -0
- package/dist/modules/agents/agent.routes.d.ts +2 -0
- package/dist/modules/agents/agent.routes.js +61 -0
- package/dist/modules/agents/agent.routes.js.map +1 -0
- package/dist/modules/appointment-validation/appointment-validation.model.d.ts +76 -0
- package/dist/modules/appointment-validation/appointment-validation.model.js +118 -0
- package/dist/modules/appointment-validation/appointment-validation.model.js.map +1 -0
- package/dist/modules/appointment-validation/appointment-validation.routes.d.ts +2 -0
- package/dist/modules/appointment-validation/appointment-validation.routes.js +202 -0
- package/dist/modules/appointment-validation/appointment-validation.routes.js.map +1 -0
- package/dist/modules/appointment-validation/appointment-validation.service.d.ts +53 -0
- package/dist/modules/appointment-validation/appointment-validation.service.js +827 -0
- package/dist/modules/appointment-validation/appointment-validation.service.js.map +1 -0
- package/dist/modules/auth/auth.model.d.ts +17 -0
- package/dist/modules/auth/auth.model.js +64 -0
- package/dist/modules/auth/auth.model.js.map +1 -0
- package/dist/modules/auth/auth.routes.d.ts +2 -0
- package/dist/modules/auth/auth.routes.js +202 -0
- package/dist/modules/auth/auth.routes.js.map +1 -0
- package/dist/modules/auth/auth.service.d.ts +28 -0
- package/dist/modules/auth/auth.service.js +183 -0
- package/dist/modules/auth/auth.service.js.map +1 -0
- package/dist/modules/auth/refresh-token.model.d.ts +13 -0
- package/dist/modules/auth/refresh-token.model.js +52 -0
- package/dist/modules/auth/refresh-token.model.js.map +1 -0
- package/dist/modules/billing/billing-alert.model.d.ts +16 -0
- package/dist/modules/billing/billing-alert.model.js +47 -0
- package/dist/modules/billing/billing-alert.model.js.map +1 -0
- package/dist/modules/billing/billing-period-snapshot.model.d.ts +35 -0
- package/dist/modules/billing/billing-period-snapshot.model.js +68 -0
- package/dist/modules/billing/billing-period-snapshot.model.js.map +1 -0
- package/dist/modules/billing/billing.model.d.ts +18 -0
- package/dist/modules/billing/billing.model.js +62 -0
- package/dist/modules/billing/billing.model.js.map +1 -0
- package/dist/modules/billing/billing.routes.d.ts +2 -0
- package/dist/modules/billing/billing.routes.js +63 -0
- package/dist/modules/billing/billing.routes.js.map +1 -0
- package/dist/modules/billing/billing.service.d.ts +69 -0
- package/dist/modules/billing/billing.service.js +498 -0
- package/dist/modules/billing/billing.service.js.map +1 -0
- package/dist/modules/billing/payment.model.d.ts +24 -0
- package/dist/modules/billing/payment.model.js +57 -0
- package/dist/modules/billing/payment.model.js.map +1 -0
- package/dist/modules/calls/call.model.d.ts +41 -0
- package/dist/modules/calls/call.model.js +97 -0
- package/dist/modules/calls/call.model.js.map +1 -0
- package/dist/modules/calls/call.routes.d.ts +2 -0
- package/dist/modules/calls/call.routes.js +103 -0
- package/dist/modules/calls/call.routes.js.map +1 -0
- package/dist/modules/campaigns/campaign.model.d.ts +45 -0
- package/dist/modules/campaigns/campaign.model.js +98 -0
- package/dist/modules/campaigns/campaign.model.js.map +1 -0
- package/dist/modules/campaigns/campaign.routes.d.ts +2 -0
- package/dist/modules/campaigns/campaign.routes.js +323 -0
- package/dist/modules/campaigns/campaign.routes.js.map +1 -0
- package/dist/modules/campaigns/campaign.service.d.ts +11 -0
- package/dist/modules/campaigns/campaign.service.js +86 -0
- package/dist/modules/campaigns/campaign.service.js.map +1 -0
- package/dist/modules/google-calendar/google-calendar.routes.d.ts +2 -0
- package/dist/modules/google-calendar/google-calendar.routes.js +32 -0
- package/dist/modules/google-calendar/google-calendar.routes.js.map +1 -0
- package/dist/modules/inbound-call/inbound-call-config.model.d.ts +20 -0
- package/dist/modules/inbound-call/inbound-call-config.model.js +68 -0
- package/dist/modules/inbound-call/inbound-call-config.model.js.map +1 -0
- package/dist/modules/inbound-call/inbound-call.routes.d.ts +2 -0
- package/dist/modules/inbound-call/inbound-call.routes.js +243 -0
- package/dist/modules/inbound-call/inbound-call.routes.js.map +1 -0
- package/dist/modules/leads/lead.model.d.ts +24 -0
- package/dist/modules/leads/lead.model.js +54 -0
- package/dist/modules/leads/lead.model.js.map +1 -0
- package/dist/modules/leads/lead.routes.d.ts +2 -0
- package/dist/modules/leads/lead.routes.js +201 -0
- package/dist/modules/leads/lead.routes.js.map +1 -0
- package/dist/modules/plans/plan.model.d.ts +25 -0
- package/dist/modules/plans/plan.model.js +59 -0
- package/dist/modules/plans/plan.model.js.map +1 -0
- package/dist/modules/surveys/survey.model.d.ts +30 -0
- package/dist/modules/surveys/survey.model.js +75 -0
- package/dist/modules/surveys/survey.model.js.map +1 -0
- package/dist/modules/surveys/survey.routes.d.ts +2 -0
- package/dist/modules/surveys/survey.routes.js +153 -0
- package/dist/modules/surveys/survey.routes.js.map +1 -0
- package/dist/modules/tenants/tenant.model.d.ts +86 -0
- package/dist/modules/tenants/tenant.model.js +127 -0
- package/dist/modules/tenants/tenant.model.js.map +1 -0
- package/dist/modules/tenants/tenant.routes.d.ts +2 -0
- package/dist/modules/tenants/tenant.routes.js +65 -0
- package/dist/modules/tenants/tenant.routes.js.map +1 -0
- package/dist/modules/users/user.routes.d.ts +2 -0
- package/dist/modules/users/user.routes.js +106 -0
- package/dist/modules/users/user.routes.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs-tool.routes.d.ts +20 -0
- package/dist/modules/webhooks/elevenlabs-tool.routes.js +85 -0
- package/dist/modules/webhooks/elevenlabs-tool.routes.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs-tool.service.d.ts +11 -0
- package/dist/modules/webhooks/elevenlabs-tool.service.js +360 -0
- package/dist/modules/webhooks/elevenlabs-tool.service.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs.routes.d.ts +2 -0
- package/dist/modules/webhooks/elevenlabs.routes.js +34 -0
- package/dist/modules/webhooks/elevenlabs.routes.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs.service.d.ts +6 -0
- package/dist/modules/webhooks/elevenlabs.service.js +512 -0
- package/dist/modules/webhooks/elevenlabs.service.js.map +1 -0
- package/dist/modules/webhooks/unipile.routes.d.ts +2 -0
- package/dist/modules/webhooks/unipile.routes.js +780 -0
- package/dist/modules/webhooks/unipile.routes.js.map +1 -0
- package/dist/modules/whatsapp/appointment.model.d.ts +27 -0
- package/dist/modules/whatsapp/appointment.model.js +58 -0
- package/dist/modules/whatsapp/appointment.model.js.map +1 -0
- package/dist/modules/whatsapp/operator-request.model.d.ts +29 -0
- package/dist/modules/whatsapp/operator-request.model.js +65 -0
- package/dist/modules/whatsapp/operator-request.model.js.map +1 -0
- package/dist/modules/whatsapp/stt-usage.model.d.ts +16 -0
- package/dist/modules/whatsapp/stt-usage.model.js +53 -0
- package/dist/modules/whatsapp/stt-usage.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-chat.model.d.ts +23 -0
- package/dist/modules/whatsapp/whatsapp-chat.model.js +55 -0
- package/dist/modules/whatsapp/whatsapp-chat.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-contact-profile.model.d.ts +23 -0
- package/dist/modules/whatsapp/whatsapp-contact-profile.model.js +54 -0
- package/dist/modules/whatsapp/whatsapp-contact-profile.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-message.model.d.ts +30 -0
- package/dist/modules/whatsapp/whatsapp-message.model.js +52 -0
- package/dist/modules/whatsapp/whatsapp-message.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-session.model.d.ts +33 -0
- package/dist/modules/whatsapp/whatsapp-session.model.js +65 -0
- package/dist/modules/whatsapp/whatsapp-session.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp.routes.d.ts +2 -0
- package/dist/modules/whatsapp/whatsapp.routes.js +1237 -0
- package/dist/modules/whatsapp/whatsapp.routes.js.map +1 -0
- package/dist/plugins/cors.d.ts +3 -0
- package/dist/plugins/cors.js +11 -0
- package/dist/plugins/cors.js.map +1 -0
- package/dist/plugins/jwt.d.ts +3 -0
- package/dist/plugins/jwt.js +22 -0
- package/dist/plugins/jwt.js.map +1 -0
- package/dist/plugins/rawBody.d.ts +3 -0
- package/dist/plugins/rawBody.js +16 -0
- package/dist/plugins/rawBody.js.map +1 -0
- package/dist/plugins/rbac.d.ts +5 -0
- package/dist/plugins/rbac.js +29 -0
- package/dist/plugins/rbac.js.map +1 -0
- package/dist/routes/admin.routes.d.ts +2 -0
- package/dist/routes/admin.routes.js +169 -0
- package/dist/routes/admin.routes.js.map +1 -0
- package/dist/routes/health.routes.d.ts +2 -0
- package/dist/routes/health.routes.js +16 -0
- package/dist/routes/health.routes.js.map +1 -0
- package/dist/routes/webhook.routes.d.ts +2 -0
- package/dist/routes/webhook.routes.js +17 -0
- package/dist/routes/webhook.routes.js.map +1 -0
- package/dist/services/ai/base.ai.d.ts +19 -0
- package/dist/services/ai/base.ai.js +120 -0
- package/dist/services/ai/base.ai.js.map +1 -0
- package/dist/services/ai/gemini.service.d.ts +11 -0
- package/dist/services/ai/gemini.service.js +43 -0
- package/dist/services/ai/gemini.service.js.map +1 -0
- package/dist/services/ai/index.d.ts +2 -0
- package/dist/services/ai/index.js +26 -0
- package/dist/services/ai/index.js.map +1 -0
- package/dist/services/ai/openai.service.d.ts +11 -0
- package/dist/services/ai/openai.service.js +50 -0
- package/dist/services/ai/openai.service.js.map +1 -0
- package/dist/services/elevenlabs.service.d.ts +52 -0
- package/dist/services/elevenlabs.service.js +447 -0
- package/dist/services/elevenlabs.service.js.map +1 -0
- package/dist/services/google-calendar.service.d.ts +60 -0
- package/dist/services/google-calendar.service.js +494 -0
- package/dist/services/google-calendar.service.js.map +1 -0
- package/dist/services/inbound-call-schedule.service.d.ts +11 -0
- package/dist/services/inbound-call-schedule.service.js +162 -0
- package/dist/services/inbound-call-schedule.service.js.map +1 -0
- package/dist/services/netgsm.service.d.ts +41 -0
- package/dist/services/netgsm.service.js +89 -0
- package/dist/services/netgsm.service.js.map +1 -0
- package/dist/services/unipile.service.d.ts +41 -0
- package/dist/services/unipile.service.js +149 -0
- package/dist/services/unipile.service.js.map +1 -0
- package/dist/services/whatsapp-agent.service.d.ts +139 -0
- package/dist/services/whatsapp-agent.service.js +2055 -0
- package/dist/services/whatsapp-agent.service.js.map +1 -0
- package/dist/services/whatsapp.service.d.ts +26 -0
- package/dist/services/whatsapp.service.js +206 -0
- package/dist/services/whatsapp.service.js.map +1 -0
- package/dist/templates/index.d.ts +39 -0
- package/dist/templates/index.js +35 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/receptionist.d.ts +2 -0
- package/dist/templates/receptionist.js +39 -0
- package/dist/templates/receptionist.js.map +1 -0
- package/dist/templates/survey.d.ts +2 -0
- package/dist/templates/survey.js +41 -0
- package/dist/templates/survey.js.map +1 -0
- package/dist/types/index.d.ts +173 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/logger.d.ts +3 -0
- package/dist/utils/logger.js +105 -0
- package/dist/utils/logger.js.map +1 -0
- package/docker-compose.nestjs.yml +89 -0
- package/docker-compose.yml +78 -0
- package/docs/AI_AGENT_ENHANCEMENT_PLAN.md +164 -0
- package/docs/API.md +1193 -0
- package/docs/API_ENDPOINTS.md +344 -0
- package/docs/ARCHITECTURE.md +305 -0
- package/docs/AUTH_API.md +252 -0
- package/docs/BILLING_SMS_ALERTS.md +94 -0
- package/docs/CHAT_ASSIGNMENT_SYSTEM.md +118 -0
- package/docs/CLIENT_TOOLS_AND_FEATURES.md +337 -0
- package/docs/ELEVENLABS_WEBHOOK_TOOLS.md +644 -0
- package/docs/FRONTEND_CHECKLIST.md +227 -0
- package/docs/IMPLEMENTATION_STATUS.md +470 -0
- package/docs/MIGRATION_GUIDE.md +96 -0
- package/docs/MISSINGS_REPORT.md +507 -0
- package/docs/NESTJS_MIGRATION_REFERENCE.md +5136 -0
- package/docs/PROJECT_DESCRIPTION.md +1038 -0
- package/docs/SCALING.md +148 -0
- package/docs/SESSION_SUMMARY_2026_03_17.md +135 -0
- package/docs/WHATSAPP_AGENT.md +1086 -0
- package/docs/architecture/00-SYSTEM-OVERVIEW.md +318 -0
- package/docs/architecture/01-DATABASE-SCHEMA.md +2564 -0
- package/docs/architecture/02-AUTHENTICATION.md +1040 -0
- package/docs/architecture/03-MULTI-CLINIC.md +742 -0
- package/docs/architecture/04-WHATSAPP-AGENT.md +608 -0
- package/docs/architecture/05-OPERATOR-WORKFLOW.md +444 -0
- package/docs/architecture/06-BAILEYS-MICROSERVICE.md +616 -0
- package/docs/architecture/07-APPOINTMENTS.md +849 -0
- package/docs/architecture/08-VOICE-CALLS.md +470 -0
- package/docs/architecture/09-OUTBOUND-CAMPAIGNS.md +542 -0
- package/docs/architecture/10-CLIENT-TOOLS.md +665 -0
- package/docs/architecture/11-BILLING.md +458 -0
- package/docs/architecture/12-SECURITY.md +216 -0
- package/docs/architecture/13-LOGGING-AUDIT.md +549 -0
- package/docs/architecture/14-META-BUSINESS-API.md +454 -0
- package/docs/architecture/15-AI-MODULE.md +479 -0
- package/docs/architecture/16-BACKGROUND-JOBS.md +469 -0
- package/docs/architecture/17-REALTIME-LIVECHAT.md +447 -0
- package/docs/architecture/18-FILE-STORAGE.md +410 -0
- package/docs/architecture/19-PATIENTS.md +1034 -0
- package/docs/architecture/20-TREATMENTS-AND-PLANS.md +774 -0
- package/docs/architecture/21-BEFORE-AFTER-PHOTOS.md +519 -0
- package/docs/database.md +456 -0
- package/docs/ornek-randevu-onay.csv +3 -0
- package/ecosystem.config.js +16 -0
- package/elevenlabs-convai-api-reference.md +1171 -0
- package/frontend/.dockerignore +2 -0
- package/frontend/Dockerfile +24 -0
- package/frontend/README.md +75 -0
- package/frontend/components.json +25 -0
- package/frontend/eslint.config.js +23 -0
- package/frontend/index.html +13 -0
- package/frontend/nginx.conf +37 -0
- package/frontend/package-lock.json +8709 -0
- package/frontend/package.json +71 -0
- package/frontend/public/favicon.svg +1 -0
- package/frontend/public/icons.svg +24 -0
- package/frontend/src/App.tsx +125 -0
- package/frontend/src/components/error-boundary.tsx +50 -0
- package/frontend/src/components/shared/activity-timeline.tsx +66 -0
- package/frontend/src/components/shared/appointment-calendar.css +80 -0
- package/frontend/src/components/shared/appointment-calendar.tsx +245 -0
- package/frontend/src/components/shared/chat-bubble.tsx +72 -0
- package/frontend/src/components/shared/combobox.tsx +119 -0
- package/frontend/src/components/shared/confirm-dialog.tsx +57 -0
- package/frontend/src/components/shared/data-table-pagination.tsx +97 -0
- package/frontend/src/components/shared/data-table-toolbar.tsx +39 -0
- package/frontend/src/components/shared/empty-state.tsx +27 -0
- package/frontend/src/components/shared/file-upload.tsx +140 -0
- package/frontend/src/components/shared/index.ts +20 -0
- package/frontend/src/components/shared/language-switcher.tsx +29 -0
- package/frontend/src/components/shared/notification-dropdown.tsx +115 -0
- package/frontend/src/components/shared/page-header.tsx +23 -0
- package/frontend/src/components/shared/stat-card.tsx +37 -0
- package/frontend/src/components/shared/status-badge.tsx +70 -0
- package/frontend/src/components/shared/status-dot.tsx +43 -0
- package/frontend/src/components/ui/alert-dialog.tsx +187 -0
- package/frontend/src/components/ui/alert.tsx +76 -0
- package/frontend/src/components/ui/avatar.tsx +109 -0
- package/frontend/src/components/ui/badge.tsx +52 -0
- package/frontend/src/components/ui/breadcrumb.tsx +125 -0
- package/frontend/src/components/ui/button.tsx +60 -0
- package/frontend/src/components/ui/calendar.tsx +219 -0
- package/frontend/src/components/ui/card.tsx +103 -0
- package/frontend/src/components/ui/chart.tsx +371 -0
- package/frontend/src/components/ui/checkbox.tsx +29 -0
- package/frontend/src/components/ui/collapsible.tsx +19 -0
- package/frontend/src/components/ui/command.tsx +194 -0
- package/frontend/src/components/ui/dialog.tsx +158 -0
- package/frontend/src/components/ui/dropdown-menu.tsx +268 -0
- package/frontend/src/components/ui/input-group.tsx +156 -0
- package/frontend/src/components/ui/input.tsx +20 -0
- package/frontend/src/components/ui/label.tsx +20 -0
- package/frontend/src/components/ui/pagination.tsx +130 -0
- package/frontend/src/components/ui/popover.tsx +90 -0
- package/frontend/src/components/ui/progress.tsx +83 -0
- package/frontend/src/components/ui/radio-group.tsx +36 -0
- package/frontend/src/components/ui/scroll-area.tsx +54 -0
- package/frontend/src/components/ui/select.tsx +199 -0
- package/frontend/src/components/ui/separator.tsx +23 -0
- package/frontend/src/components/ui/sheet.tsx +138 -0
- package/frontend/src/components/ui/sidebar.tsx +723 -0
- package/frontend/src/components/ui/skeleton.tsx +13 -0
- package/frontend/src/components/ui/sonner.tsx +47 -0
- package/frontend/src/components/ui/switch.tsx +30 -0
- package/frontend/src/components/ui/table.tsx +114 -0
- package/frontend/src/components/ui/tabs.tsx +82 -0
- package/frontend/src/components/ui/textarea.tsx +18 -0
- package/frontend/src/components/ui/toggle-group.tsx +89 -0
- package/frontend/src/components/ui/toggle.tsx +43 -0
- package/frontend/src/components/ui/tooltip.tsx +64 -0
- package/frontend/src/hooks/use-mobile.ts +19 -0
- package/frontend/src/i18n/index.ts +20 -0
- package/frontend/src/i18n/locales/en.json +786 -0
- package/frontend/src/i18n/locales/tr.json +786 -0
- package/frontend/src/index.css +134 -0
- package/frontend/src/layouts/admin-layout.tsx +111 -0
- package/frontend/src/layouts/app-header.tsx +130 -0
- package/frontend/src/layouts/app-layout.tsx +19 -0
- package/frontend/src/layouts/app-sidebar.tsx +212 -0
- package/frontend/src/layouts/auth-guard.tsx +31 -0
- package/frontend/src/layouts/mobile-sidebar.tsx +120 -0
- package/frontend/src/lib/api.ts +68 -0
- package/frontend/src/lib/hooks/use-appointments.ts +224 -0
- package/frontend/src/lib/hooks/use-availability-blocks.ts +83 -0
- package/frontend/src/lib/hooks/use-chats.ts +236 -0
- package/frontend/src/lib/hooks/use-clinic-detail.ts +171 -0
- package/frontend/src/lib/hooks/use-clinics.ts +37 -0
- package/frontend/src/lib/hooks/use-doctor-calendar.ts +80 -0
- package/frontend/src/lib/hooks/use-examinations.ts +89 -0
- package/frontend/src/lib/hooks/use-medical-history.ts +52 -0
- package/frontend/src/lib/hooks/use-patients.ts +296 -0
- package/frontend/src/lib/hooks/use-photo-sets.ts +118 -0
- package/frontend/src/lib/hooks/use-treatment-plans.ts +152 -0
- package/frontend/src/lib/hooks/use-treatments.ts +125 -0
- package/frontend/src/lib/hooks/use-users.ts +172 -0
- package/frontend/src/lib/utils.ts +6 -0
- package/frontend/src/main.tsx +17 -0
- package/frontend/src/pages/admin/agents/detail.tsx +774 -0
- package/frontend/src/pages/admin/agents/import.tsx +280 -0
- package/frontend/src/pages/admin/agents/index.tsx +245 -0
- package/frontend/src/pages/admin/ai-playground.tsx +543 -0
- package/frontend/src/pages/appointments/create-appointment-dialog.tsx +390 -0
- package/frontend/src/pages/appointments/index.tsx +860 -0
- package/frontend/src/pages/audit/index.tsx +24 -0
- package/frontend/src/pages/auth/login.tsx +194 -0
- package/frontend/src/pages/billing/index.tsx +24 -0
- package/frontend/src/pages/calendar/index.tsx +704 -0
- package/frontend/src/pages/calendar-connections/index.tsx +295 -0
- package/frontend/src/pages/calls/index.tsx +24 -0
- package/frontend/src/pages/campaigns/index.tsx +24 -0
- package/frontend/src/pages/chats/index.tsx +981 -0
- package/frontend/src/pages/clinics/index.tsx +224 -0
- package/frontend/src/pages/clinics/settings.tsx +412 -0
- package/frontend/src/pages/components-showcase.tsx +773 -0
- package/frontend/src/pages/connections/index.tsx +328 -0
- package/frontend/src/pages/dashboard.tsx +50 -0
- package/frontend/src/pages/leads/index.tsx +24 -0
- package/frontend/src/pages/my-schedule/index.tsx +496 -0
- package/frontend/src/pages/patients/create-patient-dialog.tsx +358 -0
- package/frontend/src/pages/patients/detail.tsx +1195 -0
- package/frontend/src/pages/patients/edit-patient-dialog.tsx +387 -0
- package/frontend/src/pages/patients/examinations-tab.tsx +460 -0
- package/frontend/src/pages/patients/index.tsx +381 -0
- package/frontend/src/pages/patients/medical-history-dialog.tsx +207 -0
- package/frontend/src/pages/patients/photo-sets-tab.tsx +616 -0
- package/frontend/src/pages/patients/timeline-tab.tsx +164 -0
- package/frontend/src/pages/patients/treatment-plans-tab.tsx +598 -0
- package/frontend/src/pages/phone-numbers/detail.tsx +427 -0
- package/frontend/src/pages/phone-numbers/index.tsx +455 -0
- package/frontend/src/pages/platform/index.tsx +454 -0
- package/frontend/src/pages/settings/index.tsx +126 -0
- package/frontend/src/pages/treatments/index.tsx +487 -0
- package/frontend/src/pages/users/doctor-profile.tsx +672 -0
- package/frontend/src/pages/users/edit.tsx +329 -0
- package/frontend/src/pages/users/index.tsx +407 -0
- package/frontend/src/pages/validation/index.tsx +24 -0
- package/frontend/src/stores/auth.store.ts +108 -0
- package/frontend/src/stores/ui.store.ts +41 -0
- package/frontend/tsconfig.app.json +32 -0
- package/frontend/tsconfig.json +13 -0
- package/frontend/tsconfig.node.json +26 -0
- package/frontend/vite.config.ts +29 -0
- package/nestjs/.dockerignore +5 -0
- package/nestjs/.env.docker +64 -0
- package/nestjs/.prettierrc +4 -0
- package/nestjs/Dockerfile +36 -0
- package/nestjs/README.md +98 -0
- package/nestjs/eslint.config.mjs +35 -0
- package/nestjs/nest-cli.json +8 -0
- package/nestjs/package-lock.json +13390 -0
- package/nestjs/package.json +114 -0
- package/nestjs/prisma/migrations/20260409161536_add_message_metadata_fields/migration.sql +1746 -0
- package/nestjs/prisma/migrations/20260410140436_add_agent_ai_fields/migration.sql +36 -0
- package/nestjs/prisma/migrations/20260410175519_add_agent_clinic_assignments/migration.sql +21 -0
- package/nestjs/prisma/migrations/20260412094344_make_agent_tenant_optional/migration.sql +2 -0
- package/nestjs/prisma/migrations/20260412110008_add_admin_chat_sessions/migration.sql +47 -0
- package/nestjs/prisma/migrations/migration_lock.toml +3 -0
- package/nestjs/prisma/schema.prisma +1843 -0
- package/nestjs/prisma/seed.ts +375 -0
- package/nestjs/prisma.config.ts +14 -0
- package/nestjs/src/admin/admin.controller.ts +27 -0
- package/nestjs/src/admin/admin.module.ts +16 -0
- package/nestjs/src/admin/admin.service.ts +91 -0
- package/nestjs/src/admin/ai-chat-session.service.ts +454 -0
- package/nestjs/src/admin/ai-test.controller.ts +191 -0
- package/nestjs/src/admin/superadmin.controller.ts +106 -0
- package/nestjs/src/agents/agents.controller.ts +262 -0
- package/nestjs/src/agents/agents.module.ts +13 -0
- package/nestjs/src/agents/agents.service.ts +733 -0
- package/nestjs/src/agents/dto/create-agent.dto.ts +99 -0
- package/nestjs/src/agents/dto/index.ts +2 -0
- package/nestjs/src/agents/dto/update-agent.dto.ts +148 -0
- package/nestjs/src/app.module.ts +115 -0
- package/nestjs/src/appointment-validation/appointment-validation.controller.ts +194 -0
- package/nestjs/src/appointment-validation/appointment-validation.module.ts +16 -0
- package/nestjs/src/appointment-validation/appointment-validation.service.ts +450 -0
- package/nestjs/src/appointment-validation/dto/create-batch.dto.ts +105 -0
- package/nestjs/src/appointment-validation/dto/index.ts +1 -0
- package/nestjs/src/appointment-validation/processors/validation-dispatch.processor.ts +26 -0
- package/nestjs/src/appointment-validation/processors/validation-sync.processor.ts +23 -0
- package/nestjs/src/appointments/appointments.controller.ts +268 -0
- package/nestjs/src/appointments/appointments.module.ts +13 -0
- package/nestjs/src/appointments/appointments.service.ts +773 -0
- package/nestjs/src/appointments/dto/create-appointment.dto.ts +72 -0
- package/nestjs/src/appointments/dto/index.ts +4 -0
- package/nestjs/src/appointments/dto/query-appointments.dto.ts +60 -0
- package/nestjs/src/appointments/dto/update-appointment.dto.ts +43 -0
- package/nestjs/src/appointments/dto/update-status.dto.ts +18 -0
- package/nestjs/src/appointments/processors/reminder.processor.ts +243 -0
- package/nestjs/src/audit/audit.controller.ts +84 -0
- package/nestjs/src/audit/audit.decorator.ts +20 -0
- package/nestjs/src/audit/audit.interceptor.ts +67 -0
- package/nestjs/src/audit/audit.interfaces.ts +15 -0
- package/nestjs/src/audit/audit.module.ts +12 -0
- package/nestjs/src/audit/audit.service.ts +177 -0
- package/nestjs/src/auth/auth.controller.ts +116 -0
- package/nestjs/src/auth/auth.module.ts +25 -0
- package/nestjs/src/auth/auth.service.ts +612 -0
- package/nestjs/src/auth/dto/change-password.dto.ts +13 -0
- package/nestjs/src/auth/dto/forgot-password.dto.ts +8 -0
- package/nestjs/src/auth/dto/index.ts +6 -0
- package/nestjs/src/auth/dto/login.dto.ts +13 -0
- package/nestjs/src/auth/dto/refresh.dto.ts +8 -0
- package/nestjs/src/auth/dto/register.dto.ts +28 -0
- package/nestjs/src/auth/dto/reset-password.dto.ts +13 -0
- package/nestjs/src/auth/permissions.config.ts +85 -0
- package/nestjs/src/availability-blocks/availability-blocks.controller.ts +83 -0
- package/nestjs/src/availability-blocks/availability-blocks.module.ts +10 -0
- package/nestjs/src/availability-blocks/availability-blocks.service.ts +202 -0
- package/nestjs/src/billing/billing.controller.ts +104 -0
- package/nestjs/src/billing/billing.module.ts +12 -0
- package/nestjs/src/billing/billing.service.ts +398 -0
- package/nestjs/src/billing/dto/index.ts +2 -0
- package/nestjs/src/billing/dto/query-billing.dto.ts +29 -0
- package/nestjs/src/billing/dto/record-payment.dto.ts +60 -0
- package/nestjs/src/billing/processors/alerts.processor.ts +216 -0
- package/nestjs/src/billing/processors/snapshot.processor.ts +181 -0
- package/nestjs/src/calls/calls.controller.ts +92 -0
- package/nestjs/src/calls/calls.module.ts +10 -0
- package/nestjs/src/calls/calls.service.ts +359 -0
- package/nestjs/src/calls/dto/index.ts +1 -0
- package/nestjs/src/calls/dto/query-calls.dto.ts +46 -0
- package/nestjs/src/clinics/clinics.controller.ts +226 -0
- package/nestjs/src/clinics/clinics.module.ts +11 -0
- package/nestjs/src/clinics/clinics.service.ts +203 -0
- package/nestjs/src/clinics/dto/create-clinic.dto.ts +40 -0
- package/nestjs/src/clinics/dto/create-meta-connection.dto.ts +44 -0
- package/nestjs/src/clinics/dto/index.ts +4 -0
- package/nestjs/src/clinics/dto/update-clinic.dto.ts +133 -0
- package/nestjs/src/clinics/dto/update-meta-connection.dto.ts +22 -0
- package/nestjs/src/clinics/meta-connections.service.ts +210 -0
- package/nestjs/src/common/decorators/accessible-clinics.decorator.ts +9 -0
- package/nestjs/src/common/decorators/current-user.decorator.ts +10 -0
- package/nestjs/src/common/decorators/features.decorator.ts +7 -0
- package/nestjs/src/common/decorators/index.ts +4 -0
- package/nestjs/src/common/decorators/permissions.decorator.ts +13 -0
- package/nestjs/src/common/gateways/events.gateway.ts +157 -0
- package/nestjs/src/common/guards/clinic-access.guard.ts +40 -0
- package/nestjs/src/common/guards/features.guard.ts +38 -0
- package/nestjs/src/common/guards/index.ts +5 -0
- package/nestjs/src/common/guards/jwt-auth.guard.ts +54 -0
- package/nestjs/src/common/guards/permissions.guard.ts +50 -0
- package/nestjs/src/common/guards/superadmin.guard.ts +35 -0
- package/nestjs/src/common/interceptors/request-context.interceptor.ts +32 -0
- package/nestjs/src/common/interceptors/superadmin-tenant.interceptor.ts +42 -0
- package/nestjs/src/common/interfaces/jwt-payload.interface.ts +11 -0
- package/nestjs/src/config/config.module.ts +13 -0
- package/nestjs/src/database/database.module.ts +9 -0
- package/nestjs/src/database/prisma.service.ts +20 -0
- package/nestjs/src/database/tenant-context.ts +27 -0
- package/nestjs/src/google-calendar/google-calendar.controller.ts +259 -0
- package/nestjs/src/google-calendar/google-calendar.module.ts +10 -0
- package/nestjs/src/google-calendar/google-calendar.service.ts +811 -0
- package/nestjs/src/integrations/ai/ai.interface.ts +74 -0
- package/nestjs/src/integrations/ai/ai.module.ts +11 -0
- package/nestjs/src/integrations/ai/ai.service.ts +148 -0
- package/nestjs/src/integrations/ai/providers/anthropic.provider.ts +146 -0
- package/nestjs/src/integrations/ai/providers/openai.provider.ts +158 -0
- package/nestjs/src/integrations/elevenlabs/elevenlabs.module.ts +8 -0
- package/nestjs/src/integrations/elevenlabs/elevenlabs.service.ts +226 -0
- package/nestjs/src/integrations/encryption/encryption.module.ts +9 -0
- package/nestjs/src/integrations/encryption/encryption.service.ts +31 -0
- package/nestjs/src/integrations/image/image.module.ts +9 -0
- package/nestjs/src/integrations/image/image.service.ts +61 -0
- package/nestjs/src/integrations/meta-business/meta-business.module.ts +10 -0
- package/nestjs/src/integrations/meta-business/meta-instagram.service.ts +94 -0
- package/nestjs/src/integrations/meta-business/meta-webhook.service.ts +52 -0
- package/nestjs/src/integrations/meta-business/meta-whatsapp.service.ts +254 -0
- package/nestjs/src/integrations/minio/minio.module.ts +9 -0
- package/nestjs/src/integrations/minio/minio.service.ts +88 -0
- package/nestjs/src/integrations/netgsm/netgsm.module.ts +8 -0
- package/nestjs/src/integrations/netgsm/netgsm.service.ts +17 -0
- package/nestjs/src/integrations/tektippay/tektippay.module.ts +8 -0
- package/nestjs/src/integrations/tektippay/tektippay.service.ts +23 -0
- package/nestjs/src/leads/dto/index.ts +2 -0
- package/nestjs/src/leads/dto/query-leads.dto.ts +50 -0
- package/nestjs/src/leads/dto/update-lead.dto.ts +26 -0
- package/nestjs/src/leads/leads.controller.ts +184 -0
- package/nestjs/src/leads/leads.module.ts +10 -0
- package/nestjs/src/leads/leads.service.ts +375 -0
- package/nestjs/src/logging/logging.controller.ts +82 -0
- package/nestjs/src/logging/logging.module.ts +11 -0
- package/nestjs/src/logging/logging.service.ts +180 -0
- package/nestjs/src/main.ts +86 -0
- package/nestjs/src/outbound-campaigns/dto/create-campaign.dto.ts +47 -0
- package/nestjs/src/outbound-campaigns/dto/index.ts +3 -0
- package/nestjs/src/outbound-campaigns/dto/update-campaign.dto.ts +31 -0
- package/nestjs/src/outbound-campaigns/dto/upload-entries.dto.ts +35 -0
- package/nestjs/src/outbound-campaigns/outbound-campaigns.controller.ts +307 -0
- package/nestjs/src/outbound-campaigns/outbound-campaigns.module.ts +13 -0
- package/nestjs/src/outbound-campaigns/outbound-campaigns.service.ts +471 -0
- package/nestjs/src/outbound-campaigns/processors/campaign-dispatch.processor.ts +366 -0
- package/nestjs/src/patients/documents.service.ts +231 -0
- package/nestjs/src/patients/dto/create-examination.dto.ts +34 -0
- package/nestjs/src/patients/dto/create-note.dto.ts +14 -0
- package/nestjs/src/patients/dto/create-patient.dto.ts +86 -0
- package/nestjs/src/patients/dto/create-photo-set.dto.ts +32 -0
- package/nestjs/src/patients/dto/index.ts +10 -0
- package/nestjs/src/patients/dto/update-examination.dto.ts +29 -0
- package/nestjs/src/patients/dto/update-medical-history.dto.ts +47 -0
- package/nestjs/src/patients/dto/update-patient.dto.ts +87 -0
- package/nestjs/src/patients/dto/update-photo-set.dto.ts +28 -0
- package/nestjs/src/patients/dto/upload-document.dto.ts +31 -0
- package/nestjs/src/patients/dto/upload-photo.dto.ts +27 -0
- package/nestjs/src/patients/examinations.service.ts +271 -0
- package/nestjs/src/patients/medical-history.service.ts +149 -0
- package/nestjs/src/patients/notes.service.ts +172 -0
- package/nestjs/src/patients/patients.controller.ts +485 -0
- package/nestjs/src/patients/patients.module.ts +22 -0
- package/nestjs/src/patients/patients.service.ts +412 -0
- package/nestjs/src/patients/photo-sets.service.ts +389 -0
- package/nestjs/src/phone-numbers/dto/create-phone-number.dto.ts +57 -0
- package/nestjs/src/phone-numbers/dto/index.ts +3 -0
- package/nestjs/src/phone-numbers/dto/update-phone-number.dto.ts +38 -0
- package/nestjs/src/phone-numbers/dto/update-schedule.dto.ts +39 -0
- package/nestjs/src/phone-numbers/phone-numbers.controller.ts +125 -0
- package/nestjs/src/phone-numbers/phone-numbers.module.ts +10 -0
- package/nestjs/src/phone-numbers/phone-numbers.service.ts +209 -0
- package/nestjs/src/plans/dto/create-plan.dto.ts +70 -0
- package/nestjs/src/plans/dto/index.ts +2 -0
- package/nestjs/src/plans/dto/update-plan.dto.ts +80 -0
- package/nestjs/src/plans/plans.controller.ts +50 -0
- package/nestjs/src/plans/plans.module.ts +10 -0
- package/nestjs/src/plans/plans.service.ts +115 -0
- package/nestjs/src/platform/dto/create-tenant.dto.ts +36 -0
- package/nestjs/src/platform/dto/index.ts +2 -0
- package/nestjs/src/platform/dto/update-tenant-platform.dto.ts +44 -0
- package/nestjs/src/platform/platform.controller.ts +79 -0
- package/nestjs/src/platform/platform.module.ts +10 -0
- package/nestjs/src/platform/platform.service.ts +301 -0
- package/nestjs/src/queue/queue.module.ts +56 -0
- package/nestjs/src/redis/redis.module.ts +20 -0
- package/nestjs/src/tenants/dto/index.ts +1 -0
- package/nestjs/src/tenants/dto/update-tenant.dto.ts +15 -0
- package/nestjs/src/tenants/tenants.controller.ts +45 -0
- package/nestjs/src/tenants/tenants.module.ts +10 -0
- package/nestjs/src/tenants/tenants.service.ts +41 -0
- package/nestjs/src/tools/adapters/elevenlabs-http.adapter.ts +51 -0
- package/nestjs/src/tools/adapters/elevenlabs-ws.adapter.ts +59 -0
- package/nestjs/src/tools/handlers/calendar.tools.ts +441 -0
- package/nestjs/src/tools/handlers/notification.tools.ts +34 -0
- package/nestjs/src/tools/handlers/operator.tools.ts +303 -0
- package/nestjs/src/tools/handlers/patient.tools.ts +242 -0
- package/nestjs/src/tools/handlers/payment.tools.ts +43 -0
- package/nestjs/src/tools/handlers/validation.tools.ts +152 -0
- package/nestjs/src/tools/tool-registry.service.ts +221 -0
- package/nestjs/src/tools/tool.decorator.ts +16 -0
- package/nestjs/src/tools/tool.interfaces.ts +26 -0
- package/nestjs/src/tools/tools.module.ts +50 -0
- package/nestjs/src/treatments/dto/create-plan-item.dto.ts +27 -0
- package/nestjs/src/treatments/dto/create-treatment-plan.dto.ts +69 -0
- package/nestjs/src/treatments/dto/create-treatment.dto.ts +59 -0
- package/nestjs/src/treatments/dto/index.ts +6 -0
- package/nestjs/src/treatments/dto/update-plan-item.dto.ts +23 -0
- package/nestjs/src/treatments/dto/update-treatment-plan.dto.ts +22 -0
- package/nestjs/src/treatments/dto/update-treatment.dto.ts +70 -0
- package/nestjs/src/treatments/treatment-plans.service.ts +362 -0
- package/nestjs/src/treatments/treatments.controller.ts +265 -0
- package/nestjs/src/treatments/treatments.module.ts +14 -0
- package/nestjs/src/treatments/treatments.service.ts +165 -0
- package/nestjs/src/users/doctor-profiles.service.ts +202 -0
- package/nestjs/src/users/dto/index.ts +4 -0
- package/nestjs/src/users/dto/invite-user.dto.ts +52 -0
- package/nestjs/src/users/dto/update-clinic-assignments.dto.ts +9 -0
- package/nestjs/src/users/dto/update-doctor-profile.dto.ts +49 -0
- package/nestjs/src/users/dto/update-user.dto.ts +41 -0
- package/nestjs/src/users/users.controller.ts +142 -0
- package/nestjs/src/users/users.module.ts +11 -0
- package/nestjs/src/users/users.service.ts +250 -0
- package/nestjs/src/webhooks/elevenlabs-tool.controller.ts +66 -0
- package/nestjs/src/webhooks/elevenlabs-webhook.controller.ts +60 -0
- package/nestjs/src/webhooks/meta-webhook.controller.ts +178 -0
- package/nestjs/src/webhooks/processors/elevenlabs-webhook.processor.ts +28 -0
- package/nestjs/src/webhooks/webhooks.module.ts +17 -0
- package/nestjs/src/whatsapp/chat-context.service.ts +281 -0
- package/nestjs/src/whatsapp/dto/add-blacklist.dto.ts +13 -0
- package/nestjs/src/whatsapp/dto/index.ts +2 -0
- package/nestjs/src/whatsapp/dto/send-message.dto.ts +14 -0
- package/nestjs/src/whatsapp/listeners/meta-message.listener.ts +579 -0
- package/nestjs/src/whatsapp/meta-auth.controller.ts +268 -0
- package/nestjs/src/whatsapp/meta-instagram-auth.controller.ts +244 -0
- package/nestjs/src/whatsapp/operator.service.ts +692 -0
- package/nestjs/src/whatsapp/processors/cost-sweep.processor.ts +130 -0
- package/nestjs/src/whatsapp/processors/grace.processor.ts +191 -0
- package/nestjs/src/whatsapp/processors/message-buffer.processor.ts +138 -0
- package/nestjs/src/whatsapp/processors/message-cleanup.processor.ts +148 -0
- package/nestjs/src/whatsapp/processors/meta-token-refresh.processor.ts +114 -0
- package/nestjs/src/whatsapp/processors/operator-expiry.processor.ts +105 -0
- package/nestjs/src/whatsapp/processors/profile-update.processor.ts +234 -0
- package/nestjs/src/whatsapp/processors/session-cleanup.processor.ts +178 -0
- package/nestjs/src/whatsapp/processors/session-labels.processor.ts +248 -0
- package/nestjs/src/whatsapp/whatsapp-agent.service.ts +2506 -0
- package/nestjs/src/whatsapp/whatsapp-recovery.service.ts +117 -0
- package/nestjs/src/whatsapp/whatsapp.controller.ts +398 -0
- package/nestjs/src/whatsapp/whatsapp.module.ts +51 -0
- package/nestjs/src/whatsapp/whatsapp.service.ts +592 -0
- package/nestjs/test/app.e2e-spec.ts +25 -0
- package/nestjs/test/jest-e2e.json +9 -0
- package/nestjs/tsconfig.build.json +4 -0
- package/nestjs/tsconfig.json +25 -0
- package/nginx.example.conf +18 -0
- package/package.json +47 -0
- package/scripts/addRecipient.ts +48 -0
- package/scripts/listRecipients.ts +31 -0
- package/scripts/migrate-agent-ref.ts +86 -0
- package/scripts/migrate-sessions.ts +183 -0
- package/scripts/promote.ts +27 -0
- package/scripts/retrigger.ts +84 -0
- package/scripts/seed.ts +435 -0
- package/scripts/testSend.ts +63 -0
- package/src/app.ts +85 -0
- package/src/config/agentPrompts.json +19 -0
- package/src/config/database.ts +21 -0
- package/src/config/env.ts +94 -0
- package/src/config/index.ts +86 -0
- package/src/controllers/webhook.controller.ts +150 -0
- package/src/errors/index.ts +9 -0
- package/src/hooks/webhookValidator.ts +55 -0
- package/src/index.ts +68 -0
- package/src/migrations/001_session-architecture.ts +138 -0
- package/src/migrations/002_agent-ref.ts +65 -0
- package/src/migrations/003_shift-schedule.ts +55 -0
- package/src/migrations/004_invert-shift-to-clinic-hours.ts +30 -0
- package/src/migrations/005_composite-baileys-chat-ids.ts +60 -0
- package/src/migrations/migration.model.ts +27 -0
- package/src/migrations/migration.routes.ts +40 -0
- package/src/migrations/migration.runner.ts +112 -0
- package/src/models/ConversationClaim.ts +17 -0
- package/src/models/ConversationEvaluation.ts +91 -0
- package/src/models/Summary.ts +77 -0
- package/src/models/Transcription.ts +68 -0
- package/src/models/WhatsAppRecipient.ts +37 -0
- package/src/modules/admin/admin.routes.ts +2385 -0
- package/src/modules/admin/elevenlabs-test-chat.routes.ts +193 -0
- package/src/modules/admin/whatsapp-test-chat.routes.ts +244 -0
- package/src/modules/agents/agent.model.ts +93 -0
- package/src/modules/agents/agent.routes.ts +65 -0
- package/src/modules/appointment-validation/appointment-validation.model.ts +163 -0
- package/src/modules/appointment-validation/appointment-validation.routes.ts +275 -0
- package/src/modules/appointment-validation/appointment-validation.service.ts +1028 -0
- package/src/modules/auth/auth.model.ts +42 -0
- package/src/modules/auth/auth.routes.ts +199 -0
- package/src/modules/auth/auth.service.ts +210 -0
- package/src/modules/auth/refresh-token.model.ts +26 -0
- package/src/modules/billing/billing-alert.model.ts +28 -0
- package/src/modules/billing/billing-period-snapshot.model.ts +68 -0
- package/src/modules/billing/billing.model.ts +42 -0
- package/src/modules/billing/billing.routes.ts +67 -0
- package/src/modules/billing/billing.service.ts +562 -0
- package/src/modules/billing/payment.model.ts +42 -0
- package/src/modules/calls/call.model.ts +102 -0
- package/src/modules/calls/call.routes.ts +118 -0
- package/src/modules/campaigns/campaign.model.ts +111 -0
- package/src/modules/campaigns/campaign.routes.ts +402 -0
- package/src/modules/campaigns/campaign.service.ts +99 -0
- package/src/modules/google-calendar/google-calendar.routes.ts +31 -0
- package/src/modules/inbound-call/inbound-call-config.model.ts +49 -0
- package/src/modules/inbound-call/inbound-call.routes.ts +289 -0
- package/src/modules/leads/lead.model.ts +40 -0
- package/src/modules/leads/lead.routes.ts +246 -0
- package/src/modules/logs/log.model.ts +27 -0
- package/src/modules/logs/log.routes.ts +102 -0
- package/src/modules/plans/plan.model.ts +45 -0
- package/src/modules/surveys/survey.model.ts +70 -0
- package/src/modules/surveys/survey.routes.ts +187 -0
- package/src/modules/tenants/tenant.model.ts +181 -0
- package/src/modules/tenants/tenant.routes.ts +78 -0
- package/src/modules/users/user.routes.ts +126 -0
- package/src/modules/webhooks/elevenlabs-tool.routes.ts +94 -0
- package/src/modules/webhooks/elevenlabs-tool.service.ts +491 -0
- package/src/modules/webhooks/elevenlabs.routes.ts +34 -0
- package/src/modules/webhooks/elevenlabs.service.ts +565 -0
- package/src/modules/webhooks/unipile.routes.ts +917 -0
- package/src/modules/whatsapp/appointment.model.ts +47 -0
- package/src/modules/whatsapp/operator-request.model.ts +58 -0
- package/src/modules/whatsapp/stt-usage.model.ts +30 -0
- package/src/modules/whatsapp/whatsapp-chat.model.ts +39 -0
- package/src/modules/whatsapp/whatsapp-contact-profile.model.ts +41 -0
- package/src/modules/whatsapp/whatsapp-message.model.ts +41 -0
- package/src/modules/whatsapp/whatsapp-session.model.ts +60 -0
- package/src/modules/whatsapp/whatsapp.routes.ts +1435 -0
- package/src/plugins/cors.ts +7 -0
- package/src/plugins/jwt.ts +18 -0
- package/src/plugins/rawBody.ts +12 -0
- package/src/plugins/rbac.ts +24 -0
- package/src/routes/admin.routes.ts +208 -0
- package/src/routes/health.routes.ts +12 -0
- package/src/routes/webhook.routes.ts +12 -0
- package/src/services/ai/base.ai.ts +132 -0
- package/src/services/ai/gemini.service.ts +41 -0
- package/src/services/ai/index.ts +24 -0
- package/src/services/ai/openai.service.ts +48 -0
- package/src/services/elevenlabs.service.ts +532 -0
- package/src/services/google-calendar.service.ts +656 -0
- package/src/services/inbound-call-schedule.service.ts +174 -0
- package/src/services/netgsm.service.ts +128 -0
- package/src/services/unipile.service.ts +200 -0
- package/src/services/whatsapp-agent.service.ts +2479 -0
- package/src/services/whatsapp.service.ts +245 -0
- package/src/templates/index.ts +71 -0
- package/src/templates/receptionist.ts +44 -0
- package/src/templates/survey.ts +44 -0
- package/src/types/index.ts +218 -0
- package/src/utils/logger.ts +83 -0
- package/tsconfig.json +19 -0
- package/web/.dockerignore +4 -0
- package/web/Dockerfile +18 -0
- package/web/README.md +73 -0
- package/web/components.json +23 -0
- package/web/eslint.config.js +23 -0
- package/web/index.html +14 -0
- package/web/nginx.conf +18 -0
- package/web/package-lock.json +10292 -0
- package/web/package.json +48 -0
- package/web/public/favicon.ico +0 -0
- package/web/public/vite.svg +1 -0
- package/web/src/App.tsx +191 -0
- package/web/src/assets/react.svg +1 -0
- package/web/src/components/Layout.tsx +261 -0
- package/web/src/components/LeadConversation.tsx +251 -0
- package/web/src/components/ProtectedRoute.tsx +20 -0
- package/web/src/components/conversation-review/CardAudioPlayer.tsx +200 -0
- package/web/src/components/conversation-review/CardEvaluation.tsx +351 -0
- package/web/src/components/conversation-review/CardMetadata.tsx +44 -0
- package/web/src/components/conversation-review/ConversationCard.tsx +95 -0
- package/web/src/components/conversation-review/ReviewContainer.tsx +120 -0
- package/web/src/components/conversation-review/ReviewFilters.tsx +88 -0
- package/web/src/components/empty-state.tsx +15 -0
- package/web/src/components/page-header.tsx +19 -0
- package/web/src/components/page-loader.tsx +32 -0
- package/web/src/components/pagination.tsx +38 -0
- package/web/src/components/stat-card.tsx +27 -0
- package/web/src/components/status-badge.tsx +125 -0
- package/web/src/components/ui/alert.tsx +66 -0
- package/web/src/components/ui/badge.tsx +48 -0
- package/web/src/components/ui/button.tsx +64 -0
- package/web/src/components/ui/card.tsx +92 -0
- package/web/src/components/ui/checkbox.tsx +32 -0
- package/web/src/components/ui/dialog.tsx +158 -0
- package/web/src/components/ui/dropdown-menu.tsx +255 -0
- package/web/src/components/ui/input.tsx +21 -0
- package/web/src/components/ui/label.tsx +22 -0
- package/web/src/components/ui/progress.tsx +29 -0
- package/web/src/components/ui/select.tsx +188 -0
- package/web/src/components/ui/separator.tsx +28 -0
- package/web/src/components/ui/sheet.tsx +123 -0
- package/web/src/components/ui/skeleton.tsx +13 -0
- package/web/src/components/ui/sonner.tsx +35 -0
- package/web/src/components/ui/table.tsx +116 -0
- package/web/src/components/ui/tabs.tsx +89 -0
- package/web/src/components/ui/textarea.tsx +18 -0
- package/web/src/components/ui/tooltip.tsx +57 -0
- package/web/src/components/whatsapp/ChatDetail.tsx +417 -0
- package/web/src/components/whatsapp/ChatHeader.tsx +78 -0
- package/web/src/components/whatsapp/ChatList.tsx +107 -0
- package/web/src/components/whatsapp/ChatListItem.tsx +60 -0
- package/web/src/components/whatsapp/MessageBubble.tsx +46 -0
- package/web/src/components/whatsapp/MessageInput.tsx +63 -0
- package/web/src/components/whatsapp/MessageStream.tsx +135 -0
- package/web/src/components/whatsapp/SessionDivider.tsx +65 -0
- package/web/src/components/whatsapp/SessionHistory.tsx +119 -0
- package/web/src/components/whatsapp/settings/AiSettingsTab.tsx +268 -0
- package/web/src/components/whatsapp/settings/CalendarTab.tsx +339 -0
- package/web/src/components/whatsapp/settings/ConnectionTab.tsx +236 -0
- package/web/src/components/whatsapp/settings/NotificationsTab.tsx +109 -0
- package/web/src/components/whatsapp/settings/OperatorTab.tsx +303 -0
- package/web/src/contexts/AuthContext.tsx +103 -0
- package/web/src/index.css +130 -0
- package/web/src/lib/api.ts +92 -0
- package/web/src/lib/utils.ts +6 -0
- package/web/src/main.tsx +10 -0
- package/web/src/pages/AppointmentDetail.tsx +206 -0
- package/web/src/pages/AppointmentValidation.tsx +157 -0
- package/web/src/pages/AppointmentValidationDetail.tsx +617 -0
- package/web/src/pages/AppointmentValidationNew.tsx +1005 -0
- package/web/src/pages/Appointments.tsx +283 -0
- package/web/src/pages/Billing.tsx +126 -0
- package/web/src/pages/CallDetail.tsx +293 -0
- package/web/src/pages/CallSettings.tsx +313 -0
- package/web/src/pages/Calls.tsx +188 -0
- package/web/src/pages/CampaignDetail.tsx +216 -0
- package/web/src/pages/CampaignNew.tsx +277 -0
- package/web/src/pages/CampaignResults.tsx +185 -0
- package/web/src/pages/Campaigns.tsx +171 -0
- package/web/src/pages/Dashboard.tsx +336 -0
- package/web/src/pages/InboundSchedule.tsx +246 -0
- package/web/src/pages/LeadDetail.tsx +183 -0
- package/web/src/pages/Leads.tsx +258 -0
- package/web/src/pages/Login.tsx +99 -0
- package/web/src/pages/Register.tsx +129 -0
- package/web/src/pages/Settings.tsx +133 -0
- package/web/src/pages/SurveyDetail.tsx +232 -0
- package/web/src/pages/SurveyPreview.tsx +179 -0
- package/web/src/pages/Surveys.tsx +207 -0
- package/web/src/pages/Users.tsx +199 -0
- package/web/src/pages/WhatsApp.tsx +147 -0
- package/web/src/pages/WhatsAppSettings.tsx +215 -0
- package/web/src/pages/admin/AdminBaileysMessageLog.tsx +331 -0
- package/web/src/pages/admin/AdminBaileysRawMessages.tsx +318 -0
- package/web/src/pages/admin/AdminConversationReview.tsx +116 -0
- package/web/src/pages/admin/AdminCredits.tsx +467 -0
- package/web/src/pages/admin/AdminElevenLabsAgentDetail.tsx +332 -0
- package/web/src/pages/admin/AdminElevenLabsAgents.tsx +164 -0
- package/web/src/pages/admin/AdminElevenLabsBatchCallDetail.tsx +214 -0
- package/web/src/pages/admin/AdminElevenLabsBatchCalls.tsx +293 -0
- package/web/src/pages/admin/AdminElevenLabsConversationDetail.tsx +230 -0
- package/web/src/pages/admin/AdminElevenLabsConversations.tsx +228 -0
- package/web/src/pages/admin/AdminElevenLabsInboundCalls.tsx +293 -0
- package/web/src/pages/admin/AdminElevenLabsPhoneNumbers.tsx +506 -0
- package/web/src/pages/admin/AdminElevenLabsTestChat.tsx +258 -0
- package/web/src/pages/admin/AdminElevenLabsWebhooks.tsx +289 -0
- package/web/src/pages/admin/AdminEvaluationDashboard.tsx +520 -0
- package/web/src/pages/admin/AdminLeads.tsx +339 -0
- package/web/src/pages/admin/AdminLogs.tsx +283 -0
- package/web/src/pages/admin/AdminMigrations.tsx +247 -0
- package/web/src/pages/admin/AdminPlans.tsx +313 -0
- package/web/src/pages/admin/AdminSystem.tsx +391 -0
- package/web/src/pages/admin/AdminTenantBillableItems.tsx +464 -0
- package/web/src/pages/admin/AdminTenantDetail.tsx +1317 -0
- package/web/src/pages/admin/AdminTenants.tsx +274 -0
- package/web/src/pages/admin/AdminWhatsApp.tsx +618 -0
- package/web/src/pages/admin/AdminWhatsAppTestChat.tsx +328 -0
- package/web/src/types/index.ts +242 -0
- package/web/tsconfig.app.json +32 -0
- package/web/tsconfig.json +13 -0
- package/web/tsconfig.node.json +26 -0
- package/web/vite.config.ts +23 -0
|
@@ -0,0 +1,1317 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useParams, Link, useNavigate } from 'react-router-dom';
|
|
3
|
+
import api from '../../lib/api';
|
|
4
|
+
import { PageLoader } from '@/components/page-loader';
|
|
5
|
+
import { StatCard } from '@/components/stat-card';
|
|
6
|
+
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
|
7
|
+
import { Input } from '@/components/ui/input';
|
|
8
|
+
import { Label } from '@/components/ui/label';
|
|
9
|
+
import { Textarea } from '@/components/ui/textarea';
|
|
10
|
+
import { Button } from '@/components/ui/button';
|
|
11
|
+
import { Badge } from '@/components/ui/badge';
|
|
12
|
+
import { Checkbox } from '@/components/ui/checkbox';
|
|
13
|
+
import {
|
|
14
|
+
Select,
|
|
15
|
+
SelectContent,
|
|
16
|
+
SelectItem,
|
|
17
|
+
SelectTrigger,
|
|
18
|
+
SelectValue,
|
|
19
|
+
} from '@/components/ui/select';
|
|
20
|
+
import {
|
|
21
|
+
Table,
|
|
22
|
+
TableBody,
|
|
23
|
+
TableCell,
|
|
24
|
+
TableHead,
|
|
25
|
+
TableHeader,
|
|
26
|
+
TableRow,
|
|
27
|
+
} from '@/components/ui/table';
|
|
28
|
+
import {
|
|
29
|
+
Dialog,
|
|
30
|
+
DialogContent,
|
|
31
|
+
DialogHeader,
|
|
32
|
+
DialogTitle,
|
|
33
|
+
DialogTrigger,
|
|
34
|
+
} from '@/components/ui/dialog';
|
|
35
|
+
import { Alert, AlertDescription } from '@/components/ui/alert';
|
|
36
|
+
import { toast } from 'sonner';
|
|
37
|
+
import { ArrowLeftIcon, Loader2Icon, UsersIcon, BotIcon, PhoneIcon, PhoneOutgoingIcon, MegaphoneIcon, PlusIcon, PencilIcon, CreditCardIcon, TrashIcon, MessageSquareIcon, ReceiptIcon } from 'lucide-react';
|
|
38
|
+
|
|
39
|
+
const ALL_FEATURES: { key: string; label: string }[] = [
|
|
40
|
+
{ key: 'inbound_agent', label: 'Gelen Arama Agent' },
|
|
41
|
+
{ key: 'outbound_campaigns', label: 'Giden Kampanyalar' },
|
|
42
|
+
{ key: 'survey_builder', label: 'Anket Oluşturucu' },
|
|
43
|
+
{ key: 'whatsapp_notifications', label: 'WhatsApp Bildirimleri' },
|
|
44
|
+
{ key: 'whatsapp_agent', label: 'WhatsApp Agent' },
|
|
45
|
+
{ key: 'google_calendar', label: 'Google Takvim Entegrasyonu' },
|
|
46
|
+
{ key: 'operator_workflow', label: 'Estetisyen Yönlendirme' },
|
|
47
|
+
{ key: 'sms_notifications', label: 'SMS Bildirimleri (NetGSM)' },
|
|
48
|
+
{ key: 'appointment_validation', label: 'Randevu Onay (Toplu Arama)' },
|
|
49
|
+
{ key: 'inbound_call_schedule', label: 'Gelen Arama Programi' },
|
|
50
|
+
{ key: 'voice_transcription', label: 'Sesli Mesaj Transkripsiyonu' },
|
|
51
|
+
{ key: 'chat_continuity', label: 'Chat Continuity' },
|
|
52
|
+
{ key: 'conversation_forwarding', label: 'Konusma Yonlendirme' },
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
const DEFAULT_SUMMARY_PROMPT = `Sen bir telefon gorusmesi analiz asistanisin. Asagidaki transkripti analiz et ve JSON formatinda Turkce ozet cikar.
|
|
56
|
+
|
|
57
|
+
KURALLAR:
|
|
58
|
+
- Yanitini YALNIZCA gecerli JSON olarak ver, baska hicbir sey yazma.
|
|
59
|
+
- Markdown, backtick, aciklama veya ek metin ekleme.
|
|
60
|
+
- Bir alan icin anlamli veri yoksa, o alani JSON'a DAHIL ETME.
|
|
61
|
+
- Kisa ve net ol. Her alan en fazla 1-2 cumle olsun.
|
|
62
|
+
|
|
63
|
+
JSON SEMASI:
|
|
64
|
+
{
|
|
65
|
+
"arayan": "Arayanin ismi, eger kendini tanittiysa",
|
|
66
|
+
"amac": "Aramanin amaci, ornegin: Bilgi almak, Randevu talebi, Sikayet, Takip",
|
|
67
|
+
"talep": "Spesifik talep detayi (randevu zamani, istenen hizmet vb.)",
|
|
68
|
+
"durum": "Gorusme sonucu ve verilen yanit, 1-2 cumle",
|
|
69
|
+
"aksiyon": "Yapilmasi gereken takip aksiyonu varsa (geri donus, onay bekleniyor vb.)"
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
Transkript:
|
|
73
|
+
{transcript}`;
|
|
74
|
+
|
|
75
|
+
const DEFAULT_WHATSAPP_TEMPLATE = `\u{1F464} {arayan} | \u{1F4CC} {amac} | \u{1F5D3} {talep} | \u{1F4CB} {durum} | \u{1F9ED} {aksiyon}`;
|
|
76
|
+
|
|
77
|
+
interface Tenant {
|
|
78
|
+
_id: string;
|
|
79
|
+
name: string;
|
|
80
|
+
plan: string;
|
|
81
|
+
enabled_features: string[];
|
|
82
|
+
is_active: boolean;
|
|
83
|
+
deleted_at: string | null;
|
|
84
|
+
settings: {
|
|
85
|
+
default_language: string;
|
|
86
|
+
notification_recipients?: string[];
|
|
87
|
+
whatsapp_agent?: {
|
|
88
|
+
whatsapp_bridge_provider?: string;
|
|
89
|
+
unipile_account_id?: string | null;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
createdAt: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
interface UserRow { _id: string; name: string; email: string; role: string; createdAt: string }
|
|
96
|
+
interface AgentRow {
|
|
97
|
+
_id: string;
|
|
98
|
+
phone_number: string;
|
|
99
|
+
elevenlabs_agent_id: string;
|
|
100
|
+
agent_template: string;
|
|
101
|
+
direction: string;
|
|
102
|
+
is_active: boolean;
|
|
103
|
+
post_call_processing: {
|
|
104
|
+
strategy: string;
|
|
105
|
+
llm_provider: string;
|
|
106
|
+
summary_prompt: string;
|
|
107
|
+
system_message: string;
|
|
108
|
+
whatsapp_message_template: string;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const PAYMENT_METHOD_LABELS: Record<string, string> = {
|
|
113
|
+
cash: 'Nakit',
|
|
114
|
+
bank_transfer: 'Havale/EFT',
|
|
115
|
+
other: 'Diger',
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
interface PaymentRow {
|
|
119
|
+
_id: string;
|
|
120
|
+
type: 'subscription' | 'top_up';
|
|
121
|
+
plan_slug: string;
|
|
122
|
+
plan_name: string;
|
|
123
|
+
amount: number;
|
|
124
|
+
extra_minutes: number;
|
|
125
|
+
period_start: string;
|
|
126
|
+
period_end: string;
|
|
127
|
+
payment_method: string;
|
|
128
|
+
notes: string;
|
|
129
|
+
createdAt: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export default function AdminTenantDetail() {
|
|
133
|
+
const { id } = useParams<{ id: string }>();
|
|
134
|
+
const navigate = useNavigate();
|
|
135
|
+
const [tenant, setTenant] = useState<Tenant | null>(null);
|
|
136
|
+
const [users, setUsers] = useState<UserRow[]>([]);
|
|
137
|
+
const [agents, setAgents] = useState<AgentRow[]>([]);
|
|
138
|
+
const [callCount, setCallCount] = useState(0);
|
|
139
|
+
const [campaignCount, setCampaignCount] = useState(0);
|
|
140
|
+
const [loading, setLoading] = useState(true);
|
|
141
|
+
const [saving, setSaving] = useState(false);
|
|
142
|
+
|
|
143
|
+
const [name, setName] = useState('');
|
|
144
|
+
const [plan, setPlan] = useState('');
|
|
145
|
+
const [features, setFeatures] = useState<string[]>([]);
|
|
146
|
+
|
|
147
|
+
const [userDialogOpen, setUserDialogOpen] = useState(false);
|
|
148
|
+
const [agentDialogOpen, setAgentDialogOpen] = useState(false);
|
|
149
|
+
const [editingAgent, setEditingAgent] = useState<AgentRow | null>(null);
|
|
150
|
+
const [payments, setPayments] = useState<PaymentRow[]>([]);
|
|
151
|
+
const [paymentDialogOpen, setPaymentDialogOpen] = useState(false);
|
|
152
|
+
const [dbPlans, setDbPlans] = useState<{ slug: string; name: string; price: number; included_minutes: number }[]>([]);
|
|
153
|
+
const [recipients, setRecipients] = useState<string[]>([]);
|
|
154
|
+
const [newRecipient, setNewRecipient] = useState('');
|
|
155
|
+
const [bridgeProvider, setBridgeProvider] = useState('unipile');
|
|
156
|
+
const [availableProviders, setAvailableProviders] = useState<string[]>([]);
|
|
157
|
+
const [savingBridge, setSavingBridge] = useState(false);
|
|
158
|
+
const [savingRecipients, setSavingRecipients] = useState(false);
|
|
159
|
+
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
api.get('/admin/plans')
|
|
162
|
+
.then(({ data }) => setDbPlans(data.plans.filter((p: any) => p.is_active)))
|
|
163
|
+
.catch(() => {});
|
|
164
|
+
api.get('/admin/whatsapp-providers')
|
|
165
|
+
.then(({ data }) => setAvailableProviders(data.providers))
|
|
166
|
+
.catch(() => {});
|
|
167
|
+
}, []);
|
|
168
|
+
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
Promise.all([
|
|
171
|
+
api.get(`/admin/tenants/${id}`),
|
|
172
|
+
api.get(`/admin/tenants/${id}/payments`)
|
|
173
|
+
]).then(([tenantRes, paymentsRes]) => {
|
|
174
|
+
setTenant(tenantRes.data.tenant);
|
|
175
|
+
setUsers(tenantRes.data.users);
|
|
176
|
+
setAgents(tenantRes.data.agents);
|
|
177
|
+
setCallCount(tenantRes.data.callCount);
|
|
178
|
+
setCampaignCount(tenantRes.data.campaignCount);
|
|
179
|
+
setName(tenantRes.data.tenant.name);
|
|
180
|
+
setPlan(tenantRes.data.tenant.plan);
|
|
181
|
+
setFeatures([...tenantRes.data.tenant.enabled_features]);
|
|
182
|
+
setRecipients(tenantRes.data.tenant.settings?.notification_recipients || []);
|
|
183
|
+
setBridgeProvider(tenantRes.data.tenant.settings?.whatsapp_agent?.whatsapp_bridge_provider || 'unipile');
|
|
184
|
+
setPayments(paymentsRes.data.payments);
|
|
185
|
+
}).finally(() => setLoading(false));
|
|
186
|
+
}, [id]);
|
|
187
|
+
|
|
188
|
+
function toggleFeature(f: string) {
|
|
189
|
+
setFeatures(prev => prev.includes(f) ? prev.filter(x => x !== f) : [...prev, f]);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function handleSave() {
|
|
193
|
+
setSaving(true);
|
|
194
|
+
try {
|
|
195
|
+
const { data } = await api.put(`/admin/tenants/${id}`, { name, plan, enabled_features: features });
|
|
196
|
+
setTenant(data.tenant);
|
|
197
|
+
toast.success('Kaydedildi');
|
|
198
|
+
} catch (err: any) {
|
|
199
|
+
toast.error(err.response?.data?.error || 'Hata');
|
|
200
|
+
} finally {
|
|
201
|
+
setSaving(false);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async function saveRecipients(updated: string[]) {
|
|
206
|
+
setSavingRecipients(true);
|
|
207
|
+
try {
|
|
208
|
+
await api.put(`/admin/tenants/${id}`, {
|
|
209
|
+
settings: { notification_recipients: updated }
|
|
210
|
+
});
|
|
211
|
+
setRecipients(updated);
|
|
212
|
+
toast.success('Kaydedildi');
|
|
213
|
+
} catch (err: any) {
|
|
214
|
+
toast.error(err.response?.data?.error || 'Hata');
|
|
215
|
+
} finally {
|
|
216
|
+
setSavingRecipients(false);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function handleAddRecipient() {
|
|
221
|
+
const cleaned = newRecipient.replace(/\s/g, '');
|
|
222
|
+
if (!cleaned) return;
|
|
223
|
+
if (recipients.includes(cleaned)) {
|
|
224
|
+
toast.error('Bu numara zaten ekli');
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
setNewRecipient('');
|
|
228
|
+
saveRecipients([...recipients, cleaned]);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function handleRemoveRecipient(number: string) {
|
|
232
|
+
saveRecipients(recipients.filter(r => r !== number));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async function handleSaveBridgeProvider() {
|
|
236
|
+
setSavingBridge(true);
|
|
237
|
+
try {
|
|
238
|
+
await api.put(`/admin/tenants/${id}/whatsapp-bridge`, { provider: bridgeProvider });
|
|
239
|
+
toast.success('Kopru saglayicisi kaydedildi');
|
|
240
|
+
} catch (err: any) {
|
|
241
|
+
toast.error(err.response?.data?.error || 'Hata');
|
|
242
|
+
} finally {
|
|
243
|
+
setSavingBridge(false);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async function handleDeactivate() {
|
|
248
|
+
if (!confirm('Bu tenanti devre disi birakmak istediginize emin misiniz?')) return;
|
|
249
|
+
try {
|
|
250
|
+
const { data } = await api.put(`/admin/tenants/${id}/deactivate`);
|
|
251
|
+
setTenant(data.tenant);
|
|
252
|
+
toast.success('Tenant devre disi birakildi');
|
|
253
|
+
} catch (err: any) {
|
|
254
|
+
toast.error(err.response?.data?.error || 'Hata');
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async function handleReactivate() {
|
|
259
|
+
try {
|
|
260
|
+
const { data } = await api.put(`/admin/tenants/${id}/reactivate`);
|
|
261
|
+
setTenant(data.tenant);
|
|
262
|
+
toast.success('Tenant yeniden etkinlestirildi');
|
|
263
|
+
} catch (err: any) {
|
|
264
|
+
toast.error(err.response?.data?.error || 'Hata');
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async function handleHardDelete() {
|
|
269
|
+
if (!confirm('DIKKAT: Bu tenant ve tum verileri kalici olarak silinecek. Bu islem geri alinamaz. Devam etmek istiyor musunuz?')) return;
|
|
270
|
+
try {
|
|
271
|
+
await api.delete(`/admin/tenants/${id}`);
|
|
272
|
+
toast.success('Tenant kalici olarak silindi');
|
|
273
|
+
navigate('/admin/tenants');
|
|
274
|
+
} catch (err: any) {
|
|
275
|
+
toast.error(err.response?.data?.error || 'Hata');
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (loading) return <PageLoader />;
|
|
280
|
+
if (!tenant) return <p className="text-muted-foreground">Tenant bulunamadi</p>;
|
|
281
|
+
|
|
282
|
+
return (
|
|
283
|
+
<div>
|
|
284
|
+
<Button variant="ghost" size="sm" asChild className="mb-4">
|
|
285
|
+
<Link to="/admin/tenants">
|
|
286
|
+
<ArrowLeftIcon className="size-4 mr-1" />
|
|
287
|
+
Tenantlara Don
|
|
288
|
+
</Link>
|
|
289
|
+
</Button>
|
|
290
|
+
|
|
291
|
+
<h1 className="text-2xl font-bold tracking-tight mb-6">{tenant.name}</h1>
|
|
292
|
+
|
|
293
|
+
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4 mb-4">
|
|
294
|
+
<StatCard label="Kullanicilar" value={users.length} icon={<UsersIcon className="size-5" />} />
|
|
295
|
+
<StatCard label="Agentler" value={agents.length} icon={<BotIcon className="size-5" />} />
|
|
296
|
+
<StatCard label="Aramalar" value={callCount} icon={<PhoneIcon className="size-5" />} />
|
|
297
|
+
<StatCard label="Kampanyalar" value={campaignCount} icon={<MegaphoneIcon className="size-5" />} />
|
|
298
|
+
</div>
|
|
299
|
+
|
|
300
|
+
<div className="flex items-center justify-between mb-6">
|
|
301
|
+
<div className="flex gap-2">
|
|
302
|
+
<Button variant="outline" size="sm" asChild>
|
|
303
|
+
<Link to={`/admin/tenants/${id}/billable-items`}>
|
|
304
|
+
<ReceiptIcon className="size-4 mr-1" />
|
|
305
|
+
Faturalanabilir Kalemler
|
|
306
|
+
</Link>
|
|
307
|
+
</Button>
|
|
308
|
+
<Button variant="outline" size="sm" asChild>
|
|
309
|
+
<Link to={`/admin/whatsapp?tenant_id=${id}`}>
|
|
310
|
+
<MessageSquareIcon className="size-4 mr-1" />
|
|
311
|
+
WhatsApp Sohbetleri
|
|
312
|
+
</Link>
|
|
313
|
+
</Button>
|
|
314
|
+
</div>
|
|
315
|
+
<div className="flex gap-2">
|
|
316
|
+
{tenant.is_active === false ? (
|
|
317
|
+
<>
|
|
318
|
+
<Button variant="outline" size="sm" onClick={handleReactivate}>
|
|
319
|
+
Yeniden Etkinlestir
|
|
320
|
+
</Button>
|
|
321
|
+
<Button variant="destructive" size="sm" onClick={handleHardDelete}>
|
|
322
|
+
<TrashIcon className="size-4 mr-1" />
|
|
323
|
+
Kalici Sil
|
|
324
|
+
</Button>
|
|
325
|
+
</>
|
|
326
|
+
) : (
|
|
327
|
+
<Button variant="destructive" size="sm" onClick={handleDeactivate}>
|
|
328
|
+
Devre Disi Birak
|
|
329
|
+
</Button>
|
|
330
|
+
)}
|
|
331
|
+
</div>
|
|
332
|
+
</div>
|
|
333
|
+
|
|
334
|
+
{tenant.is_active === false && (
|
|
335
|
+
<Alert variant="destructive" className="mb-6">
|
|
336
|
+
<AlertDescription>
|
|
337
|
+
Bu tenant devre disi birakilmis.
|
|
338
|
+
{tenant.deleted_at && ` (${new Date(tenant.deleted_at).toLocaleDateString('tr-TR')})`}
|
|
339
|
+
</AlertDescription>
|
|
340
|
+
</Alert>
|
|
341
|
+
)}
|
|
342
|
+
|
|
343
|
+
{/* Tenant Settings */}
|
|
344
|
+
<Card className="mb-6">
|
|
345
|
+
<CardHeader>
|
|
346
|
+
<CardTitle>Tenant Ayarlari</CardTitle>
|
|
347
|
+
</CardHeader>
|
|
348
|
+
<CardContent className="space-y-4 max-w-md">
|
|
349
|
+
<div className="space-y-2">
|
|
350
|
+
<Label>Ad</Label>
|
|
351
|
+
<Input value={name} onChange={e => setName(e.target.value)} />
|
|
352
|
+
</div>
|
|
353
|
+
<div className="space-y-2">
|
|
354
|
+
<Label>Plan</Label>
|
|
355
|
+
<Select value={plan} onValueChange={setPlan}>
|
|
356
|
+
<SelectTrigger>
|
|
357
|
+
<SelectValue />
|
|
358
|
+
</SelectTrigger>
|
|
359
|
+
<SelectContent>
|
|
360
|
+
{dbPlans.map(p => (
|
|
361
|
+
<SelectItem key={p.slug} value={p.slug}>
|
|
362
|
+
{p.name} — {p.price.toLocaleString('tr-TR')}TL/ay ({p.included_minutes} dk)
|
|
363
|
+
</SelectItem>
|
|
364
|
+
))}
|
|
365
|
+
{/* Show current plan if not in DB list */}
|
|
366
|
+
{plan && !dbPlans.some(p => p.slug === plan) && (
|
|
367
|
+
<SelectItem value={plan}>{plan}</SelectItem>
|
|
368
|
+
)}
|
|
369
|
+
</SelectContent>
|
|
370
|
+
</Select>
|
|
371
|
+
</div>
|
|
372
|
+
<div className="space-y-3">
|
|
373
|
+
<Label>Ozellikler</Label>
|
|
374
|
+
{ALL_FEATURES.map(f => (
|
|
375
|
+
<div key={f.key} className="flex items-center gap-2">
|
|
376
|
+
<Checkbox id={`feat-${f.key}`} checked={features.includes(f.key)} onCheckedChange={() => toggleFeature(f.key)} />
|
|
377
|
+
<Label htmlFor={`feat-${f.key}`} className="text-sm font-normal">{f.label}</Label>
|
|
378
|
+
</div>
|
|
379
|
+
))}
|
|
380
|
+
</div>
|
|
381
|
+
<Button onClick={handleSave} disabled={saving}>
|
|
382
|
+
{saving && <Loader2Icon className="size-4 mr-2 animate-spin" />}
|
|
383
|
+
Kaydet
|
|
384
|
+
</Button>
|
|
385
|
+
|
|
386
|
+
{/* WhatsApp Bridge Provider — only shown when multiple providers available */}
|
|
387
|
+
{availableProviders.length > 1 && (
|
|
388
|
+
<div className="space-y-2 pt-4 border-t">
|
|
389
|
+
<Label>WhatsApp Kopru Saglayicisi</Label>
|
|
390
|
+
<div className="flex gap-2 items-center">
|
|
391
|
+
<Select value={bridgeProvider} onValueChange={setBridgeProvider}>
|
|
392
|
+
<SelectTrigger className="w-48">
|
|
393
|
+
<SelectValue />
|
|
394
|
+
</SelectTrigger>
|
|
395
|
+
<SelectContent>
|
|
396
|
+
{availableProviders.map(p => (
|
|
397
|
+
<SelectItem key={p} value={p}>
|
|
398
|
+
{p === 'unipile' ? 'Unipile (Bulut)' : 'Baileys (Yerel)'}
|
|
399
|
+
</SelectItem>
|
|
400
|
+
))}
|
|
401
|
+
</SelectContent>
|
|
402
|
+
</Select>
|
|
403
|
+
<Button
|
|
404
|
+
size="sm"
|
|
405
|
+
onClick={handleSaveBridgeProvider}
|
|
406
|
+
disabled={savingBridge || bridgeProvider === (tenant.settings?.whatsapp_agent?.whatsapp_bridge_provider || 'unipile')}
|
|
407
|
+
>
|
|
408
|
+
{savingBridge && <Loader2Icon className="size-4 mr-2 animate-spin" />}
|
|
409
|
+
Kaydet
|
|
410
|
+
</Button>
|
|
411
|
+
</div>
|
|
412
|
+
{tenant.settings?.whatsapp_agent?.unipile_account_id && (
|
|
413
|
+
<p className="text-xs text-amber-600">
|
|
414
|
+
Bu tenant aktif bir WhatsApp baglantisina sahip. Saglayici degistirmek icin once baglantisini kesin.
|
|
415
|
+
</p>
|
|
416
|
+
)}
|
|
417
|
+
</div>
|
|
418
|
+
)}
|
|
419
|
+
|
|
420
|
+
</CardContent>
|
|
421
|
+
</Card>
|
|
422
|
+
|
|
423
|
+
{/* Appointment Validation Config — only when feature enabled */}
|
|
424
|
+
{features.includes('appointment_validation') && (
|
|
425
|
+
<AppointmentValidationConfig tenantId={id!} agents={agents} tenant={tenant} />
|
|
426
|
+
)}
|
|
427
|
+
|
|
428
|
+
{/* Conversation Forwarding Config */}
|
|
429
|
+
{features.includes('conversation_forwarding') && (
|
|
430
|
+
<ConversationForwardingConfig tenantId={id!} tenant={tenant} />
|
|
431
|
+
)}
|
|
432
|
+
|
|
433
|
+
{/* WhatsApp Recipients */}
|
|
434
|
+
<Card className="mb-6">
|
|
435
|
+
<CardHeader>
|
|
436
|
+
<CardTitle className="text-sm flex items-center gap-2">
|
|
437
|
+
<MessageSquareIcon className="size-4" />
|
|
438
|
+
WhatsApp Alicilari
|
|
439
|
+
<Badge variant="secondary">{recipients.length}</Badge>
|
|
440
|
+
</CardTitle>
|
|
441
|
+
</CardHeader>
|
|
442
|
+
<CardContent className="space-y-4 max-w-md">
|
|
443
|
+
<div className="flex gap-2">
|
|
444
|
+
<Input
|
|
445
|
+
placeholder="+905551234567"
|
|
446
|
+
value={newRecipient}
|
|
447
|
+
onChange={e => setNewRecipient(e.target.value)}
|
|
448
|
+
onKeyDown={e => {
|
|
449
|
+
if (e.key === 'Enter') {
|
|
450
|
+
e.preventDefault();
|
|
451
|
+
handleAddRecipient();
|
|
452
|
+
}
|
|
453
|
+
}}
|
|
454
|
+
/>
|
|
455
|
+
<Button onClick={handleAddRecipient} disabled={savingRecipients || !newRecipient.trim()}>
|
|
456
|
+
{savingRecipients ? <Loader2Icon className="size-4 animate-spin" /> : <PlusIcon className="size-4" />}
|
|
457
|
+
</Button>
|
|
458
|
+
</div>
|
|
459
|
+
{recipients.length === 0 ? (
|
|
460
|
+
<p className="text-sm text-muted-foreground">Henuz alici eklenmemis.</p>
|
|
461
|
+
) : (
|
|
462
|
+
<div className="space-y-1">
|
|
463
|
+
{recipients.map(number => (
|
|
464
|
+
<div key={number} className="flex items-center justify-between py-2 px-3 rounded-md border">
|
|
465
|
+
<div className="flex items-center gap-2">
|
|
466
|
+
<PhoneIcon className="size-4 text-muted-foreground" />
|
|
467
|
+
<span className="text-sm font-mono">{number}</span>
|
|
468
|
+
</div>
|
|
469
|
+
<Button
|
|
470
|
+
variant="ghost"
|
|
471
|
+
size="sm"
|
|
472
|
+
onClick={() => handleRemoveRecipient(number)}
|
|
473
|
+
disabled={savingRecipients}
|
|
474
|
+
className="text-destructive hover:text-destructive"
|
|
475
|
+
>
|
|
476
|
+
<TrashIcon className="size-4" />
|
|
477
|
+
</Button>
|
|
478
|
+
</div>
|
|
479
|
+
))}
|
|
480
|
+
</div>
|
|
481
|
+
)}
|
|
482
|
+
</CardContent>
|
|
483
|
+
</Card>
|
|
484
|
+
|
|
485
|
+
{/* Users */}
|
|
486
|
+
<Card className="mb-6">
|
|
487
|
+
<CardHeader className="flex-row items-center justify-between">
|
|
488
|
+
<CardTitle className="text-sm">
|
|
489
|
+
Kullanicilar
|
|
490
|
+
<Badge variant="secondary" className="ml-2">{users.length}</Badge>
|
|
491
|
+
</CardTitle>
|
|
492
|
+
<Dialog open={userDialogOpen} onOpenChange={setUserDialogOpen}>
|
|
493
|
+
<DialogTrigger asChild>
|
|
494
|
+
<Button size="sm">
|
|
495
|
+
<PlusIcon className="size-4 mr-1" />
|
|
496
|
+
Kullanici Ekle
|
|
497
|
+
</Button>
|
|
498
|
+
</DialogTrigger>
|
|
499
|
+
<DialogContent>
|
|
500
|
+
<DialogHeader>
|
|
501
|
+
<DialogTitle>Kullanici Olustur</DialogTitle>
|
|
502
|
+
</DialogHeader>
|
|
503
|
+
<CreateUserForm tenantId={id!} onDone={(u) => {
|
|
504
|
+
setUsers([u, ...users]);
|
|
505
|
+
setUserDialogOpen(false);
|
|
506
|
+
toast.success('Kullanici olusturuldu');
|
|
507
|
+
}} />
|
|
508
|
+
</DialogContent>
|
|
509
|
+
</Dialog>
|
|
510
|
+
</CardHeader>
|
|
511
|
+
<CardContent className="px-0 py-0">
|
|
512
|
+
<Table>
|
|
513
|
+
<TableHeader>
|
|
514
|
+
<TableRow>
|
|
515
|
+
<TableHead className="pl-6">Isim</TableHead>
|
|
516
|
+
<TableHead>E-posta</TableHead>
|
|
517
|
+
<TableHead>Rol</TableHead>
|
|
518
|
+
<TableHead className="pr-6">Tarih</TableHead>
|
|
519
|
+
</TableRow>
|
|
520
|
+
</TableHeader>
|
|
521
|
+
<TableBody>
|
|
522
|
+
{users.length === 0 ? (
|
|
523
|
+
<TableRow>
|
|
524
|
+
<TableCell colSpan={4} className="text-center text-muted-foreground py-6">
|
|
525
|
+
Henuz kullanici yok
|
|
526
|
+
</TableCell>
|
|
527
|
+
</TableRow>
|
|
528
|
+
) : users.map(u => (
|
|
529
|
+
<TableRow key={u._id}>
|
|
530
|
+
<TableCell className="pl-6 font-medium">{u.name}</TableCell>
|
|
531
|
+
<TableCell className="text-muted-foreground">{u.email}</TableCell>
|
|
532
|
+
<TableCell><Badge variant="secondary">{u.role}</Badge></TableCell>
|
|
533
|
+
<TableCell className="text-muted-foreground pr-6">{new Date(u.createdAt).toLocaleDateString('tr-TR')}</TableCell>
|
|
534
|
+
</TableRow>
|
|
535
|
+
))}
|
|
536
|
+
</TableBody>
|
|
537
|
+
</Table>
|
|
538
|
+
</CardContent>
|
|
539
|
+
</Card>
|
|
540
|
+
|
|
541
|
+
{/* Agents */}
|
|
542
|
+
<Card>
|
|
543
|
+
<CardHeader className="flex-row items-center justify-between">
|
|
544
|
+
<CardTitle className="text-sm">
|
|
545
|
+
Agentler
|
|
546
|
+
<Badge variant="secondary" className="ml-2">{agents.length}</Badge>
|
|
547
|
+
</CardTitle>
|
|
548
|
+
<Dialog open={agentDialogOpen} onOpenChange={setAgentDialogOpen}>
|
|
549
|
+
<DialogTrigger asChild>
|
|
550
|
+
<Button size="sm">
|
|
551
|
+
<PlusIcon className="size-4 mr-1" />
|
|
552
|
+
Agent Ekle
|
|
553
|
+
</Button>
|
|
554
|
+
</DialogTrigger>
|
|
555
|
+
<DialogContent className="max-h-[85vh] overflow-y-auto">
|
|
556
|
+
<DialogHeader>
|
|
557
|
+
<DialogTitle>Agent Olustur</DialogTitle>
|
|
558
|
+
</DialogHeader>
|
|
559
|
+
<CreateAgentForm tenantId={id!} onDone={(a) => {
|
|
560
|
+
setAgents([a, ...agents]);
|
|
561
|
+
setAgentDialogOpen(false);
|
|
562
|
+
toast.success('Agent olusturuldu');
|
|
563
|
+
}} />
|
|
564
|
+
</DialogContent>
|
|
565
|
+
</Dialog>
|
|
566
|
+
</CardHeader>
|
|
567
|
+
<CardContent className="px-0 py-0">
|
|
568
|
+
{agents.length === 0 ? (
|
|
569
|
+
<p className="text-sm text-muted-foreground p-6">Henuz agent yok</p>
|
|
570
|
+
) : (
|
|
571
|
+
<Table>
|
|
572
|
+
<TableHeader>
|
|
573
|
+
<TableRow>
|
|
574
|
+
<TableHead className="pl-6">Telefon</TableHead>
|
|
575
|
+
<TableHead>ElevenLabs Agent</TableHead>
|
|
576
|
+
<TableHead>Durum</TableHead>
|
|
577
|
+
<TableHead className="pr-6 w-10"></TableHead>
|
|
578
|
+
</TableRow>
|
|
579
|
+
</TableHeader>
|
|
580
|
+
<TableBody>
|
|
581
|
+
{agents.map(a => (
|
|
582
|
+
<TableRow key={a._id}>
|
|
583
|
+
<TableCell className="pl-6 font-mono text-sm">{a.phone_number}</TableCell>
|
|
584
|
+
<TableCell className="font-mono text-xs text-muted-foreground">{a.elevenlabs_agent_id}</TableCell>
|
|
585
|
+
<TableCell>
|
|
586
|
+
<Badge variant={a.is_active ? 'secondary' : 'destructive'}
|
|
587
|
+
className={a.is_active ? 'bg-emerald-100 text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-400' : ''}>
|
|
588
|
+
{a.is_active ? 'Aktif' : 'Pasif'}
|
|
589
|
+
</Badge>
|
|
590
|
+
</TableCell>
|
|
591
|
+
<TableCell className="pr-6">
|
|
592
|
+
<Button variant="ghost" size="icon" className="size-8" onClick={() => setEditingAgent(a)}>
|
|
593
|
+
<PencilIcon className="size-4" />
|
|
594
|
+
</Button>
|
|
595
|
+
</TableCell>
|
|
596
|
+
</TableRow>
|
|
597
|
+
))}
|
|
598
|
+
</TableBody>
|
|
599
|
+
</Table>
|
|
600
|
+
)}
|
|
601
|
+
</CardContent>
|
|
602
|
+
</Card>
|
|
603
|
+
|
|
604
|
+
{/* Payments */}
|
|
605
|
+
<Card className="mt-6">
|
|
606
|
+
<CardHeader className="flex-row items-center justify-between">
|
|
607
|
+
<CardTitle className="text-sm">
|
|
608
|
+
Odeme Gecmisi
|
|
609
|
+
<Badge variant="secondary" className="ml-2">{payments.length}</Badge>
|
|
610
|
+
</CardTitle>
|
|
611
|
+
<Dialog open={paymentDialogOpen} onOpenChange={setPaymentDialogOpen}>
|
|
612
|
+
<DialogTrigger asChild>
|
|
613
|
+
<Button size="sm">
|
|
614
|
+
<PlusIcon className="size-4 mr-1" />
|
|
615
|
+
Odeme Kaydet
|
|
616
|
+
</Button>
|
|
617
|
+
</DialogTrigger>
|
|
618
|
+
<DialogContent>
|
|
619
|
+
<DialogHeader>
|
|
620
|
+
<DialogTitle>Odeme Kaydet</DialogTitle>
|
|
621
|
+
</DialogHeader>
|
|
622
|
+
<RecordPaymentForm
|
|
623
|
+
tenantId={id!}
|
|
624
|
+
currentPlanSlug={plan}
|
|
625
|
+
plans={dbPlans}
|
|
626
|
+
lastPeriodEnd={payments[0]?.period_end}
|
|
627
|
+
onDone={(p) => {
|
|
628
|
+
setPayments([p, ...payments]);
|
|
629
|
+
setPaymentDialogOpen(false);
|
|
630
|
+
toast.success('Odeme kaydedildi');
|
|
631
|
+
}}
|
|
632
|
+
/>
|
|
633
|
+
</DialogContent>
|
|
634
|
+
</Dialog>
|
|
635
|
+
</CardHeader>
|
|
636
|
+
<CardContent className="px-0 py-0">
|
|
637
|
+
{payments.length === 0 ? (
|
|
638
|
+
<p className="text-sm text-muted-foreground p-6">Henuz odeme kaydı yok</p>
|
|
639
|
+
) : (
|
|
640
|
+
<Table>
|
|
641
|
+
<TableHeader>
|
|
642
|
+
<TableRow>
|
|
643
|
+
<TableHead className="pl-6">Donem</TableHead>
|
|
644
|
+
<TableHead>Tur</TableHead>
|
|
645
|
+
<TableHead>Plan / Detay</TableHead>
|
|
646
|
+
<TableHead>Tutar</TableHead>
|
|
647
|
+
<TableHead>Yontem</TableHead>
|
|
648
|
+
<TableHead>Notlar</TableHead>
|
|
649
|
+
<TableHead className="pr-6">Kayit Tarihi</TableHead>
|
|
650
|
+
</TableRow>
|
|
651
|
+
</TableHeader>
|
|
652
|
+
<TableBody>
|
|
653
|
+
{payments.map(p => (
|
|
654
|
+
<TableRow key={p._id}>
|
|
655
|
+
<TableCell className="pl-6 whitespace-nowrap">
|
|
656
|
+
{new Date(p.period_start).toLocaleDateString('tr-TR')} — {new Date(p.period_end).toLocaleDateString('tr-TR')}
|
|
657
|
+
</TableCell>
|
|
658
|
+
<TableCell>
|
|
659
|
+
<Badge variant={p.type === 'top_up' ? 'default' : 'outline'} className="text-[10px]">
|
|
660
|
+
{p.type === 'top_up' ? 'Ek Dakika' : 'Abonelik'}
|
|
661
|
+
</Badge>
|
|
662
|
+
</TableCell>
|
|
663
|
+
<TableCell>
|
|
664
|
+
<Badge variant="secondary">{p.plan_name}</Badge>
|
|
665
|
+
{p.type === 'top_up' && p.extra_minutes > 0 && (
|
|
666
|
+
<span className="text-xs text-muted-foreground ml-1">+{p.extra_minutes} dk</span>
|
|
667
|
+
)}
|
|
668
|
+
</TableCell>
|
|
669
|
+
<TableCell className="font-medium">
|
|
670
|
+
{p.amount.toLocaleString('tr-TR')}TL
|
|
671
|
+
</TableCell>
|
|
672
|
+
<TableCell className="text-muted-foreground">
|
|
673
|
+
{PAYMENT_METHOD_LABELS[p.payment_method] || p.payment_method}
|
|
674
|
+
</TableCell>
|
|
675
|
+
<TableCell className="text-muted-foreground text-xs max-w-[200px] truncate">
|
|
676
|
+
{p.notes || '-'}
|
|
677
|
+
</TableCell>
|
|
678
|
+
<TableCell className="text-muted-foreground whitespace-nowrap pr-6">
|
|
679
|
+
{new Date(p.createdAt).toLocaleDateString('tr-TR')}
|
|
680
|
+
</TableCell>
|
|
681
|
+
</TableRow>
|
|
682
|
+
))}
|
|
683
|
+
</TableBody>
|
|
684
|
+
</Table>
|
|
685
|
+
)}
|
|
686
|
+
</CardContent>
|
|
687
|
+
</Card>
|
|
688
|
+
|
|
689
|
+
{/* Edit Agent Dialog */}
|
|
690
|
+
<Dialog open={!!editingAgent} onOpenChange={(open) => { if (!open) setEditingAgent(null); }}>
|
|
691
|
+
<DialogContent className="max-h-[85vh] overflow-y-auto">
|
|
692
|
+
<DialogHeader>
|
|
693
|
+
<DialogTitle>Agent Duzenle</DialogTitle>
|
|
694
|
+
</DialogHeader>
|
|
695
|
+
{editingAgent && (
|
|
696
|
+
<EditAgentForm agent={editingAgent} onDone={(updated) => {
|
|
697
|
+
setAgents(agents.map(a => a._id === updated._id ? updated : a));
|
|
698
|
+
setEditingAgent(null);
|
|
699
|
+
toast.success('Agent guncellendi');
|
|
700
|
+
}} />
|
|
701
|
+
)}
|
|
702
|
+
</DialogContent>
|
|
703
|
+
</Dialog>
|
|
704
|
+
</div>
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// ─── Create User Form ───────────────────────────────────────
|
|
709
|
+
|
|
710
|
+
function CreateUserForm({ tenantId, onDone }: { tenantId: string; onDone: (user: UserRow) => void }) {
|
|
711
|
+
const [email, setEmail] = useState('');
|
|
712
|
+
const [password, setPassword] = useState('');
|
|
713
|
+
const [name, setName] = useState('');
|
|
714
|
+
const [role, setRole] = useState('admin');
|
|
715
|
+
const [error, setError] = useState('');
|
|
716
|
+
const [loading, setLoading] = useState(false);
|
|
717
|
+
|
|
718
|
+
async function handleSubmit(e: React.FormEvent) {
|
|
719
|
+
e.preventDefault();
|
|
720
|
+
setLoading(true);
|
|
721
|
+
setError('');
|
|
722
|
+
try {
|
|
723
|
+
const { data } = await api.post(`/admin/tenants/${tenantId}/users`, { email, password, name, role });
|
|
724
|
+
onDone(data.user);
|
|
725
|
+
} catch (err: any) {
|
|
726
|
+
setError(err.response?.data?.error || 'Hata');
|
|
727
|
+
} finally {
|
|
728
|
+
setLoading(false);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
return (
|
|
733
|
+
<form onSubmit={handleSubmit} className="space-y-4">
|
|
734
|
+
{error && <Alert variant="destructive"><AlertDescription>{error}</AlertDescription></Alert>}
|
|
735
|
+
<div className="space-y-2">
|
|
736
|
+
<Label>Isim</Label>
|
|
737
|
+
<Input value={name} onChange={e => setName(e.target.value)} required />
|
|
738
|
+
</div>
|
|
739
|
+
<div className="space-y-2">
|
|
740
|
+
<Label>E-posta</Label>
|
|
741
|
+
<Input type="email" value={email} onChange={e => setEmail(e.target.value)} required />
|
|
742
|
+
</div>
|
|
743
|
+
<div className="space-y-2">
|
|
744
|
+
<Label>Sifre</Label>
|
|
745
|
+
<Input type="password" value={password} onChange={e => setPassword(e.target.value)} required minLength={8} />
|
|
746
|
+
</div>
|
|
747
|
+
<div className="space-y-2">
|
|
748
|
+
<Label>Rol</Label>
|
|
749
|
+
<Select value={role} onValueChange={setRole}>
|
|
750
|
+
<SelectTrigger><SelectValue /></SelectTrigger>
|
|
751
|
+
<SelectContent>
|
|
752
|
+
<SelectItem value="admin">Admin</SelectItem>
|
|
753
|
+
<SelectItem value="manager">Manager</SelectItem>
|
|
754
|
+
<SelectItem value="viewer">Viewer</SelectItem>
|
|
755
|
+
</SelectContent>
|
|
756
|
+
</Select>
|
|
757
|
+
</div>
|
|
758
|
+
<Button type="submit" disabled={loading} className="w-full">
|
|
759
|
+
{loading && <Loader2Icon className="size-4 mr-2 animate-spin" />}
|
|
760
|
+
Olustur
|
|
761
|
+
</Button>
|
|
762
|
+
</form>
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// ─── Create Agent Form ──────────────────────────────────────
|
|
767
|
+
|
|
768
|
+
interface ELAgent {
|
|
769
|
+
agent_id: string;
|
|
770
|
+
name: string;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
function CreateAgentForm({ tenantId, onDone }: { tenantId: string; onDone: (agent: AgentRow) => void }) {
|
|
774
|
+
const [phoneNumber, setPhoneNumber] = useState('');
|
|
775
|
+
const [elevenlabsAgentId, setElevenlabsAgentId] = useState('');
|
|
776
|
+
const [direction, setDirection] = useState('inbound');
|
|
777
|
+
const [summaryPrompt, setSummaryPrompt] = useState(DEFAULT_SUMMARY_PROMPT);
|
|
778
|
+
const [whatsappTemplate, setWhatsappTemplate] = useState(DEFAULT_WHATSAPP_TEMPLATE);
|
|
779
|
+
const [error, setError] = useState('');
|
|
780
|
+
const [loading, setLoading] = useState(false);
|
|
781
|
+
|
|
782
|
+
const [availableAgents, setAvailableAgents] = useState<ELAgent[]>([]);
|
|
783
|
+
const [loadingAgents, setLoadingAgents] = useState(true);
|
|
784
|
+
|
|
785
|
+
useEffect(() => {
|
|
786
|
+
api.get('/admin/elevenlabs/agents', { params: { page_size: '100' } })
|
|
787
|
+
.then(({ data }) => setAvailableAgents(
|
|
788
|
+
(data.agents || []).map((a: any) => ({ agent_id: a.agentId || a.agent_id, name: a.name }))
|
|
789
|
+
))
|
|
790
|
+
.catch(() => setAvailableAgents([]))
|
|
791
|
+
.finally(() => setLoadingAgents(false));
|
|
792
|
+
}, []);
|
|
793
|
+
|
|
794
|
+
async function handleSubmit(e: React.FormEvent) {
|
|
795
|
+
e.preventDefault();
|
|
796
|
+
setLoading(true);
|
|
797
|
+
setError('');
|
|
798
|
+
try {
|
|
799
|
+
const { data } = await api.post('/admin/agents', {
|
|
800
|
+
tenant_id: tenantId,
|
|
801
|
+
phone_number: phoneNumber,
|
|
802
|
+
elevenlabs_agent_id: elevenlabsAgentId,
|
|
803
|
+
direction,
|
|
804
|
+
post_call_processing: {
|
|
805
|
+
summary_prompt: summaryPrompt === DEFAULT_SUMMARY_PROMPT ? '' : summaryPrompt,
|
|
806
|
+
whatsapp_message_template: whatsappTemplate === DEFAULT_WHATSAPP_TEMPLATE ? '' : whatsappTemplate,
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
onDone(data.agent);
|
|
810
|
+
} catch (err: any) {
|
|
811
|
+
setError(err.response?.data?.error || 'Hata');
|
|
812
|
+
} finally {
|
|
813
|
+
setLoading(false);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
return (
|
|
818
|
+
<form onSubmit={handleSubmit} className="space-y-4">
|
|
819
|
+
{error && <Alert variant="destructive"><AlertDescription>{error}</AlertDescription></Alert>}
|
|
820
|
+
|
|
821
|
+
<div className="space-y-2">
|
|
822
|
+
<Label>ElevenLabs Agent</Label>
|
|
823
|
+
{loadingAgents ? (
|
|
824
|
+
<div className="flex items-center gap-2 text-sm text-muted-foreground py-2">
|
|
825
|
+
<Loader2Icon className="size-4 animate-spin" />
|
|
826
|
+
Agentler yukleniyor...
|
|
827
|
+
</div>
|
|
828
|
+
) : availableAgents.length === 0 ? (
|
|
829
|
+
<p className="text-sm text-muted-foreground py-2">
|
|
830
|
+
ElevenLabs'da agent bulunamadi.
|
|
831
|
+
</p>
|
|
832
|
+
) : (
|
|
833
|
+
<Select value={elevenlabsAgentId} onValueChange={setElevenlabsAgentId}>
|
|
834
|
+
<SelectTrigger>
|
|
835
|
+
<SelectValue placeholder="Agent secin..." />
|
|
836
|
+
</SelectTrigger>
|
|
837
|
+
<SelectContent>
|
|
838
|
+
{availableAgents.map(a => (
|
|
839
|
+
<SelectItem key={a.agent_id} value={a.agent_id}>
|
|
840
|
+
{a.name || a.agent_id}
|
|
841
|
+
</SelectItem>
|
|
842
|
+
))}
|
|
843
|
+
</SelectContent>
|
|
844
|
+
</Select>
|
|
845
|
+
)}
|
|
846
|
+
</div>
|
|
847
|
+
|
|
848
|
+
<div className="space-y-2">
|
|
849
|
+
<Label>Telefon Numarasi</Label>
|
|
850
|
+
<Input placeholder="+905551234567" value={phoneNumber} onChange={e => setPhoneNumber(e.target.value)} required />
|
|
851
|
+
</div>
|
|
852
|
+
|
|
853
|
+
<div className="space-y-2">
|
|
854
|
+
<Label>Yon</Label>
|
|
855
|
+
<Select value={direction} onValueChange={setDirection}>
|
|
856
|
+
<SelectTrigger><SelectValue /></SelectTrigger>
|
|
857
|
+
<SelectContent>
|
|
858
|
+
<SelectItem value="inbound">Gelen (Inbound)</SelectItem>
|
|
859
|
+
<SelectItem value="outbound">Giden (Outbound)</SelectItem>
|
|
860
|
+
<SelectItem value="both">Her Ikisi (Both)</SelectItem>
|
|
861
|
+
</SelectContent>
|
|
862
|
+
</Select>
|
|
863
|
+
</div>
|
|
864
|
+
|
|
865
|
+
<div className="space-y-2">
|
|
866
|
+
<Label>Ozet Promptu</Label>
|
|
867
|
+
<p className="text-xs text-muted-foreground">Transkript icin {'{transcript}'} yer tutucusunu kullanin.</p>
|
|
868
|
+
<Textarea
|
|
869
|
+
value={summaryPrompt}
|
|
870
|
+
onChange={e => setSummaryPrompt(e.target.value)}
|
|
871
|
+
rows={8}
|
|
872
|
+
/>
|
|
873
|
+
</div>
|
|
874
|
+
|
|
875
|
+
<div className="space-y-2">
|
|
876
|
+
<Label>WhatsApp Mesaj Sablonu</Label>
|
|
877
|
+
<p className="text-xs text-muted-foreground">
|
|
878
|
+
Kullanilabilir degiskenler: {'{summary}'}, {'{caller_number}'}, {'{duration}'}, {'{date}'}
|
|
879
|
+
</p>
|
|
880
|
+
<Textarea
|
|
881
|
+
value={whatsappTemplate}
|
|
882
|
+
onChange={e => setWhatsappTemplate(e.target.value)}
|
|
883
|
+
rows={5}
|
|
884
|
+
/>
|
|
885
|
+
</div>
|
|
886
|
+
|
|
887
|
+
<Button type="submit" disabled={loading || !elevenlabsAgentId || !phoneNumber} className="w-full">
|
|
888
|
+
{loading && <Loader2Icon className="size-4 mr-2 animate-spin" />}
|
|
889
|
+
Agent Olustur
|
|
890
|
+
</Button>
|
|
891
|
+
</form>
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// ─── Edit Agent Form ───────────────────────────────────────
|
|
896
|
+
|
|
897
|
+
function EditAgentForm({ agent, onDone }: { agent: AgentRow; onDone: (agent: AgentRow) => void }) {
|
|
898
|
+
const [phoneNumber, setPhoneNumber] = useState(agent.phone_number);
|
|
899
|
+
const [direction, setDirection] = useState(agent.direction || 'inbound');
|
|
900
|
+
const dbPrompt = agent.post_call_processing?.summary_prompt || '';
|
|
901
|
+
const dbTemplate = agent.post_call_processing?.whatsapp_message_template || '';
|
|
902
|
+
const [summaryPrompt, setSummaryPrompt] = useState(dbPrompt || DEFAULT_SUMMARY_PROMPT);
|
|
903
|
+
const [whatsappTemplate, setWhatsappTemplate] = useState(dbTemplate || DEFAULT_WHATSAPP_TEMPLATE);
|
|
904
|
+
const [isActive, setIsActive] = useState(agent.is_active);
|
|
905
|
+
const [error, setError] = useState('');
|
|
906
|
+
const [loading, setLoading] = useState(false);
|
|
907
|
+
|
|
908
|
+
async function handleSubmit(e: React.FormEvent) {
|
|
909
|
+
e.preventDefault();
|
|
910
|
+
setLoading(true);
|
|
911
|
+
setError('');
|
|
912
|
+
try {
|
|
913
|
+
// Save empty string if user kept the default — backend will use code defaults
|
|
914
|
+
const promptToSave = summaryPrompt === DEFAULT_SUMMARY_PROMPT ? '' : summaryPrompt;
|
|
915
|
+
const templateToSave = whatsappTemplate === DEFAULT_WHATSAPP_TEMPLATE ? '' : whatsappTemplate;
|
|
916
|
+
const { data } = await api.put(`/admin/agents/${agent._id}`, {
|
|
917
|
+
phone_number: phoneNumber,
|
|
918
|
+
direction,
|
|
919
|
+
is_active: isActive,
|
|
920
|
+
post_call_processing: { summary_prompt: promptToSave, whatsapp_message_template: templateToSave },
|
|
921
|
+
});
|
|
922
|
+
onDone(data.agent);
|
|
923
|
+
} catch (err: any) {
|
|
924
|
+
setError(err.response?.data?.error || 'Hata');
|
|
925
|
+
} finally {
|
|
926
|
+
setLoading(false);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
return (
|
|
931
|
+
<form onSubmit={handleSubmit} className="space-y-4">
|
|
932
|
+
{error && <Alert variant="destructive"><AlertDescription>{error}</AlertDescription></Alert>}
|
|
933
|
+
|
|
934
|
+
<div className="space-y-2">
|
|
935
|
+
<Label>ElevenLabs Agent ID</Label>
|
|
936
|
+
<Input value={agent.elevenlabs_agent_id} disabled className="font-mono text-xs" />
|
|
937
|
+
</div>
|
|
938
|
+
|
|
939
|
+
<div className="space-y-2">
|
|
940
|
+
<Label>Telefon Numarasi</Label>
|
|
941
|
+
<Input value={phoneNumber} onChange={e => setPhoneNumber(e.target.value)} required />
|
|
942
|
+
</div>
|
|
943
|
+
|
|
944
|
+
<div className="space-y-2">
|
|
945
|
+
<Label>Yon</Label>
|
|
946
|
+
<Select value={direction} onValueChange={setDirection}>
|
|
947
|
+
<SelectTrigger><SelectValue /></SelectTrigger>
|
|
948
|
+
<SelectContent>
|
|
949
|
+
<SelectItem value="inbound">Gelen (Inbound)</SelectItem>
|
|
950
|
+
<SelectItem value="outbound">Giden (Outbound)</SelectItem>
|
|
951
|
+
<SelectItem value="both">Her Ikisi (Both)</SelectItem>
|
|
952
|
+
</SelectContent>
|
|
953
|
+
</Select>
|
|
954
|
+
</div>
|
|
955
|
+
|
|
956
|
+
<div className="space-y-2">
|
|
957
|
+
<div className="flex items-center justify-between">
|
|
958
|
+
<Label>Ozet Promptu</Label>
|
|
959
|
+
{summaryPrompt !== DEFAULT_SUMMARY_PROMPT && (
|
|
960
|
+
<Button type="button" variant="ghost" size="sm" className="text-xs h-6" onClick={() => setSummaryPrompt(DEFAULT_SUMMARY_PROMPT)}>
|
|
961
|
+
Varsayilana sifirla
|
|
962
|
+
</Button>
|
|
963
|
+
)}
|
|
964
|
+
</div>
|
|
965
|
+
<Textarea
|
|
966
|
+
value={summaryPrompt}
|
|
967
|
+
onChange={e => setSummaryPrompt(e.target.value)}
|
|
968
|
+
rows={8}
|
|
969
|
+
/>
|
|
970
|
+
</div>
|
|
971
|
+
|
|
972
|
+
<div className="space-y-2">
|
|
973
|
+
<div className="flex items-center justify-between">
|
|
974
|
+
<Label>WhatsApp Mesaj Sablonu</Label>
|
|
975
|
+
{whatsappTemplate !== DEFAULT_WHATSAPP_TEMPLATE && (
|
|
976
|
+
<Button type="button" variant="ghost" size="sm" className="text-xs h-6" onClick={() => setWhatsappTemplate(DEFAULT_WHATSAPP_TEMPLATE)}>
|
|
977
|
+
Varsayilana sifirla
|
|
978
|
+
</Button>
|
|
979
|
+
)}
|
|
980
|
+
</div>
|
|
981
|
+
<Textarea
|
|
982
|
+
value={whatsappTemplate}
|
|
983
|
+
onChange={e => setWhatsappTemplate(e.target.value)}
|
|
984
|
+
rows={5}
|
|
985
|
+
/>
|
|
986
|
+
</div>
|
|
987
|
+
|
|
988
|
+
<div className="flex items-center gap-2">
|
|
989
|
+
<Checkbox id="edit-active" checked={isActive} onCheckedChange={(v) => setIsActive(!!v)} />
|
|
990
|
+
<Label htmlFor="edit-active" className="text-sm font-normal">Aktif</Label>
|
|
991
|
+
</div>
|
|
992
|
+
|
|
993
|
+
<Button type="submit" disabled={loading} className="w-full">
|
|
994
|
+
{loading && <Loader2Icon className="size-4 mr-2 animate-spin" />}
|
|
995
|
+
Kaydet
|
|
996
|
+
</Button>
|
|
997
|
+
</form>
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
// ─── Record Payment Form ─────────────────────────────────────
|
|
1002
|
+
|
|
1003
|
+
function RecordPaymentForm({ tenantId, currentPlanSlug, plans, lastPeriodEnd, onDone }: {
|
|
1004
|
+
tenantId: string;
|
|
1005
|
+
currentPlanSlug: string;
|
|
1006
|
+
plans: { slug: string; name: string; price: number; included_minutes: number }[];
|
|
1007
|
+
lastPeriodEnd?: string;
|
|
1008
|
+
onDone: (payment: PaymentRow) => void;
|
|
1009
|
+
}) {
|
|
1010
|
+
const [paymentType, setPaymentType] = useState<'subscription' | 'top_up'>('subscription');
|
|
1011
|
+
const [planSlug, setPlanSlug] = useState(currentPlanSlug);
|
|
1012
|
+
const selectedPlan = plans.find(p => p.slug === planSlug);
|
|
1013
|
+
const [amount, setAmount] = useState(selectedPlan?.price?.toString() || '');
|
|
1014
|
+
const [extraMinutes, setExtraMinutes] = useState('');
|
|
1015
|
+
const [periodStart, setPeriodStart] = useState(() => {
|
|
1016
|
+
if (lastPeriodEnd) {
|
|
1017
|
+
const d = new Date(lastPeriodEnd);
|
|
1018
|
+
d.setDate(d.getDate() + 1);
|
|
1019
|
+
return d.toISOString().split('T')[0];
|
|
1020
|
+
}
|
|
1021
|
+
const d = new Date();
|
|
1022
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-01`;
|
|
1023
|
+
});
|
|
1024
|
+
const [periodEnd, setPeriodEnd] = useState(() => {
|
|
1025
|
+
if (lastPeriodEnd) {
|
|
1026
|
+
const d = new Date(lastPeriodEnd);
|
|
1027
|
+
d.setDate(d.getDate() + 1);
|
|
1028
|
+
d.setMonth(d.getMonth() + 1);
|
|
1029
|
+
return d.toISOString().split('T')[0];
|
|
1030
|
+
}
|
|
1031
|
+
const d = new Date();
|
|
1032
|
+
d.setMonth(d.getMonth() + 1);
|
|
1033
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-01`;
|
|
1034
|
+
});
|
|
1035
|
+
const [paymentMethod, setPaymentMethod] = useState('cash');
|
|
1036
|
+
const [notes, setNotes] = useState('');
|
|
1037
|
+
const [error, setError] = useState('');
|
|
1038
|
+
const [loading, setLoading] = useState(false);
|
|
1039
|
+
|
|
1040
|
+
function handlePlanChange(slug: string) {
|
|
1041
|
+
setPlanSlug(slug);
|
|
1042
|
+
if (paymentType === 'subscription') {
|
|
1043
|
+
const p = plans.find(x => x.slug === slug);
|
|
1044
|
+
if (p) setAmount(p.price.toString());
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
function handleTypeChange(type: 'subscription' | 'top_up') {
|
|
1049
|
+
setPaymentType(type);
|
|
1050
|
+
if (type === 'subscription') {
|
|
1051
|
+
const p = plans.find(x => x.slug === planSlug);
|
|
1052
|
+
if (p) setAmount(p.price.toString());
|
|
1053
|
+
setExtraMinutes('');
|
|
1054
|
+
} else {
|
|
1055
|
+
setAmount('');
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
async function handleSubmit(e: React.FormEvent) {
|
|
1060
|
+
e.preventDefault();
|
|
1061
|
+
setLoading(true);
|
|
1062
|
+
setError('');
|
|
1063
|
+
try {
|
|
1064
|
+
const { data } = await api.post('/admin/payments', {
|
|
1065
|
+
tenant_id: tenantId,
|
|
1066
|
+
type: paymentType,
|
|
1067
|
+
plan_slug: planSlug,
|
|
1068
|
+
amount: parseFloat(amount),
|
|
1069
|
+
extra_minutes: paymentType === 'top_up' ? parseInt(extraMinutes, 10) : 0,
|
|
1070
|
+
period_start: periodStart,
|
|
1071
|
+
period_end: periodEnd,
|
|
1072
|
+
payment_method: paymentMethod,
|
|
1073
|
+
notes,
|
|
1074
|
+
});
|
|
1075
|
+
onDone(data.payment);
|
|
1076
|
+
} catch (err: any) {
|
|
1077
|
+
setError(err.response?.data?.error || 'Hata');
|
|
1078
|
+
} finally {
|
|
1079
|
+
setLoading(false);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
return (
|
|
1084
|
+
<form onSubmit={handleSubmit} className="space-y-4">
|
|
1085
|
+
{error && <Alert variant="destructive"><AlertDescription>{error}</AlertDescription></Alert>}
|
|
1086
|
+
|
|
1087
|
+
<div className="space-y-2">
|
|
1088
|
+
<Label>Odeme Turu</Label>
|
|
1089
|
+
<Select value={paymentType} onValueChange={v => handleTypeChange(v as 'subscription' | 'top_up')}>
|
|
1090
|
+
<SelectTrigger>
|
|
1091
|
+
<SelectValue />
|
|
1092
|
+
</SelectTrigger>
|
|
1093
|
+
<SelectContent>
|
|
1094
|
+
<SelectItem value="subscription">Abonelik Odemesi</SelectItem>
|
|
1095
|
+
<SelectItem value="top_up">Ek Dakika Yuklemesi</SelectItem>
|
|
1096
|
+
</SelectContent>
|
|
1097
|
+
</Select>
|
|
1098
|
+
</div>
|
|
1099
|
+
|
|
1100
|
+
<div className="space-y-2">
|
|
1101
|
+
<Label>Plan</Label>
|
|
1102
|
+
<Select value={planSlug} onValueChange={handlePlanChange}>
|
|
1103
|
+
<SelectTrigger>
|
|
1104
|
+
<SelectValue placeholder="Plan secin..." />
|
|
1105
|
+
</SelectTrigger>
|
|
1106
|
+
<SelectContent>
|
|
1107
|
+
{plans.map(p => (
|
|
1108
|
+
<SelectItem key={p.slug} value={p.slug}>
|
|
1109
|
+
{p.name} — {p.price.toLocaleString('tr-TR')}TL/ay
|
|
1110
|
+
</SelectItem>
|
|
1111
|
+
))}
|
|
1112
|
+
{planSlug && !plans.some(p => p.slug === planSlug) && (
|
|
1113
|
+
<SelectItem value={planSlug}>{planSlug}</SelectItem>
|
|
1114
|
+
)}
|
|
1115
|
+
</SelectContent>
|
|
1116
|
+
</Select>
|
|
1117
|
+
</div>
|
|
1118
|
+
|
|
1119
|
+
{paymentType === 'top_up' && (
|
|
1120
|
+
<div className="space-y-2">
|
|
1121
|
+
<Label>Ek Dakika</Label>
|
|
1122
|
+
<Input
|
|
1123
|
+
type="number"
|
|
1124
|
+
min="1"
|
|
1125
|
+
value={extraMinutes}
|
|
1126
|
+
onChange={e => setExtraMinutes(e.target.value)}
|
|
1127
|
+
placeholder="Orn: 100"
|
|
1128
|
+
required
|
|
1129
|
+
/>
|
|
1130
|
+
</div>
|
|
1131
|
+
)}
|
|
1132
|
+
|
|
1133
|
+
<div className="space-y-2">
|
|
1134
|
+
<Label>Tutar (TL)</Label>
|
|
1135
|
+
<Input type="number" step="0.01" value={amount} onChange={e => setAmount(e.target.value)} required />
|
|
1136
|
+
</div>
|
|
1137
|
+
|
|
1138
|
+
<div className="grid grid-cols-2 gap-4">
|
|
1139
|
+
<div className="space-y-2">
|
|
1140
|
+
<Label>Donem Baslangic</Label>
|
|
1141
|
+
<Input type="date" value={periodStart} onChange={e => setPeriodStart(e.target.value)} required />
|
|
1142
|
+
</div>
|
|
1143
|
+
<div className="space-y-2">
|
|
1144
|
+
<Label>Donem Bitis</Label>
|
|
1145
|
+
<Input type="date" value={periodEnd} onChange={e => setPeriodEnd(e.target.value)} required />
|
|
1146
|
+
</div>
|
|
1147
|
+
</div>
|
|
1148
|
+
|
|
1149
|
+
<div className="space-y-2">
|
|
1150
|
+
<Label>Odeme Yontemi</Label>
|
|
1151
|
+
<Select value={paymentMethod} onValueChange={setPaymentMethod}>
|
|
1152
|
+
<SelectTrigger>
|
|
1153
|
+
<SelectValue />
|
|
1154
|
+
</SelectTrigger>
|
|
1155
|
+
<SelectContent>
|
|
1156
|
+
<SelectItem value="cash">Nakit</SelectItem>
|
|
1157
|
+
<SelectItem value="bank_transfer">Havale/EFT</SelectItem>
|
|
1158
|
+
<SelectItem value="other">Diger</SelectItem>
|
|
1159
|
+
</SelectContent>
|
|
1160
|
+
</Select>
|
|
1161
|
+
</div>
|
|
1162
|
+
|
|
1163
|
+
<div className="space-y-2">
|
|
1164
|
+
<Label>Notlar</Label>
|
|
1165
|
+
<Textarea value={notes} onChange={e => setNotes(e.target.value)} rows={2} placeholder="Opsiyonel..." />
|
|
1166
|
+
</div>
|
|
1167
|
+
|
|
1168
|
+
<Button type="submit" disabled={loading || !planSlug || !amount || (paymentType === 'top_up' && !extraMinutes)} className="w-full">
|
|
1169
|
+
{loading && <Loader2Icon className="size-4 mr-2 animate-spin" />}
|
|
1170
|
+
{paymentType === 'top_up' ? 'Ek Dakika Kaydet' : 'Odemeyi Kaydet'}
|
|
1171
|
+
</Button>
|
|
1172
|
+
</form>
|
|
1173
|
+
);
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// ─── Appointment Validation Config ────────────────────────────
|
|
1177
|
+
|
|
1178
|
+
function ConversationForwardingConfig({ tenantId, tenant }: { tenantId: string; tenant: Tenant }) {
|
|
1179
|
+
const wa = (tenant as any).settings?.whatsapp_agent || {};
|
|
1180
|
+
const [phone, setPhone] = useState(wa.conversation_forwarding_phone || '');
|
|
1181
|
+
const [refPrefix, setRefPrefix] = useState(wa.operator_ref_prefix || 'R');
|
|
1182
|
+
const [saving, setSaving] = useState(false);
|
|
1183
|
+
|
|
1184
|
+
async function handleSave() {
|
|
1185
|
+
setSaving(true);
|
|
1186
|
+
try {
|
|
1187
|
+
await api.put(`/admin/tenants/${tenantId}`, {
|
|
1188
|
+
settings: {
|
|
1189
|
+
whatsapp_agent: {
|
|
1190
|
+
conversation_forwarding_phone: phone || null,
|
|
1191
|
+
operator_ref_prefix: refPrefix || 'R',
|
|
1192
|
+
},
|
|
1193
|
+
},
|
|
1194
|
+
});
|
|
1195
|
+
toast.success('Konusma yonlendirme ayarlari kaydedildi');
|
|
1196
|
+
} catch (err: any) {
|
|
1197
|
+
toast.error(err.response?.data?.error || 'Hata');
|
|
1198
|
+
} finally {
|
|
1199
|
+
setSaving(false);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
return (
|
|
1204
|
+
<Card className="mb-6">
|
|
1205
|
+
<CardHeader>
|
|
1206
|
+
<CardTitle className="text-sm flex items-center gap-2">
|
|
1207
|
+
<MessageSquareIcon className="size-4" />
|
|
1208
|
+
Konusma Yonlendirme Ayarlari
|
|
1209
|
+
</CardTitle>
|
|
1210
|
+
</CardHeader>
|
|
1211
|
+
<CardContent className="space-y-4 max-w-lg">
|
|
1212
|
+
<div className="space-y-2">
|
|
1213
|
+
<Label>Yonlendirme Telefon Numarasi</Label>
|
|
1214
|
+
<Input placeholder="+905551234567" value={phone} onChange={e => setPhone(e.target.value)} />
|
|
1215
|
+
</div>
|
|
1216
|
+
<div className="space-y-2">
|
|
1217
|
+
<Label>REF Kodu Oneki</Label>
|
|
1218
|
+
<Input placeholder="R" value={refPrefix} onChange={e => setRefPrefix(e.target.value.toUpperCase())} className="w-24" />
|
|
1219
|
+
</div>
|
|
1220
|
+
<Button onClick={handleSave} disabled={saving} size="sm">
|
|
1221
|
+
{saving && <Loader2Icon className="size-4 mr-2 animate-spin" />}
|
|
1222
|
+
Kaydet
|
|
1223
|
+
</Button>
|
|
1224
|
+
</CardContent>
|
|
1225
|
+
</Card>
|
|
1226
|
+
);
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
function AppointmentValidationConfig({ tenantId, agents, tenant }: { tenantId: string; agents: AgentRow[]; tenant: Tenant }) {
|
|
1230
|
+
const wa = (tenant as any).settings?.whatsapp_agent || {};
|
|
1231
|
+
const [agentId, setAgentId] = useState(wa.appointment_validation_agent_id || '');
|
|
1232
|
+
const [phoneNumId, setPhoneNumId] = useState(wa.appointment_validation_phone_number_id || '');
|
|
1233
|
+
const [saving, setSaving] = useState(false);
|
|
1234
|
+
const [elPhoneNumbers, setElPhoneNumbers] = useState<{ phoneNumberId: string; phoneNumber: string; label: string }[]>([]);
|
|
1235
|
+
|
|
1236
|
+
useEffect(() => {
|
|
1237
|
+
api.get('/inbound-call/phone-numbers')
|
|
1238
|
+
.then(res => setElPhoneNumbers(res.data.phoneNumbers || []))
|
|
1239
|
+
.catch(() => {});
|
|
1240
|
+
}, []);
|
|
1241
|
+
|
|
1242
|
+
async function handleSave() {
|
|
1243
|
+
setSaving(true);
|
|
1244
|
+
try {
|
|
1245
|
+
await api.put(`/admin/tenants/${tenantId}`, {
|
|
1246
|
+
settings: {
|
|
1247
|
+
whatsapp_agent: {
|
|
1248
|
+
appointment_validation_agent_id: agentId || null,
|
|
1249
|
+
appointment_validation_phone_number_id: phoneNumId || null,
|
|
1250
|
+
},
|
|
1251
|
+
},
|
|
1252
|
+
});
|
|
1253
|
+
toast.success('Randevu onay ayarlari kaydedildi');
|
|
1254
|
+
} catch (err: any) {
|
|
1255
|
+
toast.error(err.response?.data?.error || 'Hata');
|
|
1256
|
+
} finally {
|
|
1257
|
+
setSaving(false);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
return (
|
|
1262
|
+
<Card className="mb-6">
|
|
1263
|
+
<CardHeader>
|
|
1264
|
+
<CardTitle className="text-sm flex items-center gap-2">
|
|
1265
|
+
<PhoneOutgoingIcon className="size-4" />
|
|
1266
|
+
Randevu Onay Ayarlari
|
|
1267
|
+
</CardTitle>
|
|
1268
|
+
</CardHeader>
|
|
1269
|
+
<CardContent className="space-y-4 max-w-lg">
|
|
1270
|
+
<div className="space-y-2">
|
|
1271
|
+
<Label>Arama Agenti</Label>
|
|
1272
|
+
<Select value={agentId || '__none__'} onValueChange={v => setAgentId(v === '__none__' ? '' : v)}>
|
|
1273
|
+
<SelectTrigger>
|
|
1274
|
+
<SelectValue placeholder="Agent secin" />
|
|
1275
|
+
</SelectTrigger>
|
|
1276
|
+
<SelectContent>
|
|
1277
|
+
<SelectItem value="__none__">-- Secilmedi --</SelectItem>
|
|
1278
|
+
{agents.filter(a => a.is_active).map(a => (
|
|
1279
|
+
<SelectItem key={a._id} value={a._id}>
|
|
1280
|
+
{a.agent_template} — {a.phone_number}
|
|
1281
|
+
</SelectItem>
|
|
1282
|
+
))}
|
|
1283
|
+
</SelectContent>
|
|
1284
|
+
</Select>
|
|
1285
|
+
<p className="text-[11px] text-muted-foreground">
|
|
1286
|
+
Randevu onay aramalarinda kullanilacak ElevenLabs agenti
|
|
1287
|
+
</p>
|
|
1288
|
+
</div>
|
|
1289
|
+
|
|
1290
|
+
<div className="space-y-2">
|
|
1291
|
+
<Label>ElevenLabs Telefon Numarasi</Label>
|
|
1292
|
+
<Select value={phoneNumId || '__none__'} onValueChange={v => setPhoneNumId(v === '__none__' ? '' : v)}>
|
|
1293
|
+
<SelectTrigger>
|
|
1294
|
+
<SelectValue placeholder="Telefon numarasi secin" />
|
|
1295
|
+
</SelectTrigger>
|
|
1296
|
+
<SelectContent>
|
|
1297
|
+
<SelectItem value="__none__">-- Secilmedi --</SelectItem>
|
|
1298
|
+
{elPhoneNumbers.map(pn => (
|
|
1299
|
+
<SelectItem key={pn.phoneNumberId} value={pn.phoneNumberId}>
|
|
1300
|
+
{pn.phoneNumber} {pn.label ? `(${pn.label})` : ''}
|
|
1301
|
+
</SelectItem>
|
|
1302
|
+
))}
|
|
1303
|
+
</SelectContent>
|
|
1304
|
+
</Select>
|
|
1305
|
+
<p className="text-[11px] text-muted-foreground">
|
|
1306
|
+
Randevu onay aramalarinda kullanilacak telefon numarasi
|
|
1307
|
+
</p>
|
|
1308
|
+
</div>
|
|
1309
|
+
|
|
1310
|
+
<Button onClick={handleSave} disabled={saving} size="sm">
|
|
1311
|
+
{saving && <Loader2Icon className="size-4 mr-2 animate-spin" />}
|
|
1312
|
+
Kaydet
|
|
1313
|
+
</Button>
|
|
1314
|
+
</CardContent>
|
|
1315
|
+
</Card>
|
|
1316
|
+
);
|
|
1317
|
+
}
|