diff --git a/.gitignore b/.gitignore index 6370798..5e32110 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ __pycache__/ *.pyc +keycloak/*.env +keycloak/.env diff --git a/docker-compose.aimaq.override.yml b/docker-compose.aimaq.override.yml index 96d3f64..ffc6e12 100644 --- a/docker-compose.aimaq.override.yml +++ b/docker-compose.aimaq.override.yml @@ -6,3 +6,133 @@ services: SALES_VOICE_RUNTIME_ENABLED: "1" ASTERISK_CALLCONTROL_ENABLED: "1" ASTERISK_WEBRTC_ENABLED: "1" + ai-voice-runtime-service: + environment: + ERROR_TELEGRAM_ALERTS: "1" + ai-orchestrator-service: + environment: + ERROR_TELEGRAM_ALERTS: "1" + api-gateway: + environment: + PLATFORM_SERVICE_URL: "http://platform-service:8000" + QC_SERVICE_URL: "http://call-center-platform:8090" + WFM_SERVICE_URL: "http://call-center-platform:8090" + depends_on: !override + call-center-platform: {condition: service_healthy} + ai-orchestrator-service: {condition: service_healthy} + ai-voice-runtime-service: {condition: service_healthy} + asterisk-bridge-service: {condition: service_started} + auth-service: {condition: service_started} + interaction-service: {condition: service_started} + kb-service: {condition: service_healthy} + recording-service: {condition: service_started} + reporting-service: {condition: service_started} + routing-service: {condition: service_healthy} + sales-service: {condition: service_started} + telegram-adapter-service: {condition: service_healthy} + voice-adapter-service: {condition: service_started} + whatsapp-adapter-service: {condition: service_healthy} + platform-service: + image: ${CALL_CENTER_IMAGE:-call-center-app:active-aimaq} + restart: unless-stopped + env_file: + - ./.env.production + environment: + APP_MODULE: services.platform_service.app:app + CC_DATA_DIR: /app/.data_local + DATABASE_URL: postgresql+psycopg://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB} + SCHEMA_MANAGEMENT_MODE: migrations + CASE_PLATFORM_ENABLED: "1" + volumes: + - ./.data_local:/app/.data_local + extra_hosts: + - host.docker.internal:host-gateway + depends_on: + - postgres + audit-service: + profiles: ["archived"] + customer-service: + profiles: ["archived"] + email-adapter-service: + profiles: ["archived"] + event-bus-service: + profiles: ["archived"] + ivr-service: + profiles: ["archived"] + webchat-adapter-service: + profiles: ["archived"] + qc-service: + profiles: ["archived"] + wfm-service: + profiles: ["archived"] + call-center-platform: + image: ${CALL_CENTER_PLATFORM_IMAGE:-call-center-platform:latest} + restart: unless-stopped + env_file: + - ./.env.production + environment: + DATABASE_URL: jdbc:postgresql://postgres:5432/${POSTGRES_DB} + DATABASE_USER: ${POSTGRES_USER} + DATABASE_PASSWORD: ${POSTGRES_PASSWORD} + DATABASE_POOL_SIZE: "8" + KEYCLOAK_ISSUER_URI: https://aimaq.konturai.kz/auth/realms/callcenter + JAVA_TOOL_OPTIONS: "-XX:MaxRAMPercentage=70 -XX:+ExitOnOutOfMemoryError -XX:+UseSerialGC -Xss512k" + mem_limit: 512m + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8090/health >/dev/null || exit 1"] + interval: 15s + timeout: 5s + retries: 10 + start_period: 40s + depends_on: + postgres: + condition: service_healthy + keycloak: + image: quay.io/keycloak/keycloak:26.8.0 + restart: unless-stopped + command: ["start", "--import-realm"] + env_file: + - ./keycloak/.env + environment: + KC_DB: postgres + KC_DB_URL: jdbc:postgresql://postgres:5432/keycloak + KC_DB_USERNAME: keycloak + KC_DB_POOL_MAX_SIZE: "10" + KC_HOSTNAME: https://aimaq.konturai.kz/auth + KC_HTTP_ENABLED: "true" + KC_HTTP_RELATIVE_PATH: /auth + KC_PROXY_HEADERS: xforwarded + KC_HEALTH_ENABLED: "true" + KC_CACHE: local + KC_LOG_LEVEL: INFO + JAVA_OPTS_KC_HEAP: "-XX:MaxRAMPercentage=65 -XX:InitialRAMPercentage=30" + volumes: + - ./keycloak/callcenter-realm.json:/opt/keycloak/data/import/callcenter-realm.json:ro + mem_limit: 900m + healthcheck: + test: ["CMD-SHELL", "exec 3<>/dev/tcp/127.0.0.1/9000 && printf 'GET /auth/health/ready HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n' >&3 && grep -q UP <&3"] + interval: 15s + timeout: 5s + retries: 20 + start_period: 90s + depends_on: + postgres: + condition: service_healthy + networks: + - default + - common_network + auth-service: + env_file: + - ./.env.production + - ./keycloak/auth-client.env + environment: + OIDC_ENABLED: "1" + OIDC_PROVIDER: keycloak + OIDC_ISSUER_URL: https://aimaq.konturai.kz/auth/realms/callcenter + OIDC_CLIENT_ID: callcenter-auth + OIDC_REDIRECT_URI: https://aimaq.konturai.kz/proxy/auth/auth/oidc/callback + OIDC_SCOPES: openid profile email + OIDC_ROLE_CLAIM: roles + OIDC_ROLE_MAP_JSON: '{"admin":"admin","supervisor":"supervisor","operator":"operator","analyst":"analyst"}' + supervisor-service: + profiles: ["archived"] diff --git a/docker-compose.minimal.yml b/docker-compose.minimal.yml index 241a06c..33392cd 100644 --- a/docker-compose.minimal.yml +++ b/docker-compose.minimal.yml @@ -1,3 +1,4 @@ + name: aimaq-call-center x-app-env: &app_env @@ -13,6 +14,8 @@ x-app-env: &app_env ASTERISK_BRIDGE_SERVICE_URL: http://asterisk-bridge-service:8000 SALES_SERVICE_URL: http://sales-service:8000 REPORTING_SERVICE_URL: http://reporting-service:8000 + QC_SERVICE_URL: http://qc-service:8000 + WFM_SERVICE_URL: http://wfm-service:8000 LOCAL_STACK_PUBLIC_BASE_URL: https://aimaq.konturai.kz ASTERISK_WEBRTC_WS_URL: wss://aimaq.konturai.kz/asterisk-ws ASTERISK_CALLCONTROL_ENABLED: "0" @@ -62,6 +65,7 @@ services: migrate: <<: *service_defaults + image: ${MIGRATE_IMAGE:-call-center-app:active-main} restart: "no" depends_on: postgres: @@ -118,6 +122,22 @@ services: CC_RECORDINGS_DIR: /app/.data_local/recordings RECORDING_MAX_BYTES: 26214400 + qc-service: + <<: *service_defaults + depends_on: + - postgres + environment: + <<: *app_env + APP_MODULE: services.qc_service.app:app + + wfm-service: + <<: *service_defaults + depends_on: + - postgres + environment: + <<: *app_env + APP_MODULE: services.wfm_service.app:app + reporting-service: <<: *service_defaults depends_on: @@ -169,6 +189,7 @@ services: - reporting-service - sales-service - asterisk-bridge-service + - wfm-service environment: <<: *app_env APP_MODULE: gateway.app:app diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 1775514..7ffb97b 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -8,9 +8,6 @@ services: - AI_VOICE_V2_DUPLEX_ENABLED=1 - AI_VOICE_V2_STREAMING_ASR_TIMEOUT_SECONDS=15 - AI_VOICE_V2_STREAMING_ASR_SUPPORTED_LANGUAGES=ru,kk - - AI_VOICE_VAD_RMS_THRESHOLD=300 - - AI_VOICE_VAD_MIN_SPEECH_MS=200 - - AI_VOICE_VAD_TRAILING_SILENCE_MS=800 - AI_VOICE_NO_SPEECH_REPROMPT_ENABLED=1 - AI_VOICE_V2_ACK_MODE=immediate_short - AI_VOICE_V2_EMOTIVE_ACK_ENABLED=1 @@ -23,6 +20,8 @@ services: - ASTERISK_BRIDGE_ENABLED=1 - ASTERISK_SFTP_HOST=172.19.0.1 - MVPCC_AI_AUDIOSOCKET_SERVICE=127.0.0.1:9019 + volumes: + - /home/mvpcc/asterisk-runtime/monitor/mvpcc:/home/mvpcc/asterisk-runtime/monitor/mvpcc:ro sales-service: environment: - WHATSAPP_OUTBOUND_ENABLED=1 diff --git a/keycloak/callcenter-realm.json b/keycloak/callcenter-realm.json new file mode 100644 index 0000000..d006c1b --- /dev/null +++ b/keycloak/callcenter-realm.json @@ -0,0 +1,326 @@ +{ + "realm": "callcenter", + "displayName": "Аймак Колл-центр", + "enabled": true, + "sslRequired": "external", + "registrationAllowed": false, + "loginWithEmailAllowed": false, + "duplicateEmailsAllowed": true, + "resetPasswordAllowed": false, + "editUsernameAllowed": false, + "rememberMe": true, + "bruteForceProtected": true, + "permanentLockout": false, + "failureFactor": 10, + "waitIncrementSeconds": 60, + "maxFailureWaitSeconds": 900, + "internationalizationEnabled": true, + "supportedLocales": [ + "ru", + "kk", + "en" + ], + "defaultLocale": "ru", + "accessTokenLifespan": 900, + "ssoSessionIdleTimeout": 43200, + "ssoSessionMaxLifespan": 86400, + "passwordPolicy": "length(12) and notUsername", + "roles": { + "realm": [ + { + "name": "admin", + "description": "Администратор" + }, + { + "name": "supervisor", + "description": "Супервизор" + }, + { + "name": "operator", + "description": "Оператор" + }, + { + "name": "analyst", + "description": "Аналитик" + } + ] + }, + "clients": [ + { + "clientId": "callcenter-platform", + "name": "Contact-center platform API", + "enabled": true, + "bearerOnly": true, + "publicClient": false, + "standardFlowEnabled": false, + "directAccessGrantsEnabled": false + }, + { + "clientId": "callcenter-auth", + "name": "Contact-center login bridge", + "enabled": true, + "publicClient": false, + "clientAuthenticatorType": "client-secret", + "secret": "${AUTH_CLIENT_SECRET}", + "standardFlowEnabled": true, + "directAccessGrantsEnabled": false, + "implicitFlowEnabled": false, + "serviceAccountsEnabled": false, + "rootUrl": "https://aimaq.konturai.kz", + "redirectUris": [ + "https://aimaq.konturai.kz/proxy/auth/auth/oidc/callback" + ], + "webOrigins": [ + "https://aimaq.konturai.kz" + ], + "attributes": { + "pkce.code.challenge.method": "S256", + "post.logout.redirect.uris": "https://aimaq.konturai.kz/*" + }, + "defaultClientScopes": [ + "basic", + "profile", + "email", + "roles", + "web-origins", + "acr" + ], + "optionalClientScopes": [], + "protocolMappers": [ + { + "name": "tenant_id", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "config": { + "user.attribute": "tenant_id", + "claim.name": "tenant_id", + "jsonType.label": "String", + "access.token.claim": "true", + "id.token.claim": "true", + "userinfo.token.claim": "true" + } + }, + { + "name": "roles", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-realm-role-mapper", + "config": { + "claim.name": "roles", + "multivalued": "true", + "jsonType.label": "String", + "access.token.claim": "true", + "id.token.claim": "true", + "userinfo.token.claim": "true" + } + }, + { + "name": "platform-audience", + "protocol": "openid-connect", + "protocolMapper": "oidc-audience-mapper", + "config": { + "included.client.audience": "callcenter-platform", + "access.token.claim": "true", + "id.token.claim": "false" + } + } + ] + }, + { + "clientId": "callcenter-web", + "name": "Contact-center web", + "enabled": true, + "publicClient": true, + "standardFlowEnabled": true, + "directAccessGrantsEnabled": false, + "implicitFlowEnabled": false, + "rootUrl": "https://aimaq.konturai.kz", + "redirectUris": [ + "https://aimaq.konturai.kz/*" + ], + "webOrigins": [ + "https://aimaq.konturai.kz" + ], + "attributes": { + "pkce.code.challenge.method": "S256", + "post.logout.redirect.uris": "https://aimaq.konturai.kz/*" + }, + "defaultClientScopes": [ + "basic", + "profile", + "email", + "roles", + "web-origins", + "acr" + ], + "optionalClientScopes": [], + "protocolMappers": [ + { + "name": "tenant_id", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "config": { + "user.attribute": "tenant_id", + "claim.name": "tenant_id", + "jsonType.label": "String", + "access.token.claim": "true", + "id.token.claim": "true", + "userinfo.token.claim": "true" + } + }, + { + "name": "roles", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-realm-role-mapper", + "config": { + "claim.name": "roles", + "multivalued": "true", + "jsonType.label": "String", + "access.token.claim": "true", + "id.token.claim": "true", + "userinfo.token.claim": "true" + } + }, + { + "name": "platform-audience", + "protocol": "openid-connect", + "protocolMapper": "oidc-audience-mapper", + "config": { + "included.client.audience": "callcenter-platform", + "access.token.claim": "true", + "id.token.claim": "false" + } + } + ] + }, + { + "clientId": "callcenter-voice", + "name": "Voice engine service account", + "enabled": true, + "publicClient": false, + "clientAuthenticatorType": "client-secret", + "secret": "${VOICE_CLIENT_SECRET}", + "standardFlowEnabled": false, + "directAccessGrantsEnabled": false, + "serviceAccountsEnabled": true, + "defaultClientScopes": [ + "basic", + "roles" + ], + "protocolMappers": [ + { + "name": "platform-audience", + "protocol": "openid-connect", + "protocolMapper": "oidc-audience-mapper", + "config": { + "included.client.audience": "callcenter-platform", + "access.token.claim": "true", + "id.token.claim": "false" + } + } + ] + } + ], + "users": [ + { + "id": "usr_bdcbef7c68", + "username": "admin", + "firstName": "System", + "lastName": "Admin", + "enabled": true, + "attributes": { + "tenant_id": [ + "dev-aimaq" + ] + }, + "realmRoles": [ + "admin" + ], + "credentials": [ + { + "type": "password", + "value": "${KC_PASSWORD_ADMIN}", + "temporary": false + } + ] + }, + { + "id": "usr_8164b6518f", + "username": "supervisor", + "firstName": "Shift", + "lastName": "Supervisor", + "enabled": true, + "attributes": { + "tenant_id": [ + "dev-aimaq" + ] + }, + "realmRoles": [ + "supervisor" + ], + "credentials": [ + { + "type": "password", + "value": "${KC_PASSWORD_SUPERVISOR}", + "temporary": false + } + ] + }, + { + "id": "usr_add9799554", + "username": "operator", + "firstName": "Call", + "lastName": "Operator", + "enabled": true, + "attributes": { + "tenant_id": [ + "dev-aimaq" + ] + }, + "realmRoles": [ + "operator" + ], + "credentials": [ + { + "type": "password", + "value": "${KC_PASSWORD_OPERATOR}", + "temporary": false + } + ] + }, + { + "id": "usr_f342af6751", + "username": "analyst", + "firstName": "Business", + "lastName": "Analyst", + "enabled": true, + "attributes": { + "tenant_id": [ + "dev-aimaq" + ] + }, + "realmRoles": [ + "analyst" + ], + "credentials": [ + { + "type": "password", + "value": "${KC_PASSWORD_ANALYST}", + "temporary": false + } + ] + } + ], + "components": { + "org.keycloak.userprofile.UserProfileProvider": [ + { + "providerId": "declarative-user-profile", + "subComponents": {}, + "config": { + "kc.user.profile.config": [ + "{\"attributes\": [{\"name\": \"username\", \"displayName\": \"Логин\", \"validations\": {\"length\": {\"min\": 3, \"max\": 255}, \"username-prohibited-characters\": {}, \"up-username-not-idn-homograph\": {}}, \"permissions\": {\"view\": [\"admin\", \"user\"], \"edit\": [\"admin\", \"user\"]}, \"multivalued\": false}, {\"name\": \"email\", \"displayName\": \"Email\", \"validations\": {\"email\": {}, \"length\": {\"max\": 255}}, \"permissions\": {\"view\": [\"admin\", \"user\"], \"edit\": [\"admin\", \"user\"]}, \"multivalued\": false}, {\"name\": \"firstName\", \"displayName\": \"Имя\", \"validations\": {\"length\": {\"max\": 255}, \"person-name-prohibited-characters\": {}}, \"permissions\": {\"view\": [\"admin\", \"user\"], \"edit\": [\"admin\", \"user\"]}, \"multivalued\": false}, {\"name\": \"lastName\", \"displayName\": \"Фамилия\", \"validations\": {\"length\": {\"max\": 255}, \"person-name-prohibited-characters\": {}}, \"permissions\": {\"view\": [\"admin\", \"user\"], \"edit\": [\"admin\", \"user\"]}, \"multivalued\": false}, {\"name\": \"tenant_id\", \"displayName\": \"Арендатор\", \"validations\": {\"length\": {\"min\": 1, \"max\": 64}}, \"permissions\": {\"view\": [\"admin\", \"user\"], \"edit\": [\"admin\"]}, \"multivalued\": false}], \"groups\": [{\"name\": \"user-metadata\", \"displayHeader\": \"User metadata\", \"displayDescription\": \"Attributes, which refer to user metadata\"}]}" + ] + } + } + ] + } +}