Architecture: hbf-session-manager
C4 Component Diagram
Key Flows
Session Expiry and Completion (main scheduled flow)
SchedulerServicefirescheckConversationscron at everyCHAT_SESSION_CHECK_INTERVAL_IN_MINSminutes.SessionsService.checkConversations()loads all enabled webhook integrations from MySQL.findInactiveChatSessions()is called: a. All tenants are loaded from hbf-core withincludeSettings,includeSystemSettings, andincludePlugins. b. Tenant usage is checked. If usage exceedsmaxNumOfSessionsormaxNumOfUserMessages, the tenant is setdisabled: truein hbf-core. c. For each tenant, the per-tenantexpireInactiveSessionAfteris read (fallback:BOT_EXPIRE_CONVERSATION_AFTER_DEFAULT_VALUEseconds). d. hbf-core is paginated to findACTIVEsessions whoselastInteractionis older than the threshold. e. Only sessions where all associated live chats have statusLIVECHAT_TERMINATEDare selected. f. Selected session IDs are batch-set toCOMPLETEDviabatchSetStatusCompleted. g. For each selected session:handleTriggerFlows()fireschat-session-completedandsurvey-completedevents to hbf-event-publisher.- For each enabled integration, each completed session is matched against
integration.tenants[]. If the session's tenant matches,sendChatSession()POSTs the fullChatSessionDTOtointegration.urlwith custom headers. - On webhook failure: error is saved to
SessionIntegrationError. IferrorEmailRecipientsis set, an HTML email is sent via nodemailer using the Handlebars template. - After all session processing:
handleChatSessionSummarization()is called. For tenants withLLM_SUMMARIZATIONplugin andautomaticallyRunOnSessionCompletion: true,hbf-nlp.summarizeChatSession()is called fire-and-forget (non-blocking) for sessions that contain user interactions.
NLP Pipeline Auto-Training
SchedulerServicefirescheckNLPPipelinescron. After each run, the next trigger is scheduledNLP_PIPELINE_CHECK_INTERVAL_IN_MINSminutes from completion (not from start — prevents overlap).NLPPipelinesService.checkForOutdatedPipelines()queries hbf-core for pipelines withtenantHasAutoTrain: trueand a non-current status.- For each outdated pipeline,
hbfCoreService.trainOne(id, { waitUntilCompletion: true })is called. Training completion is polled using RxJSinterval+takeWhileuntil status transitions fromTRAINING, with a configurable timeout.
Webhook Integration Management
An org admin creates an integration specifying a URL, list of tenant IDs to scope, custom HTTP headers (stored separately in hbf_sessions_headers), whether it is enabled, and optional error email recipients. The session expiry flow only dispatches to integrations where enabled: true and where the session's tenant.id is in the integration's tenants[] array. Each organization can have at most one integration (enforced by a UNIQUE constraint on organization_id in hbf_sessions_integrations).