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
package/docs/API.md
ADDED
|
@@ -0,0 +1,1193 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
All protected routes require `Authorization: Bearer <access_token>` header.
|
|
4
|
+
All routes are **tenant-scoped** — users can only access data belonging to their own tenant.
|
|
5
|
+
|
|
6
|
+
For auth endpoints (register, login, refresh, logout, me), see [AUTH_API.md](./AUTH_API.md).
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Tenants
|
|
11
|
+
|
|
12
|
+
Base URL: `/tenants`
|
|
13
|
+
|
|
14
|
+
All routes require authentication.
|
|
15
|
+
|
|
16
|
+
### GET /tenants/me
|
|
17
|
+
|
|
18
|
+
Returns the current user's tenant details.
|
|
19
|
+
|
|
20
|
+
**Auth:** Bearer token
|
|
21
|
+
**Roles:** any
|
|
22
|
+
|
|
23
|
+
**200 OK:**
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"tenant": {
|
|
28
|
+
"id": "664f1a...",
|
|
29
|
+
"name": "Acme Corp",
|
|
30
|
+
"plan": "free",
|
|
31
|
+
"enabled_features": ["inbound_agent", "whatsapp_notifications"],
|
|
32
|
+
"settings": {
|
|
33
|
+
"kvkk_consent": false,
|
|
34
|
+
"notification_recipients": [],
|
|
35
|
+
"default_language": "tr"
|
|
36
|
+
},
|
|
37
|
+
"createdAt": "2025-01-15T10:00:00.000Z"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Errors:**
|
|
43
|
+
|
|
44
|
+
| Status | Condition |
|
|
45
|
+
|--------|-----------|
|
|
46
|
+
| 401 | Missing or invalid token |
|
|
47
|
+
| 404 | Tenant not found |
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
### PUT /tenants/me
|
|
52
|
+
|
|
53
|
+
Updates tenant name and/or settings. Only provided fields are updated.
|
|
54
|
+
|
|
55
|
+
**Auth:** Bearer token
|
|
56
|
+
**Roles:** `admin`
|
|
57
|
+
|
|
58
|
+
**Request Body:**
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"name": "New Company Name",
|
|
63
|
+
"settings": {
|
|
64
|
+
"kvkk_consent": true,
|
|
65
|
+
"notification_recipients": ["+905551234567"],
|
|
66
|
+
"default_language": "en"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
All fields are optional. Only include the ones you want to change.
|
|
72
|
+
|
|
73
|
+
**200 OK:**
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"tenant": {
|
|
78
|
+
"id": "664f1a...",
|
|
79
|
+
"name": "New Company Name",
|
|
80
|
+
"plan": "free",
|
|
81
|
+
"enabled_features": ["inbound_agent", "whatsapp_notifications"],
|
|
82
|
+
"settings": {
|
|
83
|
+
"kvkk_consent": true,
|
|
84
|
+
"notification_recipients": ["+905551234567"],
|
|
85
|
+
"default_language": "en"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Errors:**
|
|
92
|
+
|
|
93
|
+
| Status | Condition |
|
|
94
|
+
|--------|-----------|
|
|
95
|
+
| 400 | No valid fields provided |
|
|
96
|
+
| 403 | Not an admin |
|
|
97
|
+
| 404 | Tenant not found |
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Users
|
|
102
|
+
|
|
103
|
+
Base URL: `/users`
|
|
104
|
+
|
|
105
|
+
All routes require authentication. Users are scoped to the authenticated user's tenant.
|
|
106
|
+
|
|
107
|
+
### GET /users
|
|
108
|
+
|
|
109
|
+
Lists all users in the current tenant.
|
|
110
|
+
|
|
111
|
+
**Auth:** Bearer token
|
|
112
|
+
**Roles:** `admin`, `manager`, `viewer`
|
|
113
|
+
|
|
114
|
+
**200 OK:**
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"users": [
|
|
119
|
+
{
|
|
120
|
+
"_id": "664f1a...",
|
|
121
|
+
"tenant_id": "664f1a...",
|
|
122
|
+
"email": "user@example.com",
|
|
123
|
+
"role": "admin",
|
|
124
|
+
"name": "John Doe",
|
|
125
|
+
"createdAt": "2025-01-15T10:00:00.000Z"
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Note: `password_hash` is excluded from the response.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
### POST /users/invite
|
|
136
|
+
|
|
137
|
+
Creates a new user in the current tenant.
|
|
138
|
+
|
|
139
|
+
**Auth:** Bearer token
|
|
140
|
+
**Roles:** `admin`
|
|
141
|
+
|
|
142
|
+
**Request Body:**
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"email": "newuser@example.com",
|
|
147
|
+
"password": "min8chars",
|
|
148
|
+
"name": "Jane Doe",
|
|
149
|
+
"role": "manager"
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**201 Created:**
|
|
154
|
+
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"user": {
|
|
158
|
+
"id": "664f1b...",
|
|
159
|
+
"email": "newuser@example.com",
|
|
160
|
+
"name": "Jane Doe",
|
|
161
|
+
"role": "manager",
|
|
162
|
+
"createdAt": "2025-01-15T10:00:00.000Z"
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Errors:**
|
|
168
|
+
|
|
169
|
+
| Status | Condition |
|
|
170
|
+
|--------|-----------|
|
|
171
|
+
| 400 | Missing required fields |
|
|
172
|
+
| 400 | Password shorter than 8 characters |
|
|
173
|
+
| 400 | Invalid role (must be `admin`, `manager`, or `viewer`) |
|
|
174
|
+
| 403 | Not an admin |
|
|
175
|
+
| 409 | Email already registered |
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
### PUT /users/:id
|
|
180
|
+
|
|
181
|
+
Updates a user's role and/or name.
|
|
182
|
+
|
|
183
|
+
**Auth:** Bearer token
|
|
184
|
+
**Roles:** `admin`
|
|
185
|
+
|
|
186
|
+
**Request Body:**
|
|
187
|
+
|
|
188
|
+
```json
|
|
189
|
+
{
|
|
190
|
+
"role": "viewer",
|
|
191
|
+
"name": "Updated Name"
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Both fields are optional.
|
|
196
|
+
|
|
197
|
+
**200 OK:**
|
|
198
|
+
|
|
199
|
+
```json
|
|
200
|
+
{
|
|
201
|
+
"user": {
|
|
202
|
+
"id": "664f1b...",
|
|
203
|
+
"email": "newuser@example.com",
|
|
204
|
+
"name": "Updated Name",
|
|
205
|
+
"role": "viewer"
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**Errors:**
|
|
211
|
+
|
|
212
|
+
| Status | Condition |
|
|
213
|
+
|--------|-----------|
|
|
214
|
+
| 400 | Invalid role |
|
|
215
|
+
| 400 | Cannot change your own role |
|
|
216
|
+
| 403 | Not an admin |
|
|
217
|
+
| 404 | User not found in this tenant |
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
### DELETE /users/:id
|
|
222
|
+
|
|
223
|
+
Removes a user from the tenant.
|
|
224
|
+
|
|
225
|
+
**Auth:** Bearer token
|
|
226
|
+
**Roles:** `admin`
|
|
227
|
+
|
|
228
|
+
**200 OK:**
|
|
229
|
+
|
|
230
|
+
```json
|
|
231
|
+
{
|
|
232
|
+
"success": true
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**Errors:**
|
|
237
|
+
|
|
238
|
+
| Status | Condition |
|
|
239
|
+
|--------|-----------|
|
|
240
|
+
| 400 | Cannot delete yourself |
|
|
241
|
+
| 403 | Not an admin |
|
|
242
|
+
| 404 | User not found in this tenant |
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Calls
|
|
247
|
+
|
|
248
|
+
Base URL: `/calls`
|
|
249
|
+
|
|
250
|
+
All routes require authentication.
|
|
251
|
+
|
|
252
|
+
### GET /calls
|
|
253
|
+
|
|
254
|
+
Lists calls for the current tenant with pagination and filters.
|
|
255
|
+
|
|
256
|
+
**Auth:** Bearer token
|
|
257
|
+
**Roles:** `admin`, `manager`, `viewer`
|
|
258
|
+
|
|
259
|
+
**Query Parameters:**
|
|
260
|
+
|
|
261
|
+
| Param | Type | Default | Description |
|
|
262
|
+
|-------|------|---------|-------------|
|
|
263
|
+
| `page` | number | `1` | Page number |
|
|
264
|
+
| `limit` | number | `20` | Items per page (max 100) |
|
|
265
|
+
| `direction` | string | - | Filter: `inbound` or `outbound` |
|
|
266
|
+
| `status` | string | - | Filter: `completed`, `failed`, `no_answer`, `voicemail`, `transferred` |
|
|
267
|
+
| `agent_id` | string | - | Filter by agent ObjectId |
|
|
268
|
+
| `from` | ISO date | - | Filter: calls after this date |
|
|
269
|
+
| `to` | ISO date | - | Filter: calls before this date |
|
|
270
|
+
|
|
271
|
+
**200 OK:**
|
|
272
|
+
|
|
273
|
+
```json
|
|
274
|
+
{
|
|
275
|
+
"calls": [
|
|
276
|
+
{
|
|
277
|
+
"_id": "664f1c...",
|
|
278
|
+
"tenant_id": "664f1a...",
|
|
279
|
+
"agent_id": {
|
|
280
|
+
"_id": "664f1b...",
|
|
281
|
+
"phone_number": "+902121234567",
|
|
282
|
+
"agent_template": "receptionist"
|
|
283
|
+
},
|
|
284
|
+
"direction": "inbound",
|
|
285
|
+
"caller_number": "+905551234567",
|
|
286
|
+
"callee_number": "+902121234567",
|
|
287
|
+
"duration_seconds": 120,
|
|
288
|
+
"status": "completed",
|
|
289
|
+
"llm_summary": "Arayan randevu almak istedi...",
|
|
290
|
+
"whatsapp_notification_sent": true,
|
|
291
|
+
"createdAt": "2025-01-15T10:00:00.000Z"
|
|
292
|
+
}
|
|
293
|
+
],
|
|
294
|
+
"total": 42,
|
|
295
|
+
"page": 1,
|
|
296
|
+
"totalPages": 3
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Note: `transcript` field is excluded from list responses for performance. Use `GET /calls/:id` for full detail.
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
### GET /calls/stats
|
|
305
|
+
|
|
306
|
+
Returns aggregated call statistics for the current tenant.
|
|
307
|
+
|
|
308
|
+
**Auth:** Bearer token
|
|
309
|
+
**Roles:** `admin`, `manager`, `viewer`
|
|
310
|
+
|
|
311
|
+
**200 OK:**
|
|
312
|
+
|
|
313
|
+
```json
|
|
314
|
+
{
|
|
315
|
+
"stats": {
|
|
316
|
+
"total": 150,
|
|
317
|
+
"completed": 120,
|
|
318
|
+
"failed": 10,
|
|
319
|
+
"no_answer": 20,
|
|
320
|
+
"inbound": 100,
|
|
321
|
+
"outbound": 50,
|
|
322
|
+
"avg_duration": 95.5,
|
|
323
|
+
"total_duration": 14325
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
### GET /calls/:id
|
|
331
|
+
|
|
332
|
+
Returns full call detail including transcript, summary, and survey responses.
|
|
333
|
+
|
|
334
|
+
**Auth:** Bearer token
|
|
335
|
+
**Roles:** `admin`, `manager`, `viewer`
|
|
336
|
+
|
|
337
|
+
**200 OK:**
|
|
338
|
+
|
|
339
|
+
```json
|
|
340
|
+
{
|
|
341
|
+
"call": {
|
|
342
|
+
"_id": "664f1c...",
|
|
343
|
+
"tenant_id": "664f1a...",
|
|
344
|
+
"agent_id": {
|
|
345
|
+
"_id": "664f1b...",
|
|
346
|
+
"phone_number": "+902121234567",
|
|
347
|
+
"agent_template": "receptionist",
|
|
348
|
+
"config": { "voice_id": "abc123" }
|
|
349
|
+
},
|
|
350
|
+
"campaign_id": null,
|
|
351
|
+
"direction": "inbound",
|
|
352
|
+
"caller_number": "+905551234567",
|
|
353
|
+
"callee_number": "+902121234567",
|
|
354
|
+
"duration_seconds": 120,
|
|
355
|
+
"status": "completed",
|
|
356
|
+
"transcript": "Arayan: Merhaba, randevu almak istiyorum.\nAsistan: Tabii, hangi gun uygun?...",
|
|
357
|
+
"llm_summary": "Arayan randevu almak istedi. 15 Ocak saat 14:00 icin randevu olusturuldu.",
|
|
358
|
+
"survey_responses": null,
|
|
359
|
+
"whatsapp_notification_sent": true,
|
|
360
|
+
"recording_url": null,
|
|
361
|
+
"createdAt": "2025-01-15T10:00:00.000Z"
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
When the call has survey responses (extract_survey strategy):
|
|
367
|
+
|
|
368
|
+
```json
|
|
369
|
+
{
|
|
370
|
+
"call": {
|
|
371
|
+
"...": "...",
|
|
372
|
+
"survey_responses": [
|
|
373
|
+
{
|
|
374
|
+
"question_id": "Q1",
|
|
375
|
+
"question_text": "Hizmetimizi 1-5 arasi nasil degerlendirirsiniz?",
|
|
376
|
+
"answer": "4",
|
|
377
|
+
"parsed_value": 4
|
|
378
|
+
}
|
|
379
|
+
]
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
**Errors:**
|
|
385
|
+
|
|
386
|
+
| Status | Condition |
|
|
387
|
+
|--------|-----------|
|
|
388
|
+
| 404 | Call not found in this tenant |
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## Webhooks
|
|
393
|
+
|
|
394
|
+
### POST /webhooks/elevenlabs
|
|
395
|
+
|
|
396
|
+
Receives post-call data from ElevenLabs. Secured by HMAC-SHA256 signature verification (not JWT).
|
|
397
|
+
|
|
398
|
+
**Auth:** `elevenlabs-signature` header (HMAC)
|
|
399
|
+
|
|
400
|
+
**Behavior:**
|
|
401
|
+
|
|
402
|
+
1. Returns `200 { "status": "received" }` immediately
|
|
403
|
+
2. Processes the call asynchronously in the background:
|
|
404
|
+
- Looks up Agent by `elevenlabs_agent_id`
|
|
405
|
+
- Creates a Call record in the new data model
|
|
406
|
+
- Runs post-call processing based on `agent.post_call_processing.strategy`:
|
|
407
|
+
|
|
408
|
+
| Strategy | Action |
|
|
409
|
+
|----------|--------|
|
|
410
|
+
| `summarize` | LLM generates summary → saved to `call.llm_summary` |
|
|
411
|
+
| `extract_survey` | LLM extracts structured answers → saved to `call.survey_responses` |
|
|
412
|
+
| `summarize_and_extract` | Both of the above |
|
|
413
|
+
| `none` | Call saved with transcript only, no LLM processing |
|
|
414
|
+
|
|
415
|
+
3. If `agent.post_call_processing.whatsapp_notify` is `true`, sends WhatsApp notification to matching recipients
|
|
416
|
+
|
|
417
|
+
**Request Body (from ElevenLabs):**
|
|
418
|
+
|
|
419
|
+
```json
|
|
420
|
+
{
|
|
421
|
+
"type": "post_call_transcription",
|
|
422
|
+
"event_timestamp": 1705312800,
|
|
423
|
+
"data": {
|
|
424
|
+
"conversation_id": "conv_123",
|
|
425
|
+
"agent_id": "agent_abc",
|
|
426
|
+
"agent_name": "Receptionist",
|
|
427
|
+
"status": "done",
|
|
428
|
+
"transcript": [
|
|
429
|
+
{ "role": "agent", "message": "Merhaba, nasil yardimci olabilirim?" },
|
|
430
|
+
{ "role": "user", "message": "Randevu almak istiyorum." }
|
|
431
|
+
],
|
|
432
|
+
"metadata": {
|
|
433
|
+
"call_duration_secs": 120,
|
|
434
|
+
"phone_call": { "external_number": "+905551234567" }
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
**200 OK:**
|
|
441
|
+
|
|
442
|
+
```json
|
|
443
|
+
{
|
|
444
|
+
"status": "received"
|
|
445
|
+
}
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
**Errors:**
|
|
449
|
+
|
|
450
|
+
| Status | Condition |
|
|
451
|
+
|--------|-----------|
|
|
452
|
+
| 401 | Invalid or missing HMAC signature |
|
|
453
|
+
|
|
454
|
+
---
|
|
455
|
+
|
|
456
|
+
## Surveys
|
|
457
|
+
|
|
458
|
+
Base URL: `/surveys`
|
|
459
|
+
|
|
460
|
+
All routes require authentication and the `survey_builder` feature.
|
|
461
|
+
|
|
462
|
+
### GET /surveys
|
|
463
|
+
|
|
464
|
+
Lists all surveys for the current tenant. Questions are excluded for performance.
|
|
465
|
+
|
|
466
|
+
**Auth:** Bearer token
|
|
467
|
+
**Feature:** `survey_builder`
|
|
468
|
+
**Roles:** `admin`, `manager`, `viewer`
|
|
469
|
+
|
|
470
|
+
**200 OK:**
|
|
471
|
+
|
|
472
|
+
```json
|
|
473
|
+
{
|
|
474
|
+
"surveys": [
|
|
475
|
+
{
|
|
476
|
+
"_id": "664f1d...",
|
|
477
|
+
"tenant_id": "664f1a...",
|
|
478
|
+
"name": "Musteri Memnuniyeti",
|
|
479
|
+
"description": "Hizmet sonrasi anket",
|
|
480
|
+
"status": "active",
|
|
481
|
+
"createdAt": "2025-01-15T10:00:00.000Z",
|
|
482
|
+
"updatedAt": "2025-01-16T08:00:00.000Z"
|
|
483
|
+
}
|
|
484
|
+
]
|
|
485
|
+
}
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
### POST /surveys
|
|
491
|
+
|
|
492
|
+
Creates a new survey in draft status.
|
|
493
|
+
|
|
494
|
+
**Auth:** Bearer token
|
|
495
|
+
**Feature:** `survey_builder`
|
|
496
|
+
**Roles:** `admin`, `manager`
|
|
497
|
+
|
|
498
|
+
**Request Body:**
|
|
499
|
+
|
|
500
|
+
```json
|
|
501
|
+
{
|
|
502
|
+
"name": "Musteri Memnuniyeti",
|
|
503
|
+
"description": "Hizmet sonrasi anket",
|
|
504
|
+
"questions": [
|
|
505
|
+
{
|
|
506
|
+
"id": "Q1",
|
|
507
|
+
"text": "Hizmetimizi 1-5 arasi nasil degerlendirirsiniz?",
|
|
508
|
+
"type": "rating",
|
|
509
|
+
"options": [],
|
|
510
|
+
"required": true,
|
|
511
|
+
"branch_logic": null
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
"id": "Q2",
|
|
515
|
+
"text": "Tekrar tercih eder misiniz?",
|
|
516
|
+
"type": "yes_no",
|
|
517
|
+
"options": [],
|
|
518
|
+
"required": true,
|
|
519
|
+
"branch_logic": {
|
|
520
|
+
"condition": "answer == 'no'",
|
|
521
|
+
"go_to": "Q3"
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
"id": "Q3",
|
|
526
|
+
"text": "Nedenini aciklar misiniz?",
|
|
527
|
+
"type": "open",
|
|
528
|
+
"options": [],
|
|
529
|
+
"required": false,
|
|
530
|
+
"branch_logic": null
|
|
531
|
+
}
|
|
532
|
+
]
|
|
533
|
+
}
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
`questions` is optional on creation — can be added later via PUT.
|
|
537
|
+
|
|
538
|
+
**Question types:**
|
|
539
|
+
|
|
540
|
+
| Type | Description |
|
|
541
|
+
|------|-------------|
|
|
542
|
+
| `open` | Free text answer |
|
|
543
|
+
| `multiple_choice` | Must have 2+ options |
|
|
544
|
+
| `rating` | Numeric rating |
|
|
545
|
+
| `yes_no` | Yes/no answer |
|
|
546
|
+
|
|
547
|
+
**Validation rules:**
|
|
548
|
+
- Question IDs must be unique
|
|
549
|
+
- `multiple_choice` questions must have at least 2 options
|
|
550
|
+
- `branch_logic.go_to` must reference an existing question ID
|
|
551
|
+
|
|
552
|
+
**201 Created:**
|
|
553
|
+
|
|
554
|
+
```json
|
|
555
|
+
{
|
|
556
|
+
"survey": {
|
|
557
|
+
"_id": "664f1d...",
|
|
558
|
+
"tenant_id": "664f1a...",
|
|
559
|
+
"name": "Musteri Memnuniyeti",
|
|
560
|
+
"status": "draft",
|
|
561
|
+
"questions": [ ... ]
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
**Errors:**
|
|
567
|
+
|
|
568
|
+
| Status | Condition |
|
|
569
|
+
|--------|-----------|
|
|
570
|
+
| 400 | Missing name |
|
|
571
|
+
| 400 | Question validation failed (see rules above) |
|
|
572
|
+
| 403 | Feature not available / insufficient role |
|
|
573
|
+
|
|
574
|
+
---
|
|
575
|
+
|
|
576
|
+
### GET /surveys/:id
|
|
577
|
+
|
|
578
|
+
Returns full survey detail including all questions.
|
|
579
|
+
|
|
580
|
+
**Auth:** Bearer token
|
|
581
|
+
**Feature:** `survey_builder`
|
|
582
|
+
**Roles:** `admin`, `manager`, `viewer`
|
|
583
|
+
|
|
584
|
+
**200 OK:**
|
|
585
|
+
|
|
586
|
+
```json
|
|
587
|
+
{
|
|
588
|
+
"survey": {
|
|
589
|
+
"_id": "664f1d...",
|
|
590
|
+
"name": "Musteri Memnuniyeti",
|
|
591
|
+
"description": "Hizmet sonrasi anket",
|
|
592
|
+
"status": "active",
|
|
593
|
+
"questions": [
|
|
594
|
+
{
|
|
595
|
+
"id": "Q1",
|
|
596
|
+
"text": "Hizmetimizi 1-5 arasi nasil degerlendirirsiniz?",
|
|
597
|
+
"type": "rating",
|
|
598
|
+
"options": [],
|
|
599
|
+
"required": true,
|
|
600
|
+
"branch_logic": null
|
|
601
|
+
}
|
|
602
|
+
]
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
**Errors:**
|
|
608
|
+
|
|
609
|
+
| Status | Condition |
|
|
610
|
+
|--------|-----------|
|
|
611
|
+
| 404 | Survey not found in this tenant |
|
|
612
|
+
|
|
613
|
+
---
|
|
614
|
+
|
|
615
|
+
### PUT /surveys/:id
|
|
616
|
+
|
|
617
|
+
Updates survey fields. All body fields are optional.
|
|
618
|
+
|
|
619
|
+
**Auth:** Bearer token
|
|
620
|
+
**Feature:** `survey_builder`
|
|
621
|
+
**Roles:** `admin`, `manager`
|
|
622
|
+
|
|
623
|
+
**Request Body:**
|
|
624
|
+
|
|
625
|
+
```json
|
|
626
|
+
{
|
|
627
|
+
"name": "Updated Name",
|
|
628
|
+
"description": "Updated description",
|
|
629
|
+
"questions": [ ... ],
|
|
630
|
+
"status": "active"
|
|
631
|
+
}
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
Status values: `draft`, `active`, `archived`.
|
|
635
|
+
|
|
636
|
+
**200 OK:**
|
|
637
|
+
|
|
638
|
+
```json
|
|
639
|
+
{
|
|
640
|
+
"survey": { ... }
|
|
641
|
+
}
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
**Errors:**
|
|
645
|
+
|
|
646
|
+
| Status | Condition |
|
|
647
|
+
|--------|-----------|
|
|
648
|
+
| 400 | Question validation failed |
|
|
649
|
+
| 404 | Survey not found |
|
|
650
|
+
|
|
651
|
+
---
|
|
652
|
+
|
|
653
|
+
### DELETE /surveys/:id
|
|
654
|
+
|
|
655
|
+
Deletes a survey. Blocked if any active campaigns reference it.
|
|
656
|
+
|
|
657
|
+
**Auth:** Bearer token
|
|
658
|
+
**Feature:** `survey_builder`
|
|
659
|
+
**Roles:** `admin`, `manager`
|
|
660
|
+
|
|
661
|
+
**200 OK:**
|
|
662
|
+
|
|
663
|
+
```json
|
|
664
|
+
{
|
|
665
|
+
"success": true
|
|
666
|
+
}
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
**Errors:**
|
|
670
|
+
|
|
671
|
+
| Status | Condition |
|
|
672
|
+
|--------|-----------|
|
|
673
|
+
| 404 | Survey not found |
|
|
674
|
+
| 409 | Cannot delete survey with active campaigns (scheduled/running/paused) |
|
|
675
|
+
|
|
676
|
+
---
|
|
677
|
+
|
|
678
|
+
### POST /surveys/:id/duplicate
|
|
679
|
+
|
|
680
|
+
Clones a survey as a new draft with "(kopya)" appended to the name.
|
|
681
|
+
|
|
682
|
+
**Auth:** Bearer token
|
|
683
|
+
**Feature:** `survey_builder`
|
|
684
|
+
**Roles:** `admin`, `manager`
|
|
685
|
+
|
|
686
|
+
**201 Created:**
|
|
687
|
+
|
|
688
|
+
```json
|
|
689
|
+
{
|
|
690
|
+
"survey": {
|
|
691
|
+
"_id": "664f1e...",
|
|
692
|
+
"name": "Musteri Memnuniyeti (kopya)",
|
|
693
|
+
"status": "draft",
|
|
694
|
+
"questions": [ ... ]
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
**Errors:**
|
|
700
|
+
|
|
701
|
+
| Status | Condition |
|
|
702
|
+
|--------|-----------|
|
|
703
|
+
| 404 | Original survey not found |
|
|
704
|
+
|
|
705
|
+
---
|
|
706
|
+
|
|
707
|
+
## Campaigns
|
|
708
|
+
|
|
709
|
+
Base URL: `/campaigns`
|
|
710
|
+
|
|
711
|
+
All routes require authentication and the `outbound_campaigns` feature.
|
|
712
|
+
|
|
713
|
+
### GET /campaigns
|
|
714
|
+
|
|
715
|
+
Lists campaigns with pagination. Phone list is excluded for performance.
|
|
716
|
+
|
|
717
|
+
**Auth:** Bearer token
|
|
718
|
+
**Feature:** `outbound_campaigns`
|
|
719
|
+
**Roles:** `admin`, `manager`, `viewer`
|
|
720
|
+
|
|
721
|
+
**Query Parameters:**
|
|
722
|
+
|
|
723
|
+
| Param | Type | Default | Description |
|
|
724
|
+
|-------|------|---------|-------------|
|
|
725
|
+
| `page` | number | `1` | Page number |
|
|
726
|
+
| `status` | string | - | Filter: `draft`, `scheduled`, `running`, `paused`, `completed` |
|
|
727
|
+
|
|
728
|
+
**200 OK:**
|
|
729
|
+
|
|
730
|
+
```json
|
|
731
|
+
{
|
|
732
|
+
"campaigns": [
|
|
733
|
+
{
|
|
734
|
+
"_id": "664f1e...",
|
|
735
|
+
"name": "Ocak Anketi",
|
|
736
|
+
"status": "running",
|
|
737
|
+
"survey_id": { "_id": "664f1d...", "name": "Musteri Memnuniyeti", "status": "active" },
|
|
738
|
+
"agent_id": { "_id": "664f1b...", "phone_number": "+902121234567", "agent_template": "survey" },
|
|
739
|
+
"schedule": { ... },
|
|
740
|
+
"stats": { "total": 100, "completed": 42, "failed": 3, "no_answer": 5, "voicemail": 0, "pending": 50 },
|
|
741
|
+
"createdAt": "2025-01-15T10:00:00.000Z"
|
|
742
|
+
}
|
|
743
|
+
],
|
|
744
|
+
"total": 5,
|
|
745
|
+
"page": 1,
|
|
746
|
+
"totalPages": 1
|
|
747
|
+
}
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
---
|
|
751
|
+
|
|
752
|
+
### POST /campaigns
|
|
753
|
+
|
|
754
|
+
Creates a new campaign in draft status. Validates that the referenced survey and agent belong to the current tenant.
|
|
755
|
+
|
|
756
|
+
**Auth:** Bearer token
|
|
757
|
+
**Feature:** `outbound_campaigns`
|
|
758
|
+
**Roles:** `admin`, `manager`
|
|
759
|
+
|
|
760
|
+
**Request Body:**
|
|
761
|
+
|
|
762
|
+
```json
|
|
763
|
+
{
|
|
764
|
+
"name": "Ocak Anketi",
|
|
765
|
+
"survey_id": "664f1d...",
|
|
766
|
+
"agent_id": "664f1b...",
|
|
767
|
+
"schedule": {
|
|
768
|
+
"start_date": "2025-02-01",
|
|
769
|
+
"end_date": "2025-02-28",
|
|
770
|
+
"daily_start_time": "09:00",
|
|
771
|
+
"daily_end_time": "18:00",
|
|
772
|
+
"days_of_week": [1, 2, 3, 4, 5],
|
|
773
|
+
"max_concurrent_calls": 3,
|
|
774
|
+
"max_retries": 3,
|
|
775
|
+
"retry_delay_minutes": 60
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
```
|
|
779
|
+
|
|
780
|
+
Schedule defaults: `daily_start_time` = "09:00", `daily_end_time` = "18:00", `days_of_week` = [1-5], `max_concurrent_calls` = 1, `max_retries` = 3, `retry_delay_minutes` = 60.
|
|
781
|
+
|
|
782
|
+
**201 Created:**
|
|
783
|
+
|
|
784
|
+
```json
|
|
785
|
+
{
|
|
786
|
+
"campaign": { ... }
|
|
787
|
+
}
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
**Errors:**
|
|
791
|
+
|
|
792
|
+
| Status | Condition |
|
|
793
|
+
|--------|-----------|
|
|
794
|
+
| 400 | Missing required fields |
|
|
795
|
+
| 404 | Survey or agent not found in this tenant |
|
|
796
|
+
|
|
797
|
+
---
|
|
798
|
+
|
|
799
|
+
### GET /campaigns/:id
|
|
800
|
+
|
|
801
|
+
Returns full campaign detail with populated survey and agent.
|
|
802
|
+
|
|
803
|
+
**Auth:** Bearer token
|
|
804
|
+
**Feature:** `outbound_campaigns`
|
|
805
|
+
**Roles:** `admin`, `manager`, `viewer`
|
|
806
|
+
|
|
807
|
+
**200 OK:**
|
|
808
|
+
|
|
809
|
+
```json
|
|
810
|
+
{
|
|
811
|
+
"campaign": {
|
|
812
|
+
"_id": "664f1e...",
|
|
813
|
+
"name": "Ocak Anketi",
|
|
814
|
+
"status": "running",
|
|
815
|
+
"survey_id": { "_id": "...", "name": "...", "status": "active", "questions": [ ... ] },
|
|
816
|
+
"agent_id": { "_id": "...", "phone_number": "...", "agent_template": "survey" },
|
|
817
|
+
"phone_list": [
|
|
818
|
+
{ "number": "+905551234567", "status": "completed", "attempts": 1, "last_attempt_at": "..." },
|
|
819
|
+
{ "number": "+905559876543", "status": "pending", "attempts": 0, "last_attempt_at": null }
|
|
820
|
+
],
|
|
821
|
+
"schedule": { ... },
|
|
822
|
+
"stats": { ... }
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
```
|
|
826
|
+
|
|
827
|
+
**Errors:**
|
|
828
|
+
|
|
829
|
+
| Status | Condition |
|
|
830
|
+
|--------|-----------|
|
|
831
|
+
| 404 | Campaign not found |
|
|
832
|
+
|
|
833
|
+
---
|
|
834
|
+
|
|
835
|
+
### PUT /campaigns/:id
|
|
836
|
+
|
|
837
|
+
Updates campaign name and/or schedule. Only allowed in `draft` or `scheduled` status.
|
|
838
|
+
|
|
839
|
+
**Auth:** Bearer token
|
|
840
|
+
**Feature:** `outbound_campaigns`
|
|
841
|
+
**Roles:** `admin`, `manager`
|
|
842
|
+
|
|
843
|
+
**Request Body:**
|
|
844
|
+
|
|
845
|
+
```json
|
|
846
|
+
{
|
|
847
|
+
"name": "Updated Name",
|
|
848
|
+
"schedule": {
|
|
849
|
+
"daily_start_time": "10:00",
|
|
850
|
+
"max_concurrent_calls": 5
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
**200 OK:**
|
|
856
|
+
|
|
857
|
+
```json
|
|
858
|
+
{
|
|
859
|
+
"campaign": { ... }
|
|
860
|
+
}
|
|
861
|
+
```
|
|
862
|
+
|
|
863
|
+
**Errors:**
|
|
864
|
+
|
|
865
|
+
| Status | Condition |
|
|
866
|
+
|--------|-----------|
|
|
867
|
+
| 400 | Campaign is not in draft or scheduled status |
|
|
868
|
+
| 404 | Campaign not found |
|
|
869
|
+
|
|
870
|
+
---
|
|
871
|
+
|
|
872
|
+
### Campaign State Machine
|
|
873
|
+
|
|
874
|
+
```
|
|
875
|
+
draft → scheduled → running → paused → running (resume)
|
|
876
|
+
↓ ↓
|
|
877
|
+
completed completed
|
|
878
|
+
```
|
|
879
|
+
|
|
880
|
+
All state transition endpoints return `{ "campaign": { ... } }` on success.
|
|
881
|
+
|
|
882
|
+
#### POST /campaigns/:id/start
|
|
883
|
+
|
|
884
|
+
Starts a campaign. If in `draft`, transitions through `scheduled` → `running` automatically. Requires a non-empty phone list.
|
|
885
|
+
|
|
886
|
+
**Roles:** `admin`, `manager`
|
|
887
|
+
|
|
888
|
+
**Errors:**
|
|
889
|
+
|
|
890
|
+
| Status | Condition |
|
|
891
|
+
|--------|-----------|
|
|
892
|
+
| 400 | Phone list is empty |
|
|
893
|
+
| 400 | Invalid transition (e.g., already completed) |
|
|
894
|
+
| 404 | Campaign not found |
|
|
895
|
+
|
|
896
|
+
#### POST /campaigns/:id/pause
|
|
897
|
+
|
|
898
|
+
Pauses a running campaign.
|
|
899
|
+
|
|
900
|
+
**Roles:** `admin`, `manager`
|
|
901
|
+
|
|
902
|
+
**Errors:**
|
|
903
|
+
|
|
904
|
+
| Status | Condition |
|
|
905
|
+
|--------|-----------|
|
|
906
|
+
| 400 | Campaign is not running |
|
|
907
|
+
|
|
908
|
+
#### POST /campaigns/:id/resume
|
|
909
|
+
|
|
910
|
+
Resumes a paused campaign.
|
|
911
|
+
|
|
912
|
+
**Roles:** `admin`, `manager`
|
|
913
|
+
|
|
914
|
+
**Errors:**
|
|
915
|
+
|
|
916
|
+
| Status | Condition |
|
|
917
|
+
|--------|-----------|
|
|
918
|
+
| 400 | Campaign is not paused |
|
|
919
|
+
|
|
920
|
+
#### POST /campaigns/:id/stop
|
|
921
|
+
|
|
922
|
+
Permanently stops a campaign (marks as completed). Works from any non-completed status.
|
|
923
|
+
|
|
924
|
+
**Roles:** `admin`, `manager`
|
|
925
|
+
|
|
926
|
+
**Errors:**
|
|
927
|
+
|
|
928
|
+
| Status | Condition |
|
|
929
|
+
|--------|-----------|
|
|
930
|
+
| 400 | Campaign is already completed |
|
|
931
|
+
|
|
932
|
+
---
|
|
933
|
+
|
|
934
|
+
### POST /campaigns/:id/phone-list
|
|
935
|
+
|
|
936
|
+
Uploads a phone number list. Only allowed in `draft` or `scheduled` status. Replaces the existing list.
|
|
937
|
+
|
|
938
|
+
**Auth:** Bearer token
|
|
939
|
+
**Feature:** `outbound_campaigns`
|
|
940
|
+
**Roles:** `admin`, `manager`
|
|
941
|
+
|
|
942
|
+
**Request Body (JSON array):**
|
|
943
|
+
|
|
944
|
+
```json
|
|
945
|
+
{
|
|
946
|
+
"numbers": ["+905551234567", "+905559876543", "+905551112233"]
|
|
947
|
+
}
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
**Request Body (CSV string):**
|
|
951
|
+
|
|
952
|
+
```json
|
|
953
|
+
{
|
|
954
|
+
"csv": "phone\n+905551234567\n+905559876543\n+905551112233"
|
|
955
|
+
}
|
|
956
|
+
```
|
|
957
|
+
|
|
958
|
+
The CSV parser:
|
|
959
|
+
- Takes the first column from each row
|
|
960
|
+
- Skips header rows (phone, number, tel, numara)
|
|
961
|
+
- Strips non-digit characters, requires 10+ digits
|
|
962
|
+
- Adds `+` prefix if missing
|
|
963
|
+
- Deduplicates
|
|
964
|
+
|
|
965
|
+
**200 OK:**
|
|
966
|
+
|
|
967
|
+
```json
|
|
968
|
+
{
|
|
969
|
+
"campaign": {
|
|
970
|
+
"id": "664f1e...",
|
|
971
|
+
"phone_count": 3,
|
|
972
|
+
"stats": {
|
|
973
|
+
"total": 3,
|
|
974
|
+
"pending": 3,
|
|
975
|
+
"completed": 0,
|
|
976
|
+
"failed": 0,
|
|
977
|
+
"no_answer": 0,
|
|
978
|
+
"voicemail": 0
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
```
|
|
983
|
+
|
|
984
|
+
**Errors:**
|
|
985
|
+
|
|
986
|
+
| Status | Condition |
|
|
987
|
+
|--------|-----------|
|
|
988
|
+
| 400 | Neither `numbers` nor `csv` provided |
|
|
989
|
+
| 400 | No valid phone numbers found |
|
|
990
|
+
| 400 | Campaign is not in draft or scheduled status |
|
|
991
|
+
| 404 | Campaign not found |
|
|
992
|
+
|
|
993
|
+
---
|
|
994
|
+
|
|
995
|
+
### GET /campaigns/:id/results
|
|
996
|
+
|
|
997
|
+
Returns structured survey results for all calls in the campaign, plus aggregated stats from actual Call records.
|
|
998
|
+
|
|
999
|
+
**Auth:** Bearer token
|
|
1000
|
+
**Feature:** `outbound_campaigns`
|
|
1001
|
+
**Roles:** `admin`, `manager`, `viewer`
|
|
1002
|
+
|
|
1003
|
+
**200 OK:**
|
|
1004
|
+
|
|
1005
|
+
```json
|
|
1006
|
+
{
|
|
1007
|
+
"campaign": {
|
|
1008
|
+
"id": "664f1e...",
|
|
1009
|
+
"name": "Ocak Anketi",
|
|
1010
|
+
"status": "running",
|
|
1011
|
+
"stats": { "total": 100, "pending": 50, "completed": 42, "..." : "..." },
|
|
1012
|
+
"call_stats": { "total": 45, "completed": 42, "failed": 2, "no_answer": 1 }
|
|
1013
|
+
},
|
|
1014
|
+
"results": [
|
|
1015
|
+
{
|
|
1016
|
+
"call_id": "664f1f...",
|
|
1017
|
+
"caller_number": "+905551234567",
|
|
1018
|
+
"status": "completed",
|
|
1019
|
+
"duration_seconds": 180,
|
|
1020
|
+
"survey_responses": [
|
|
1021
|
+
{
|
|
1022
|
+
"question_id": "Q1",
|
|
1023
|
+
"question_text": "Hizmetimizi nasil degerlendirirsiniz?",
|
|
1024
|
+
"answer": "4",
|
|
1025
|
+
"parsed_value": 4
|
|
1026
|
+
}
|
|
1027
|
+
],
|
|
1028
|
+
"llm_summary": null,
|
|
1029
|
+
"createdAt": "2025-01-15T10:00:00.000Z"
|
|
1030
|
+
}
|
|
1031
|
+
]
|
|
1032
|
+
}
|
|
1033
|
+
```
|
|
1034
|
+
|
|
1035
|
+
**Errors:**
|
|
1036
|
+
|
|
1037
|
+
| Status | Condition |
|
|
1038
|
+
|--------|-----------|
|
|
1039
|
+
| 404 | Campaign not found |
|
|
1040
|
+
|
|
1041
|
+
---
|
|
1042
|
+
|
|
1043
|
+
### GET /campaigns/:id/results/export
|
|
1044
|
+
|
|
1045
|
+
Downloads campaign results as a CSV file. Columns include phone number, status, duration, date, one column per survey question, and summary.
|
|
1046
|
+
|
|
1047
|
+
**Auth:** Bearer token
|
|
1048
|
+
**Feature:** `outbound_campaigns`
|
|
1049
|
+
**Roles:** `admin`, `manager`, `viewer`
|
|
1050
|
+
|
|
1051
|
+
**Response:**
|
|
1052
|
+
|
|
1053
|
+
- `Content-Type: text/csv; charset=utf-8`
|
|
1054
|
+
- `Content-Disposition: attachment; filename="campaign-{id}-results.csv"`
|
|
1055
|
+
|
|
1056
|
+
**Example CSV:**
|
|
1057
|
+
|
|
1058
|
+
```
|
|
1059
|
+
Telefon,Durum,Sure (sn),Tarih,Hizmetimizi nasil degerlendirirsiniz?,Tekrar tercih eder misiniz?,Ozet
|
|
1060
|
+
+905551234567,completed,180,2025-01-15T10:00:00.000Z,4,Evet,
|
|
1061
|
+
+905559876543,completed,120,2025-01-15T11:00:00.000Z,5,Evet,
|
|
1062
|
+
+905551112233,no_answer,0,2025-01-15T12:00:00.000Z,,,
|
|
1063
|
+
```
|
|
1064
|
+
|
|
1065
|
+
**Errors:**
|
|
1066
|
+
|
|
1067
|
+
| Status | Condition |
|
|
1068
|
+
|--------|-----------|
|
|
1069
|
+
| 404 | Campaign not found |
|
|
1070
|
+
|
|
1071
|
+
---
|
|
1072
|
+
|
|
1073
|
+
## Billing
|
|
1074
|
+
|
|
1075
|
+
Base URL: `/billing`
|
|
1076
|
+
|
|
1077
|
+
All routes require authentication. Admin only.
|
|
1078
|
+
|
|
1079
|
+
### GET /billing/usage
|
|
1080
|
+
|
|
1081
|
+
Returns usage summary for the current billing period (calendar month). Aggregates call counts, durations, and charges from actual Call and BillingEvent records.
|
|
1082
|
+
|
|
1083
|
+
**Auth:** Bearer token
|
|
1084
|
+
**Roles:** `admin`
|
|
1085
|
+
|
|
1086
|
+
**200 OK:**
|
|
1087
|
+
|
|
1088
|
+
```json
|
|
1089
|
+
{
|
|
1090
|
+
"usage": {
|
|
1091
|
+
"period_start": "2025-02-01T00:00:00.000Z",
|
|
1092
|
+
"period_end": "2025-02-28T23:59:59.999Z",
|
|
1093
|
+
"total_calls": 150,
|
|
1094
|
+
"total_duration_seconds": 14325,
|
|
1095
|
+
"total_duration_minutes": 239,
|
|
1096
|
+
"inbound_calls": 100,
|
|
1097
|
+
"outbound_calls": 50,
|
|
1098
|
+
"total_charges": 358.5,
|
|
1099
|
+
"currency": "TRY"
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
```
|
|
1103
|
+
|
|
1104
|
+
**Pricing:** Calls are charged at **1.5 TRY per minute** (rounded up to nearest minute). A billing event is automatically logged after each completed call via the webhook pipeline.
|
|
1105
|
+
|
|
1106
|
+
---
|
|
1107
|
+
|
|
1108
|
+
### GET /billing/history
|
|
1109
|
+
|
|
1110
|
+
Returns paginated billing event history. Each event includes type, amount, and linked call details.
|
|
1111
|
+
|
|
1112
|
+
**Auth:** Bearer token
|
|
1113
|
+
**Roles:** `admin`
|
|
1114
|
+
|
|
1115
|
+
**Query Parameters:**
|
|
1116
|
+
|
|
1117
|
+
| Param | Type | Default | Description |
|
|
1118
|
+
|-------|------|---------|-------------|
|
|
1119
|
+
| `page` | number | `1` | Page number |
|
|
1120
|
+
| `type` | string | - | Filter: `call_charge`, `subscription`, `top_up`, `refund` |
|
|
1121
|
+
|
|
1122
|
+
**200 OK:**
|
|
1123
|
+
|
|
1124
|
+
```json
|
|
1125
|
+
{
|
|
1126
|
+
"events": [
|
|
1127
|
+
{
|
|
1128
|
+
"_id": "664f20...",
|
|
1129
|
+
"tenant_id": "664f1a...",
|
|
1130
|
+
"type": "call_charge",
|
|
1131
|
+
"amount": 3,
|
|
1132
|
+
"currency": "TRY",
|
|
1133
|
+
"call_id": {
|
|
1134
|
+
"_id": "664f1f...",
|
|
1135
|
+
"caller_number": "+905551234567",
|
|
1136
|
+
"duration_seconds": 120,
|
|
1137
|
+
"direction": "inbound"
|
|
1138
|
+
},
|
|
1139
|
+
"param_transaction_id": null,
|
|
1140
|
+
"description": "Arama ucreti: 2 dk",
|
|
1141
|
+
"createdAt": "2025-02-15T10:00:00.000Z"
|
|
1142
|
+
}
|
|
1143
|
+
],
|
|
1144
|
+
"total": 150,
|
|
1145
|
+
"page": 1,
|
|
1146
|
+
"totalPages": 8
|
|
1147
|
+
}
|
|
1148
|
+
```
|
|
1149
|
+
|
|
1150
|
+
**Billing event types:**
|
|
1151
|
+
|
|
1152
|
+
| Type | Description |
|
|
1153
|
+
|------|-------------|
|
|
1154
|
+
| `call_charge` | Auto-logged per completed call |
|
|
1155
|
+
| `subscription` | Monthly subscription charge (future) |
|
|
1156
|
+
| `top_up` | Balance top-up via payment (future) |
|
|
1157
|
+
| `refund` | Refund (future) |
|
|
1158
|
+
|
|
1159
|
+
---
|
|
1160
|
+
|
|
1161
|
+
## Route Summary
|
|
1162
|
+
|
|
1163
|
+
| Method | Path | Auth | Feature | Roles | Description |
|
|
1164
|
+
|--------|------|------|---------|-------|-------------|
|
|
1165
|
+
| GET | `/tenants/me` | JWT | - | any | Get tenant details |
|
|
1166
|
+
| PUT | `/tenants/me` | JWT | - | admin | Update tenant settings |
|
|
1167
|
+
| GET | `/users` | JWT | - | all | List tenant users |
|
|
1168
|
+
| POST | `/users/invite` | JWT | - | admin | Create user |
|
|
1169
|
+
| PUT | `/users/:id` | JWT | - | admin | Update user role/name |
|
|
1170
|
+
| DELETE | `/users/:id` | JWT | - | admin | Remove user |
|
|
1171
|
+
| GET | `/calls` | JWT | - | all | List calls (paginated) |
|
|
1172
|
+
| GET | `/calls/stats` | JWT | - | all | Call statistics |
|
|
1173
|
+
| GET | `/calls/:id` | JWT | - | all | Call detail |
|
|
1174
|
+
| GET | `/surveys` | JWT | survey_builder | all | List surveys |
|
|
1175
|
+
| POST | `/surveys` | JWT | survey_builder | admin, manager | Create survey |
|
|
1176
|
+
| GET | `/surveys/:id` | JWT | survey_builder | all | Survey detail |
|
|
1177
|
+
| PUT | `/surveys/:id` | JWT | survey_builder | admin, manager | Update survey |
|
|
1178
|
+
| DELETE | `/surveys/:id` | JWT | survey_builder | admin, manager | Delete survey |
|
|
1179
|
+
| POST | `/surveys/:id/duplicate` | JWT | survey_builder | admin, manager | Clone survey |
|
|
1180
|
+
| GET | `/campaigns` | JWT | outbound_campaigns | all | List campaigns |
|
|
1181
|
+
| POST | `/campaigns` | JWT | outbound_campaigns | admin, manager | Create campaign |
|
|
1182
|
+
| GET | `/campaigns/:id` | JWT | outbound_campaigns | all | Campaign detail |
|
|
1183
|
+
| PUT | `/campaigns/:id` | JWT | outbound_campaigns | admin, manager | Update campaign |
|
|
1184
|
+
| POST | `/campaigns/:id/start` | JWT | outbound_campaigns | admin, manager | Start campaign |
|
|
1185
|
+
| POST | `/campaigns/:id/pause` | JWT | outbound_campaigns | admin, manager | Pause campaign |
|
|
1186
|
+
| POST | `/campaigns/:id/resume` | JWT | outbound_campaigns | admin, manager | Resume campaign |
|
|
1187
|
+
| POST | `/campaigns/:id/stop` | JWT | outbound_campaigns | admin, manager | Stop campaign |
|
|
1188
|
+
| POST | `/campaigns/:id/phone-list` | JWT | outbound_campaigns | admin, manager | Upload phone list |
|
|
1189
|
+
| GET | `/campaigns/:id/results` | JWT | outbound_campaigns | all | Survey results |
|
|
1190
|
+
| GET | `/campaigns/:id/results/export` | JWT | outbound_campaigns | all | Export CSV |
|
|
1191
|
+
| GET | `/billing/usage` | JWT | - | admin | Current period usage |
|
|
1192
|
+
| GET | `/billing/history` | JWT | - | admin | Billing event history |
|
|
1193
|
+
| POST | `/webhooks/elevenlabs` | HMAC | - | - | ElevenLabs webhook |
|