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,96 @@
|
|
|
1
|
+
# Production Migration Guide
|
|
2
|
+
|
|
3
|
+
> Required migrations for the WhatsApp Agent session-centric architecture and agent reference updates.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
- Node.js 18+ with `tsx` available (`npx tsx`)
|
|
10
|
+
- `MONGODB_URI` set in `.env` pointing to the target database
|
|
11
|
+
- Deploy the new code **before** running migrations (new models must be registered)
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Migration 1: Session Architecture (`migrate-sessions.ts`)
|
|
16
|
+
|
|
17
|
+
Migrates from the old chat-centric architecture (session fields embedded on `WhatsAppChat`) to the new session-centric architecture (`WhatsAppSession` collection).
|
|
18
|
+
|
|
19
|
+
### What it does
|
|
20
|
+
|
|
21
|
+
1. Creates `WhatsAppSession` documents from old embedded chat fields (`mode`, `session_status`, `taken_over_by`, etc.)
|
|
22
|
+
2. Backfills `session_id` on existing `WhatsAppMessage` documents
|
|
23
|
+
3. Sets `is_closed` and `active_session_id` on `WhatsAppChat` documents
|
|
24
|
+
4. Removes 10 old embedded fields from chats via `$unset`
|
|
25
|
+
|
|
26
|
+
### Fields removed from `WhatsAppChat`
|
|
27
|
+
|
|
28
|
+
`mode`, `session_status`, `session_started_at`, `session_grace_deadline`, `session_resolved_by`, `taken_over_by`, `taken_over_at`, `elevenlabs_conversation_id`, `elevenlabs_conversation_created_at`, `elevenlabs_last_interaction_at`
|
|
29
|
+
|
|
30
|
+
### Run
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Preview changes (no writes)
|
|
34
|
+
npx tsx scripts/migrate-sessions.ts --dry-run
|
|
35
|
+
|
|
36
|
+
# Execute migration
|
|
37
|
+
npx tsx scripts/migrate-sessions.ts
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Idempotent
|
|
41
|
+
|
|
42
|
+
Skips chats that already have `active_session_id` set. Safe to re-run.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Migration 2: Agent Reference (`migrate-agent-ref.ts`)
|
|
47
|
+
|
|
48
|
+
Converts the old `elevenlabs_agent_id` string in tenant WhatsApp settings to an `agent_id` ObjectId reference to the `Agent` model.
|
|
49
|
+
|
|
50
|
+
### What it does
|
|
51
|
+
|
|
52
|
+
1. Finds tenants with `settings.whatsapp_agent.elevenlabs_agent_id` set
|
|
53
|
+
2. Looks up the matching `Agent` document (by ElevenLabs ID, or falls back to tenant's active agent)
|
|
54
|
+
3. Sets `settings.whatsapp_agent.agent_id` to the Agent's ObjectId
|
|
55
|
+
4. Removes the old `elevenlabs_agent_id` field
|
|
56
|
+
|
|
57
|
+
### Run
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Preview changes (no writes)
|
|
61
|
+
npx tsx scripts/migrate-agent-ref.ts --dry-run
|
|
62
|
+
|
|
63
|
+
# Execute migration
|
|
64
|
+
npx tsx scripts/migrate-agent-ref.ts
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Idempotent
|
|
68
|
+
|
|
69
|
+
Skips tenants that already have `agent_id` set. Safe to re-run.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Deployment Order
|
|
74
|
+
|
|
75
|
+
1. **Deploy** new code to production
|
|
76
|
+
2. **Run** `migrate-sessions.ts` (creates the `WhatsAppSession` collection the new code depends on)
|
|
77
|
+
3. **Run** `migrate-agent-ref.ts` (needs `Agent` documents to resolve references)
|
|
78
|
+
4. **Verify** via dry-run or DB check that migrations completed
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Full sequence on prod
|
|
82
|
+
MONGODB_URI=mongodb+srv://... npx tsx scripts/migrate-sessions.ts --dry-run
|
|
83
|
+
MONGODB_URI=mongodb+srv://... npx tsx scripts/migrate-sessions.ts
|
|
84
|
+
MONGODB_URI=mongodb+srv://... npx tsx scripts/migrate-agent-ref.ts --dry-run
|
|
85
|
+
MONGODB_URI=mongodb+srv://... npx tsx scripts/migrate-agent-ref.ts
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Rollback
|
|
91
|
+
|
|
92
|
+
Both migrations are forward-only. The old embedded fields are removed via `$unset`. If you need to rollback:
|
|
93
|
+
|
|
94
|
+
- The new code is backward-compatible with missing sessions (startup recovery will handle `waiting` sessions)
|
|
95
|
+
- Old frontend code would need the embedded fields restored manually from the `WhatsAppSession` documents
|
|
96
|
+
- In practice, rollback is not recommended — fix forward instead
|
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
# NestJS Architecture Audit -- Gaps Report
|
|
2
|
+
|
|
3
|
+
> Generated: 2026-04-03
|
|
4
|
+
> Scope: All architecture docs (00--21) vs. NestJS source at `nestjs/src/`
|
|
5
|
+
> Reference: `docs/IMPLEMENTATION_STATUS.md` cross-checked
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Documented Features NOT Implemented
|
|
10
|
+
|
|
11
|
+
### 1.1 WhatsApp AI Engine (Doc 04)
|
|
12
|
+
|
|
13
|
+
| Gap | Doc Reference | Priority |
|
|
14
|
+
|-----|--------------|----------|
|
|
15
|
+
| ElevenLabs WebSocket connection lifecycle (signed URL, handshake, keepalive, lazy reconnect) | 04 Section 10 | **P0** |
|
|
16
|
+
| `triggerAiResponse()` -- send combined messages to ElevenLabs via WS `user_message` | 04 Section 9-10 | **P0** |
|
|
17
|
+
| `buildChatContext()` -- timeline builder for `contextual_update` | 04 Section 4 "Chat Context Building" | **P0** |
|
|
18
|
+
| Grace period BullMQ processor (`whatsapp:grace`) -- verify session state, activate AI, replay pending messages | 04 Section 1 | **P0** |
|
|
19
|
+
| Message buffer BullMQ processor (`whatsapp:message-buffer`) -- collect + combine pending messages, send to AI | 04 Section 1 | **P0** |
|
|
20
|
+
| Session cleanup sweep processor (`whatsapp:session-cleanup`) -- 2h inactivity auto-resolve | 04 Section 1 | **P0** |
|
|
21
|
+
| Cost sweep processor (`whatsapp:cost-sweep`) -- fetch ElevenLabs conversation costs | 04 Section 12 | **P1** |
|
|
22
|
+
| Profile update processor (`whatsapp:profile-update`) -- AI summary regeneration via AIModule | 04 Section 8 | **P1** |
|
|
23
|
+
| Session labels processor (`whatsapp:session-labels`) -- sentiment + category via AIModule | 04 Section 8 | **P1** |
|
|
24
|
+
| Message cleanup processor (`whatsapp:message-cleanup`) -- delete old messages + MinIO media | 04 Section 12 | **P1** |
|
|
25
|
+
| Operator expiry processor (`whatsapp:operator-expiry`) -- expire pending requests, notify AI | 05 Section 4 | **P1** |
|
|
26
|
+
| Dynamic variables sent to ElevenLabs (`user_summary`, `current_date`, `continuation_directive`) | 04 Section 4 | **P0** |
|
|
27
|
+
| Chat continuity on WS reconnection (`continuation_directive` builder) | 04 Section 5 | **P1** |
|
|
28
|
+
| AI shift scheduling check (outside clinic hours logic) | 04 Section 6 | **P1** |
|
|
29
|
+
| Session recovery on startup (re-evaluate stuck `waiting` sessions) | 04 Section 13 | **P1** |
|
|
30
|
+
| Voice transcription (STT) -- download audio from Meta, send to ElevenLabs Scribe | 04 Section 2 Step 3 | **P1** |
|
|
31
|
+
| Message deduplication on echo (match by `msg_external_id` or text+timestamp fallback) | 04 Section 12 | **P0** |
|
|
32
|
+
| System message filtering (40+ regex patterns for non-conversational messages) | 04 Section 2 Step 2 | **P0** |
|
|
33
|
+
| Patient find-or-create on first contact | 04 Section 2 Step 5 | **P0** |
|
|
34
|
+
| Fixed first message sending on new session | 04 Section 11 | **P1** |
|
|
35
|
+
| Self-sent message handling (resolve `waiting` as `human`, auto-switch `active` sessions) | 04 Section 10 | **P0** |
|
|
36
|
+
| Redis WS connection state (`ws:conn:{chatId}` hash with agentId, sessionId, etc.) | 04 Section 7 | **P0** |
|
|
37
|
+
|
|
38
|
+
**Status in code:** `whatsapp-agent.service.ts` has method signatures but all core methods contain only `// TODO` comments. All 8 WhatsApp BullMQ processors are stubs (`process()` body is just a TODO comment).
|
|
39
|
+
|
|
40
|
+
### 1.2 Operator Workflow (Doc 05)
|
|
41
|
+
|
|
42
|
+
| Gap | Doc Reference | Priority |
|
|
43
|
+
|-----|--------------|----------|
|
|
44
|
+
| `forwardToOperator()` -- find media, generate REF code, forward via Meta API with 500ms delay | 05 Section 2 | **P0** |
|
|
45
|
+
| `handleOperatorReply()` -- detect operator phone, extract REF code, update OperatorRequest, inject response | 05 Section 3 | **P0** |
|
|
46
|
+
| `injectOperatorResponse()` -- recreate WS if dead, send contextual_update + user_message | 05 Section 3 | **P0** |
|
|
47
|
+
| Forward conversation to operator (text-only variant) | 05 Section 5 | **P1** |
|
|
48
|
+
| Send example photo from MinIO | 05 Section 6 | **P1** |
|
|
49
|
+
| REF code generation (random 4-char alphanumeric with collision check) | 05 Section 8 | **P0** |
|
|
50
|
+
| Operator reply detection in webhook handler (sender phone check + REF code regex) | 05 Section 3 | **P0** |
|
|
51
|
+
|
|
52
|
+
**Status in code:** `operator.service.ts` has method skeletons but `forwardToOperator()` says `// TODO: Forward media to operator phone via Meta Business API`, `handleOperatorReply()` says `// TODO: Inject operator response into ElevenLabs conversation`, `handleExpiredRequest()` says `// TODO: Notify AI to inform patient`.
|
|
53
|
+
|
|
54
|
+
### 1.3 Client Tool Handlers (Doc 10) -- ALL 13 are TODO stubs
|
|
55
|
+
|
|
56
|
+
| Tool | File | Priority |
|
|
57
|
+
|------|------|----------|
|
|
58
|
+
| `check_availability` | `tools/handlers/calendar.tools.ts` | **P0** |
|
|
59
|
+
| `reserve_slot` | `tools/handlers/calendar.tools.ts` | **P0** |
|
|
60
|
+
| `list_reservations` | `tools/handlers/calendar.tools.ts` | **P0** |
|
|
61
|
+
| `cancel_reservation` | `tools/handlers/calendar.tools.ts` | **P0** |
|
|
62
|
+
| `reschedule_reservation` | `tools/handlers/calendar.tools.ts` | **P0** |
|
|
63
|
+
| `check_patient_history` | `tools/handlers/patient.tools.ts` | **P1** |
|
|
64
|
+
| `call_patient` | `tools/handlers/patient.tools.ts` | **P1** |
|
|
65
|
+
| `forward_to_operator` | `tools/handlers/operator.tools.ts` | **P0** |
|
|
66
|
+
| `forward_conversation` | `tools/handlers/operator.tools.ts` | **P1** |
|
|
67
|
+
| `send_example_photo` | `tools/handlers/operator.tools.ts` | **P1** |
|
|
68
|
+
| `confirm_appointment_validation` | `tools/handlers/validation.tools.ts` | **P1** |
|
|
69
|
+
| `request_payment` | `tools/handlers/payment.tools.ts` | **STUB** |
|
|
70
|
+
| `send_sms` | `tools/handlers/notification.tools.ts` | **STUB** |
|
|
71
|
+
|
|
72
|
+
**Status in code:** All handler methods have `@Tool()` decorators with proper metadata (name, description, parameters, requiredFeatures, channels) but the method bodies are `// TODO: Delegate to ...` stubs that return placeholder results.
|
|
73
|
+
|
|
74
|
+
### 1.4 WebSocket Gateway (Doc 17) -- NOT CREATED
|
|
75
|
+
|
|
76
|
+
| Gap | Doc Reference | Priority |
|
|
77
|
+
|-----|--------------|----------|
|
|
78
|
+
| `EventsGateway` (`@WebSocketGateway` with Socket.IO) | 17 Section 2 | **P0** |
|
|
79
|
+
| JWT authentication on WS handshake | 17 Section 2.2 | **P0** |
|
|
80
|
+
| Tenant room joining (`tenant:{tenantId}`) | 17 Section 2.3 | **P0** |
|
|
81
|
+
| Redis adapter for multi-instance support | 17 Section 2.4 | **P1** |
|
|
82
|
+
| 11 event types (`chat:new`, `chat:message`, `chat:session-status`, `chat:typing`, `call:new`, `call:completed`, `lead:new`, `appointment:new`, `appointment:cancelled`, `notification`, `validation:status`) | 17 Section 3 | **P0** |
|
|
83
|
+
| `@OnEvent` listeners that broadcast to tenant rooms | 17 Section 3.5 | **P0** |
|
|
84
|
+
| Typing indicator handler (`@SubscribeMessage('typing')`) | 17 Section 7 | **P2** |
|
|
85
|
+
| `LiveChatService` for human message sending | 17 Section 8 | **P0** |
|
|
86
|
+
| `POST /whatsapp/chats/:chatId/send-media` (multipart upload, MinIO storage, send via Meta API) | 17 Section 4.5 | **P1** |
|
|
87
|
+
|
|
88
|
+
**Status in code:** No `events.gateway.ts` file exists anywhere. No `live-chat.service.ts` exists. Packages `@nestjs/websockets`, `@nestjs/platform-socket.io`, `socket.io`, `@socket.io/redis-adapter` are installed in `package.json` but unused. The WhatsApp controller has `takeover`, `release`, `resolve`, and `send message` endpoints, but there is no `send-media` endpoint and no real-time event broadcasting.
|
|
89
|
+
|
|
90
|
+
### 1.5 Prisma Tenant-Scoping Middleware (Doc 00, 12)
|
|
91
|
+
|
|
92
|
+
| Gap | Doc Reference | Priority |
|
|
93
|
+
|-----|--------------|----------|
|
|
94
|
+
| Prisma `$use` middleware that auto-injects `WHERE tenantId` on every query | 00 Rule 1, 12 "Tenant Data Isolation" | **P0** |
|
|
95
|
+
| Cross-tenant access requiring `superadmin` role + explicit `allTenants: true` flag | 00 Rule 1 | **P0** |
|
|
96
|
+
|
|
97
|
+
**Status in code:** No `prisma.$use()` call exists anywhere. `IMPLEMENTATION_STATUS.md` acknowledges: "Tenant-scoped queries (Prisma middleware) -- Structure ready, middleware TODO". Each service currently manually adds `tenantId` WHERE clauses, which is error-prone and not enforced.
|
|
98
|
+
|
|
99
|
+
### 1.6 Request Context (AsyncLocalStorage) (Doc 13)
|
|
100
|
+
|
|
101
|
+
| Gap | Doc Reference | Priority |
|
|
102
|
+
|-----|--------------|----------|
|
|
103
|
+
| `RequestContextInterceptor` with `AsyncLocalStorage` for correlation IDs | 13 "AsyncLocalStorage for Request Context Propagation" | **P1** |
|
|
104
|
+
| `X-Request-Id` header propagation across service calls and queue jobs | 13 Section "Structured Log Format" | **P1** |
|
|
105
|
+
| Correlation ID attached to all log entries | 13 Section "Structured Log Format" | **P1** |
|
|
106
|
+
|
|
107
|
+
**Status in code:** No `AsyncLocalStorage` usage anywhere in the codebase. No `RequestContextInterceptor` exists. No `src/common/interceptors/` directory exists at all.
|
|
108
|
+
|
|
109
|
+
### 1.7 HTTP Exception Filter (Doc 00)
|
|
110
|
+
|
|
111
|
+
| Gap | Doc Reference | Priority |
|
|
112
|
+
|-----|--------------|----------|
|
|
113
|
+
| `HttpExceptionFilter` for standardized error responses | 00 Section 6 "Common (Shared)" | **P1** |
|
|
114
|
+
|
|
115
|
+
**Status in code:** No `src/common/filters/` directory exists. No global exception filter is registered.
|
|
116
|
+
|
|
117
|
+
### 1.8 ElevenLabs Post-Call Webhook Processing (Doc 08)
|
|
118
|
+
|
|
119
|
+
| Gap | Doc Reference | Priority |
|
|
120
|
+
|-----|--------------|----------|
|
|
121
|
+
| `elevenlabs:webhook` BullMQ processor -- full pipeline: find agent, resolve clinic, generate AI summary, create Call + CallDetail, generate labels, log billing, create Lead, send WA notification, send SMS, emit events | 08 Section 3 | **P0** |
|
|
122
|
+
| `elevenlabs:tools` BullMQ processor -- tool webhook processing during voice calls | 08 Section 4 | **P0** |
|
|
123
|
+
|
|
124
|
+
**Status in code:** `elevenlabs-webhook.processor.ts` has `// TODO: Implement post-call processing`. The `elevenlabs-tool.controller.ts` returns `{ result: 'not_implemented' }`.
|
|
125
|
+
|
|
126
|
+
### 1.9 Outbound Campaign Dispatch (Doc 09)
|
|
127
|
+
|
|
128
|
+
| Gap | Doc Reference | Priority |
|
|
129
|
+
|-----|--------------|----------|
|
|
130
|
+
| `outbound-campaigns:dispatch` processor -- call dispatch with time window, concurrency, retry logic | 09 Section 5 | **P1** |
|
|
131
|
+
| `outbound-campaigns:sync` processor -- status sync from ElevenLabs | 09 Section 9 | **P1** |
|
|
132
|
+
|
|
133
|
+
**Status in code:** `campaign-dispatch.processor.ts` has `// TODO: Implement outbound call dispatch`.
|
|
134
|
+
|
|
135
|
+
### 1.10 Appointment Validation Processors (Doc 07)
|
|
136
|
+
|
|
137
|
+
| Gap | Doc Reference | Priority |
|
|
138
|
+
|-----|--------------|----------|
|
|
139
|
+
| `appointment-validation:dispatch` processor -- batch call dispatch | 07 Section 6 | **P1** |
|
|
140
|
+
| `appointment-validation:sync` processor -- background status sync | 07 Section 6 | **P1** |
|
|
141
|
+
|
|
142
|
+
**Status in code:** Both processors are stubs with TODO comments.
|
|
143
|
+
|
|
144
|
+
### 1.11 Billing Processors (Doc 11)
|
|
145
|
+
|
|
146
|
+
| Gap | Doc Reference | Priority |
|
|
147
|
+
|-----|--------------|----------|
|
|
148
|
+
| `billing:snapshot` processor -- daily snapshot of expired periods | 11 "Period Lifecycle" | **P1** |
|
|
149
|
+
| `billing:alerts` processor -- daily usage threshold checks + SMS alerts | 11 "Billing Alert Check" | **P1** |
|
|
150
|
+
|
|
151
|
+
**Status in code:** Queues registered in QueueModule but no processor files exist.
|
|
152
|
+
|
|
153
|
+
### 1.12 Infrastructure Processors (Doc 16)
|
|
154
|
+
|
|
155
|
+
| Gap | Doc Reference | Priority |
|
|
156
|
+
|-----|--------------|----------|
|
|
157
|
+
| `inbound-call:schedule-sync` processor -- sync phone schedules with ElevenLabs | 08 Section 1.2, 16 Section 2.5 | **P1** |
|
|
158
|
+
| `log:cleanup` processor -- delete old logs past retention | 13 "Log Cleanup" | **P2** |
|
|
159
|
+
| `appointment:reminder` processor -- send reminders via Meta template messages | 16 Section 4.3 | **P0** |
|
|
160
|
+
| `webhook:outgoing` processor -- deliver tenant outgoing webhooks with HMAC + retry | 16 Section 5.4 | **P1** |
|
|
161
|
+
|
|
162
|
+
**Status in code:** Queues registered but no processor files exist.
|
|
163
|
+
|
|
164
|
+
### 1.13 Missing Phone Number Endpoints (Doc 03)
|
|
165
|
+
|
|
166
|
+
| Gap | Doc Reference | Priority |
|
|
167
|
+
|-----|--------------|----------|
|
|
168
|
+
| `POST /phone-numbers/:id/connect-whatsapp` | 03 Section 3 "API Endpoints" | **P0** |
|
|
169
|
+
| `POST /phone-numbers/:id/disconnect-whatsapp` | 03 Section 3 "API Endpoints" | **P1** |
|
|
170
|
+
| `GET /phone-numbers/:id/whatsapp-status` | 03 Section 3 "API Endpoints" | **P1** |
|
|
171
|
+
| `POST /phone-numbers/:id/toggle-agent` (manual assign/unassign ElevenLabs agent) | 03 Section 3, 08 Section 1.2 | **P1** |
|
|
172
|
+
|
|
173
|
+
### 1.14 Missing Meta Business API Endpoints (Doc 14)
|
|
174
|
+
|
|
175
|
+
| Gap | Doc Reference | Priority |
|
|
176
|
+
|-----|--------------|----------|
|
|
177
|
+
| `POST /whatsapp/meta/connect` -- store WABA ID, phone number ID, encrypted token | 14 Section 9 | **P0** |
|
|
178
|
+
| `GET /whatsapp/meta/status` -- connection status | 14 Section 9 | **P1** |
|
|
179
|
+
| `POST /whatsapp/meta/disconnect` -- clear tokens | 14 Section 9 | **P1** |
|
|
180
|
+
| `POST /whatsapp/instagram/connect` -- Instagram account connection | 14 Section 9 | **P1** |
|
|
181
|
+
| `GET /whatsapp/instagram/status` | 14 Section 9 | **P2** |
|
|
182
|
+
| `POST /whatsapp/instagram/disconnect` | 14 Section 9 | **P2** |
|
|
183
|
+
|
|
184
|
+
### 1.15 Missing Patient Endpoints (Doc 19, 21)
|
|
185
|
+
|
|
186
|
+
| Gap | Doc Reference | Priority |
|
|
187
|
+
|-----|--------------|----------|
|
|
188
|
+
| Patient documents CRUD (`GET/POST/DELETE /patients/:id/documents`) | 19 Section 4 | **P1** |
|
|
189
|
+
| Patient photo sets CRUD (`GET/POST/PUT/DELETE /patients/:id/photo-sets`) | 21 Section 7 | **P1** |
|
|
190
|
+
| Patient photo upload (`POST /patients/:id/photo-sets/:setId/photos`) | 21 Section 5 | **P1** |
|
|
191
|
+
| Patient merge/duplicate resolution (`POST /patients/merge`) | 19 Section 10 | **P2** |
|
|
192
|
+
| Patient timeline aggregation (`GET /patients/:id/timeline`) | 19 Section 6 | **P2** |
|
|
193
|
+
| Examination records CRUD (`GET/POST/PUT/DELETE /patients/:id/examinations`) | 19 "Examination Records" | **P1** |
|
|
194
|
+
|
|
195
|
+
**Status in code:** `patients.controller.ts` has CRUD, search, medical history, and notes. No document, photo-set, examination, or timeline endpoints exist. Service files `documents.service.ts`, `photo-sets.service.ts`, `examinations.service.ts` exist but their implementations need verification.
|
|
196
|
+
|
|
197
|
+
### 1.16 Missing Audit Log Endpoint (Doc 13)
|
|
198
|
+
|
|
199
|
+
| Gap | Doc Reference | Priority |
|
|
200
|
+
|-----|--------------|----------|
|
|
201
|
+
| `GET /platform/audit-logs` -- cross-tenant audit trail for superadmin/sales | 13 "Audit Log Endpoints" | **P2** |
|
|
202
|
+
|
|
203
|
+
### 1.17 Forgot Password Email Sending (Doc 02)
|
|
204
|
+
|
|
205
|
+
| Gap | Doc Reference | Priority |
|
|
206
|
+
|-----|--------------|----------|
|
|
207
|
+
| Actual email sending in `forgotPassword()` | 02 Section 8 | **P1** |
|
|
208
|
+
|
|
209
|
+
**Status in code:** `auth.service.ts` line 302: `// TODO: Send email with rawToken (not hashed) in the reset link`. Token is generated and hashed but never sent.
|
|
210
|
+
|
|
211
|
+
### 1.18 Meta Webhook Message Processing Pipeline (Doc 04, 14)
|
|
212
|
+
|
|
213
|
+
| Gap | Doc Reference | Priority |
|
|
214
|
+
|-----|--------------|----------|
|
|
215
|
+
| Full message processing pipeline after Meta webhook fires event (`meta.whatsapp.message`) | 04 Section 2 (Steps 1-12), 14 Section 4.2 | **P0** |
|
|
216
|
+
| Webhook payload normalization from Meta format to internal format | 14 Section 2.7 | **P0** |
|
|
217
|
+
| Instagram DM message processing (similar pipeline for `meta.instagram.message`) | 14 Section 3.2 | **P1** |
|
|
218
|
+
|
|
219
|
+
**Status in code:** `meta-webhook.controller.ts` correctly verifies HMAC, extracts messages, and emits events. But no `@OnEvent('meta.whatsapp.message')` listener exists in the WhatsApp module to process the emitted events.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## 2. Implemented Features NOT Documented
|
|
224
|
+
|
|
225
|
+
| Feature | Location | Notes |
|
|
226
|
+
|---------|----------|-------|
|
|
227
|
+
| `GET /appointments` -- paginated list with filters | `appointments/appointments.controller.ts` | Appointments CRUD endpoints exist but are not listed in IMPLEMENTATION_STATUS.md |
|
|
228
|
+
| `GET /appointments/stats` | `appointments/appointments.controller.ts` | Same -- missing from status doc |
|
|
229
|
+
| `POST /appointments` | `appointments/appointments.controller.ts` | Same |
|
|
230
|
+
| `PUT /appointments/:id` | `appointments/appointments.controller.ts` | Same |
|
|
231
|
+
| `PUT /appointments/:id/status` | `appointments/appointments.controller.ts` | Same |
|
|
232
|
+
| `DELETE /appointments/:id` | `appointments/appointments.controller.ts` | Same |
|
|
233
|
+
| `GET /appointments/:id` | `appointments/appointments.controller.ts` | Same |
|
|
234
|
+
| `AppointmentsModule` | `src/appointments/` | Entire module not listed in IMPLEMENTATION_STATUS endpoints section |
|
|
235
|
+
| `DoctorProfilesService` | `src/users/doctor-profiles.service.ts` | Doctor profile management exists in code but not documented in architecture docs |
|
|
236
|
+
| `PUT /users/:id/doctor-profile` | `src/users/users.controller.ts` | Doctor profile update endpoint exists but not in architecture endpoint tables |
|
|
237
|
+
| `ClinicMetaConnection` management endpoints in `ClinicsModule` | `src/clinics/clinics.controller.ts` | Meta connection CRUD within clinics -- not clearly documented |
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## 3. Schema Mismatches
|
|
242
|
+
|
|
243
|
+
### 3.1 ClinicCalendarConnection -- Missing Field
|
|
244
|
+
|
|
245
|
+
| Field | In Doc | In Prisma | Issue |
|
|
246
|
+
|-------|--------|-----------|-------|
|
|
247
|
+
| `calcn_timezone` | Doc 03 Section 4.1, Doc 07 Section 1.1 -- `String @default("Europe/Istanbul")` | **MISSING** from `schema.prisma` | P0 -- timezone needed for all calendar calculations |
|
|
248
|
+
|
|
249
|
+
### 3.2 Plan Model -- Missing Enum
|
|
250
|
+
|
|
251
|
+
| Field | In Doc | In Prisma | Issue |
|
|
252
|
+
|-------|--------|-----------|-------|
|
|
253
|
+
| `plan_language_support` | Doc 11 -- `LanguageSupport @default(single)` enum with `single`, `dual`, `multi` | **MISSING** from schema | P2 -- enum `LanguageSupport` not defined, field not on Plan model |
|
|
254
|
+
|
|
255
|
+
### 3.3 ClinicMetaConnection -- Doc vs Schema Divergence
|
|
256
|
+
|
|
257
|
+
| Aspect | Doc 03 (original design) | Doc 14 (updated design) | Prisma Schema | Notes |
|
|
258
|
+
|--------|-------------------------|------------------------|---------------|-------|
|
|
259
|
+
| `meta_type` | Not present | `String` (whatsapp/instagram) | Present | Schema follows Doc 14 |
|
|
260
|
+
| `meta_label` | Not present | `String?` | Present as `@default("")` | OK |
|
|
261
|
+
| `meta_is_active` | Not present | `Boolean @default(true)` | Present | OK |
|
|
262
|
+
| `meta_instagram_connected` | `Boolean @default(false)` | Removed in Doc 14 | Absent | Correct |
|
|
263
|
+
| `meta_encrypted_page_token` | Present (separate from access token) | Merged into `meta_encrypted_access_token` | Absent | Correct per Doc 14 |
|
|
264
|
+
|
|
265
|
+
Doc 03 and Doc 14 show different schemas for `ClinicMetaConnection`. The Prisma schema follows Doc 14 (newer). This is correct but Doc 03 should be updated for consistency.
|
|
266
|
+
|
|
267
|
+
### 3.4 Naming Convention Drift in Database Schema Doc
|
|
268
|
+
|
|
269
|
+
| Table | Doc 01 prefix | Actual Prisma prefix | Issue |
|
|
270
|
+
|-------|--------------|---------------------|-------|
|
|
271
|
+
| `treatment_plans` | `tplan_` | `plan_` | Prisma uses `plan_` prefix which collides with the `plans` table convention |
|
|
272
|
+
|
|
273
|
+
The Prisma schema uses `plan_` prefix for both `plans` and `treatment_plans`, which matches what is in code but differs from the `tplan_` convention in Doc 01.
|
|
274
|
+
|
|
275
|
+
### 3.5 Missing Tables in Prisma (Present in Doc 01)
|
|
276
|
+
|
|
277
|
+
| Table | Doc Reference | In Prisma | Notes |
|
|
278
|
+
|-------|--------------|-----------|-------|
|
|
279
|
+
| `tasks` | Doc 19 -- Patient has `tasks Task[]` relation | **MISSING** | No Task model in schema. Patient model shows a `tasks` relation in doc but not in code |
|
|
280
|
+
|
|
281
|
+
### 3.6 Present in Prisma but NOT in Architecture Docs
|
|
282
|
+
|
|
283
|
+
| Model | In Prisma | In Docs | Notes |
|
|
284
|
+
|-------|-----------|---------|-------|
|
|
285
|
+
| `Transcription` | Yes (full model) | Doc 01 mentions it | Legacy carry-over; not referenced by any architecture doc beyond the schema list |
|
|
286
|
+
| `Summary` | Yes (full model) | Doc 01 mentions it | Same as above |
|
|
287
|
+
| `Migration` | Yes (full model) | Doc 01 mentions it | Schema migration tracking -- infrastructure |
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## 4. Configuration Gaps
|
|
292
|
+
|
|
293
|
+
### 4.1 Missing Environment Variables
|
|
294
|
+
|
|
295
|
+
| Env Variable | Described In | In `.env` | Status |
|
|
296
|
+
|-------------|-------------|-----------|--------|
|
|
297
|
+
| `TEKTIPPAY_ENCRYPTION_KEY` | Doc 12 "Six AES-256-GCM Encryption Keys" | Missing | **STUB** -- TekTipPay deferred |
|
|
298
|
+
| `GOOGLE_OAUTH_STATE_SECRET` | Doc 07 Section 1.2 | Present but empty | **P0** -- needed for Google Calendar OAuth CSRF protection |
|
|
299
|
+
|
|
300
|
+
### 4.2 Modules Described as Global but Missing @Global
|
|
301
|
+
|
|
302
|
+
All infrastructure modules that should be `@Global()` are correctly annotated: `ConfigModule`, `DatabaseModule`, `RedisModule`, `QueueModule`, `EncryptionModule`, `AuthModule`, `AuditModule`, `LoggingModule`, `AIModule`, `MinioModule`. No gap here.
|
|
303
|
+
|
|
304
|
+
Modules NOT marked `@Global()` that doc 00 suggests should be importable everywhere:
|
|
305
|
+
- `ElevenLabsModule` -- not `@Global()`, but used by many modules. Currently imported individually where needed, which is fine.
|
|
306
|
+
- `MetaBusinessModule` -- same pattern, not `@Global()`, imported where needed. Acceptable.
|
|
307
|
+
|
|
308
|
+
### 4.3 Missing Package Dependencies
|
|
309
|
+
|
|
310
|
+
| Package | Required For | In `package.json` | Status |
|
|
311
|
+
|---------|-------------|-------------------|--------|
|
|
312
|
+
| `sharp` | Thumbnail generation for patient photos (Doc 21 Section 3.3) | **MISSING** | P1 -- needed for photo upload |
|
|
313
|
+
| `@anthropic-ai/sdk` | Anthropic AI provider (Doc 15) | Present | OK |
|
|
314
|
+
| `openai` | OpenAI AI provider (Doc 15) | Present | OK |
|
|
315
|
+
| `@nestjs/platform-socket.io` | WebSocket gateway (Doc 17) | Present | OK (but unused) |
|
|
316
|
+
| `@socket.io/redis-adapter` | Multi-instance WS support (Doc 17) | Present | OK (but unused) |
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
## 5. Security Gaps
|
|
321
|
+
|
|
322
|
+
### 5.1 Tenant-Scoping Middleware NOT Implemented
|
|
323
|
+
|
|
324
|
+
- **Doc 00 Rule 1, Doc 12:** "Every DB query is tenant-scoped. Enforced at the Prisma middleware layer."
|
|
325
|
+
- **Actual:** No Prisma `$use()` middleware exists. Each service manually adds `tenantId` to WHERE clauses. This is the single highest-risk security gap -- a developer forgetting `tenantId` in a query would leak cross-tenant data.
|
|
326
|
+
- **Priority: P0**
|
|
327
|
+
|
|
328
|
+
### 5.2 Webhook HMAC Verification -- Partial
|
|
329
|
+
|
|
330
|
+
| Webhook | Doc Requirement | Implementation | Status |
|
|
331
|
+
|---------|----------------|----------------|--------|
|
|
332
|
+
| Meta Business (`POST /webhooks/meta`) | HMAC-SHA256 with `META_APP_SECRET` | **Implemented** in `meta-webhook.controller.ts` | OK |
|
|
333
|
+
| ElevenLabs post-call (`POST /webhooks/elevenlabs`) | HMAC or API key verification | Enqueues to BullMQ but no signature verification visible | **P1** |
|
|
334
|
+
| ElevenLabs tools (`POST /webhooks/elevenlabs/tools/:toolName`) | `x-api-key` header check | Checks `x-api-key` against `ELEVENLABS_WEBHOOK_SECRET` | OK |
|
|
335
|
+
|
|
336
|
+
### 5.3 Rate Limiting -- Partially Applied
|
|
337
|
+
|
|
338
|
+
| Route | Doc Requirement | Implementation | Status |
|
|
339
|
+
|-------|----------------|----------------|--------|
|
|
340
|
+
| `POST /auth/login` | 5/min per IP | Global ThrottlerModule is 200/min. Doc-specific rate not applied | **P1** |
|
|
341
|
+
| `POST /auth/forgot-password` | 3/15min per email | Not specifically rate-limited | **P1** |
|
|
342
|
+
| `POST /auth/register` | 3/hr per IP | Not specifically rate-limited | **P1** |
|
|
343
|
+
| `/webhooks/*` | 100/min per IP | Not specifically rate-limited | **P1** |
|
|
344
|
+
|
|
345
|
+
Global rate limit is set (200/min in `app.module.ts`) but per-route overrides described in Doc 12 Section "Rate Limiting Details" are not applied.
|
|
346
|
+
|
|
347
|
+
### 5.4 Message Encryption at Rest
|
|
348
|
+
|
|
349
|
+
- **Doc 04, 12:** `msg_text` and `msg_quoted_text` encrypted with AES-256-GCM using `MESSAGE_ENCRYPTION_KEY`.
|
|
350
|
+
- **Actual:** `MESSAGE_ENCRYPTION_KEY` is in `.env` and `EncryptionService` is implemented. WhatsApp service uses it for message storage/retrieval.
|
|
351
|
+
- **Status: OK** -- Implemented per IMPLEMENTATION_STATUS.md.
|
|
352
|
+
|
|
353
|
+
### 5.5 Patient PII Encryption
|
|
354
|
+
|
|
355
|
+
- **Doc 12:** TC Kimlik, medical history, exam records, clinical notes encrypted with `PATIENT_PII_ENCRYPTION_KEY`.
|
|
356
|
+
- **Actual:** Encryption key present. PatientsService uses it.
|
|
357
|
+
- **Status: OK** -- Implemented.
|
|
358
|
+
|
|
359
|
+
### 5.6 Opaque Token Authentication
|
|
360
|
+
|
|
361
|
+
- **Doc 02:** Client never sees JWT. Opaque tokens map to JWTs in Redis.
|
|
362
|
+
- **Actual:** Fully implemented.
|
|
363
|
+
- **Status: OK**
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
## 6. Integration Gaps
|
|
368
|
+
|
|
369
|
+
### 6.1 Meta Business API (`meta-whatsapp.service.ts`)
|
|
370
|
+
|
|
371
|
+
| Feature | Doc Reference | Implemented | Priority |
|
|
372
|
+
|---------|--------------|-------------|----------|
|
|
373
|
+
| `sendMessage()` (text) | 14 Section 2.1 | Yes | OK |
|
|
374
|
+
| `sendTemplate()` (template messages) | 14 Section 2.2 | Yes | OK |
|
|
375
|
+
| `sendMedia()` (image/video/audio/document) | 14 Section 2.3 | Yes | OK |
|
|
376
|
+
| `sendInteractive()` (buttons/lists) | 14 Section 2.4 | Yes | OK |
|
|
377
|
+
| `downloadMedia()` (get media from Meta CDN) | 14 Section 5.2 | Needs verification | **P0** |
|
|
378
|
+
| Instagram DM sending | 14 Section 3.1 | `meta-instagram.service.ts` exists | Needs verification |
|
|
379
|
+
|
|
380
|
+
### 6.2 ElevenLabs (`elevenlabs.service.ts`)
|
|
381
|
+
|
|
382
|
+
| Feature | Doc Reference | Implemented | Priority |
|
|
383
|
+
|---------|--------------|-------------|----------|
|
|
384
|
+
| `getSignedUrl()` for WS connection | 04 Section 10 | Yes | OK |
|
|
385
|
+
| `getConversation()` for cost/status | 04 Section 12 | Yes | OK |
|
|
386
|
+
| `getBatchCall()` for validation sync | 07 Section 6 | Yes | OK |
|
|
387
|
+
| `submitBatchCall()` | 07 Section 6 | Yes | OK |
|
|
388
|
+
| `sipTrunkOutboundCall()` | 08 Section 2.1 | Yes | OK |
|
|
389
|
+
| STT via Scribe API | 04 Section 2 Step 3 | Yes | OK |
|
|
390
|
+
| WebSocket text-only chat integration | 04 Section 4 | **NOT IMPLEMENTED** -- this is the actual WS client code that lives in `whatsapp-agent.service.ts`, not `elevenlabs.service.ts` | **P0** |
|
|
391
|
+
|
|
392
|
+
### 6.3 Google Calendar (`google-calendar.service.ts`)
|
|
393
|
+
|
|
394
|
+
| Feature | Doc Reference | Implemented | Priority |
|
|
395
|
+
|---------|--------------|-------------|----------|
|
|
396
|
+
| OAuth2 flow (auth URL generation) | 07 Section 1.2 | Yes | OK |
|
|
397
|
+
| OAuth callback (code exchange, token encryption, storage) | 07 Section 1.2 | Yes | OK |
|
|
398
|
+
| Token caching in Redis with mutex | 07 Section 1.3 | Yes | OK |
|
|
399
|
+
| FreeBusy API for availability checking | 07 Section 2 | Yes | OK |
|
|
400
|
+
| Event creation (appointment booking) | 07 Section 3 | Yes | OK |
|
|
401
|
+
| Event deletion (appointment cancellation) | 07 Section 4 | Yes | OK |
|
|
402
|
+
| Disconnect flow (revoke token, clear Redis) | 07 Section 1.4 | Yes | OK |
|
|
403
|
+
| Calendar listing for selection | 07 related | Yes | OK |
|
|
404
|
+
|
|
405
|
+
### 6.4 MinIO (`minio.service.ts`)
|
|
406
|
+
|
|
407
|
+
| Feature | Doc Reference | Implemented | Priority |
|
|
408
|
+
|---------|--------------|-------------|----------|
|
|
409
|
+
| `putObject()` | 18 Section 6 | Yes | OK |
|
|
410
|
+
| `presignedGetObject()` | 18 Section 6 | Yes | OK |
|
|
411
|
+
| `removeObject()` / `removeObjects()` | 18 Section 6 | Yes | OK |
|
|
412
|
+
| `getObject()` | 18 Section 6 | Yes | OK |
|
|
413
|
+
| `objectExists()` | 18 Section 6 | Yes | OK |
|
|
414
|
+
| Bucket auto-creation on startup | 18 Section 6 | Yes | OK |
|
|
415
|
+
|
|
416
|
+
---
|
|
417
|
+
|
|
418
|
+
## 7. Priority Classification Summary
|
|
419
|
+
|
|
420
|
+
### P0 -- Blocks Launch (22 items)
|
|
421
|
+
|
|
422
|
+
1. WhatsApp AI engine: ElevenLabs WS connection, message send/receive, tool call handling
|
|
423
|
+
2. Grace period BullMQ processor (activates AI after waiting)
|
|
424
|
+
3. Message buffer BullMQ processor (debounce + send to AI)
|
|
425
|
+
4. Session cleanup sweep (2h inactivity auto-resolve)
|
|
426
|
+
5. Dynamic variables for ElevenLabs (`user_summary`, `current_date`)
|
|
427
|
+
6. Message deduplication on echo
|
|
428
|
+
7. System message filtering (40+ regex patterns)
|
|
429
|
+
8. Patient find-or-create on first contact
|
|
430
|
+
9. Self-sent message handling
|
|
431
|
+
10. Redis WS connection state management
|
|
432
|
+
11. Operator `forwardToOperator()` with REF code and media forwarding
|
|
433
|
+
12. Operator `handleOperatorReply()` with response injection
|
|
434
|
+
13. REF code generation
|
|
435
|
+
14. All 5 calendar tool handlers (check, reserve, list, cancel, reschedule)
|
|
436
|
+
15. `forward_to_operator` tool handler
|
|
437
|
+
16. WebSocket gateway (`EventsGateway`) for real-time dashboard
|
|
438
|
+
17. 11 WS event types for live updates
|
|
439
|
+
18. Prisma tenant-scoping middleware (auto-inject WHERE tenantId)
|
|
440
|
+
19. ElevenLabs post-call webhook processor (Call + CallDetail + summary + billing)
|
|
441
|
+
20. Meta webhook message processing pipeline (event listener + full pipeline)
|
|
442
|
+
21. `POST /phone-numbers/:id/connect-whatsapp`
|
|
443
|
+
22. `POST /whatsapp/meta/connect` (Meta Business setup)
|
|
444
|
+
|
|
445
|
+
### P1 -- Important, Before Launch (28 items)
|
|
446
|
+
|
|
447
|
+
1. Chat continuity (`continuation_directive` builder)
|
|
448
|
+
2. AI shift scheduling check
|
|
449
|
+
3. Session recovery on startup
|
|
450
|
+
4. Voice transcription (STT pipeline)
|
|
451
|
+
5. Fixed first message on new session
|
|
452
|
+
6. Cost sweep processor
|
|
453
|
+
7. Profile update processor (AI summary)
|
|
454
|
+
8. Session labels processor (sentiment + categories)
|
|
455
|
+
9. Message cleanup processor (retention enforcement)
|
|
456
|
+
10. Operator expiry processor
|
|
457
|
+
11. Forward conversation to operator (text-only)
|
|
458
|
+
12. Send example photo tool
|
|
459
|
+
13. `check_patient_history` tool handler
|
|
460
|
+
14. `call_patient` tool handler
|
|
461
|
+
15. `confirm_appointment_validation` tool handler
|
|
462
|
+
16. ElevenLabs tools webhook processor
|
|
463
|
+
17. Outbound campaign dispatch + sync processors
|
|
464
|
+
18. Appointment validation dispatch + sync processors
|
|
465
|
+
19. Billing snapshot + alert processors
|
|
466
|
+
20. Inbound call schedule-sync processor
|
|
467
|
+
21. Appointment reminder processor
|
|
468
|
+
22. Webhook outgoing processor
|
|
469
|
+
23. Per-route rate limiting (login, register, forgot-password, webhooks)
|
|
470
|
+
24. ElevenLabs post-call webhook HMAC verification
|
|
471
|
+
25. Request context interceptor (AsyncLocalStorage + correlation IDs)
|
|
472
|
+
26. HTTP exception filter
|
|
473
|
+
27. Patient documents CRUD
|
|
474
|
+
28. Patient photo sets / photos CRUD + `sharp` dependency
|
|
475
|
+
29. Examination records CRUD
|
|
476
|
+
30. Forgot password email sending
|
|
477
|
+
31. Phone number disconnect-whatsapp, whatsapp-status, toggle-agent endpoints
|
|
478
|
+
32. Meta connect/disconnect/status endpoints
|
|
479
|
+
|
|
480
|
+
### P2 -- Nice to Have (7 items)
|
|
481
|
+
|
|
482
|
+
1. Typing indicator handler in WS gateway
|
|
483
|
+
2. Log cleanup processor
|
|
484
|
+
3. Patient merge/duplicate resolution
|
|
485
|
+
4. Patient timeline aggregation
|
|
486
|
+
5. Instagram connect/disconnect/status endpoints
|
|
487
|
+
6. Cross-tenant audit trail endpoint (`/platform/audit-logs`)
|
|
488
|
+
7. `LanguageSupport` enum on Plan model
|
|
489
|
+
|
|
490
|
+
### STUB -- Intentionally Deferred (4 items)
|
|
491
|
+
|
|
492
|
+
1. NetGSM SMS integration (stub module, returns `{ success: false }`)
|
|
493
|
+
2. TekTipPay payment integration (stub module, returns `{ success: false }`)
|
|
494
|
+
3. `request_payment` tool handler (returns "not yet available")
|
|
495
|
+
4. `send_sms` tool handler (returns "not yet available")
|
|
496
|
+
|
|
497
|
+
---
|
|
498
|
+
|
|
499
|
+
## 8. Recommendations
|
|
500
|
+
|
|
501
|
+
1. **Tenant-scoping middleware is the highest-risk item.** Every query without it is a potential cross-tenant data leak. Implement this first.
|
|
502
|
+
2. **WhatsApp AI engine is the highest-effort item.** The ElevenLabs WS integration, message pipeline, and all 8 BullMQ processors form a single interconnected unit. Plan for this as one concentrated sprint.
|
|
503
|
+
3. **WebSocket gateway should be implemented alongside WhatsApp engine** since both emit/consume the same events.
|
|
504
|
+
4. **Tool handlers can be implemented incrementally** -- calendar tools first (most used by patients), then operator tools, then the rest.
|
|
505
|
+
5. **The `calcn_timezone` field is missing from Prisma schema** -- add it before any calendar-related work proceeds.
|
|
506
|
+
6. **Update Doc 03** to match Doc 14's ClinicMetaConnection design (the code already follows Doc 14).
|
|
507
|
+
7. **Add `sharp` to `package.json`** before implementing patient photo uploads.
|