Skip to main content

AI Brief: hbf-lcg

What It Is

hbf-lcg (Live Chat Gateway) is a unified gateway for livechat integrations. It bridges communication between hbf-bot and multiple livechat platform providers (Helvia/hbf-lcm, Cisco WebEx, Genesys Cloud, Zendesk). The service handles bidirectional event transformation, session management, and distributed instance coordination via Redis.

Tech Stack

  • Runtime: Node.js 22, NestJS
  • Database: MySQL/MariaDB (TypeORM, lcm database)
  • Cache: Redis (optional, falls back to in-memory)
  • Cluster: Redis microservice transport for distributed coordination (leader election, RPC, heartbeat)
  • Monitoring: Elastic APM (optional)
  • Logging: Pino (ECS format)

Entry Points

  • src/main.ts -- NestJS bootstrap, HTTP on SERVICE_PORT (default 1337), Redis microservice
  • src/app.module.ts -- Root module, imports all feature modules

Key Directories

src/
entities/ -- TypeORM entities (LiveChatSession, CiscoEvent)
dtos/ -- Request/response DTOs
filters/ -- Global exception filter
guards/ -- JWT guard
features/
adapters/ -- Polling adapters (Cisco, Zendesk, Genesys)
auth/ -- JWT verification
clients/ -- Outbound HTTP clients (Core, Bot, Genesys, Cisco, Sunshine/Zendesk)
distributed/ -- Redis-based cluster coordination (leader election, RPC)
downstream/ -- Event transformers FROM external services TO hbf-bot
gateway/ -- Main gateway logic, upstream/downstream controllers
resolver/ -- Dynamic service resolution by alias/integration type
upstream/ -- Request forwarders FROM hbf-bot TO external services
migrations/ -- TypeORM migrations (4 total)

API Endpoints

Upstream (hbf-bot -> external services) -- JWT protected

MethodEndpointPurpose
POST/requestsCreate livechat request
PATCH/requests/subscribers/:subHandleUpdate request by subscriber
DELETE/sessions/tenants/:tenantId/subscribers/:subHandleTerminate session
POST/messagesForward user message
HEAD/organizations/:organizationId/requests?status=Count requests (X-Total-Count)
HEAD/organizations/:organizationId/tenants/:tenantId/metricsAvg wait time (X-Average-Waiting-Time)
GET/subscribers/:subHandle/livechat-stateGet subscriber status
GET/tenants/:tenantId/availabilityGet availability + business hours

Downstream (external services -> hbf-bot)

MethodEndpointPurpose
POST/events/:aliasReceive callback events from external services
HEAD/events/:aliasHealth check

External Dependencies

ServicePurpose
hbf-core (HBF_CORE_URL)Tenant config, organization data, plugin settings
hbf-lcm (HBF_LCM_URL)Helvia internal livechat (upstream forwarding)
hbf-bot (HBF_BOT_EVENT_URL)Deliver transformed events back to bot engine
Genesys Cloud APIOAuth2, messaging, WebSocket events
Cisco WebEx APIContact center polling
Zendesk Sunshine APIConversation polling, messaging

Supported Livechat Providers

ProviderUpstreamDownstreamAdapter
Helvia (hbf-lcm)UpstreamHelviaServiceDownstreamHelviaService (JWT verified)None (webhook)
Cisco WebExUpstreamCiscoServiceDownstreamCiscoServiceCiscoPollingAdapterService (5s poll)
Genesys CloudUpstreamGenesysServiceDownstreamGenesysServiceGenesysSocketAdapterDistributedService (WebSocket) + GenesysPollingAdapterService (inactive monitor)
ZendeskUpstreamZendeskServiceDownstreamZendeskServiceZendeskPollingAdapterService

Data Model

Two entities:

  • LiveChatSession: Tracks active sessions (subscriberHandle, externalServiceSessionId, organizationId, tenantId, integrationType, status, plugin JSON)
  • CiscoEvent: Deduplicates Cisco polling events per session (eventId + session unique constraint)

Run Commands

  • Dev: npm run start:dev
  • Build: npm run build
  • Production: npm run start:prod
  • Migrations: npm run migration:run