AI Brief: hbf-event-publisher
A NestJS service that bridges platform events (livechat, survey, chat session) to external automation connectors (Microsoft Power Automate) and delivers push notifications to mobile/web devices via Firebase. It is the platform's outbound event bus.
What This Repo Does
hbf-event-publisher exposes two API surfaces: a connectors API that registers, lists, triggers, and tracks external flows (e.g., Power Automate webhooks), and a push notifications API that registers device tokens and sends FCM messages to individual or multiple users. Trigger delivery is synchronous (direct HTTP).
Tech Stack
- Language: TypeScript
- Framework: NestJS v9 (Express platform)
- Key dependencies:
@nestjs/typeorm,typeorm,mysql2,cache-manager,firebase-admin,@nestjs/jwt,got,nestjs-pino,elastic-apm-node
Entry Points
- Main:
src/main.ts - Root module:
src/app.module.ts - Config:
.env/.env.local(loaded by@nestjs/config)
Key Directories
| Directory | Purpose |
|---|---|
src/services/connectors/ | Connector API: flow registration, trigger dispatch, status callback. |
src/services/connectors/power-automate/ | Power Automate implementation of IConnectorsService. |
src/services/push/ | Push notifications API: device registration, Firebase send. |
src/services/push/firebase/ | Firebase Admin SDK implementation of IPushNotificationService. |
src/services/clients/ | HTTP client wrappers for hbf-core. |
src/services/auth/ | JWT signing/verification service. |
src/entities/ | TypeORM entities: FlowAssociation, PushAssociation. |
src/dtos/ | Request/response DTOs with class-validator. |
src/guards/ | HBFGuard (hbf-core token), JWTGuard (internal JWT). |
src/migrations/ | TypeORM database migrations. |
API Surface
Connectors (/connectors)
GET /connectors/flows?triggerType=&organizationId=&tenantId=&activityId=— list registered flowsDELETE /connectors/flows/:flowId— delete a flowPOST /connectors/flows:trigger?triggerType=&organizationId=&tenantId=&activityId=— fire matching flowsPATCH /connectors/triggers/:flowId— callback to update trigger success/failure status
Push Notifications (/push/:implementation)
POST /push/:implementation/register— register device tokenPOST /push/:implementation/unregister— invalidate device tokenPOST /push/:implementation/send— send to one platform userPOST /push/:implementation/send-to-many— send to multiple platform usersPOST /push/:implementation/send-batch— send batch of messages to one userPOST /push/:implementation/send-batch-to-many— send batch to multiple users
Current implementation values: firebase.
Trigger Types (enum TriggerType)
livechat-request-missed, livechat-conversation-finished, survey-completed, automated-answer-triggered, chat-session-completed
External Dependencies
- MySQL: TypeORM with MySQL2 driver — stores
FlowAssociationandPushAssociationtables - Firebase Admin SDK:
firebase-admin— FCM multicast push delivery (max 500 tokens/request) - hbf-core: validates inbound HBF tokens via
HBFGuard - APM:
elastic-apm-node— optional
Running Locally
npm install
cp .env .env.local # fill in DB credentials, Firebase key path, JWT secrets
npm run start:dev
Tests
npm test # unit tests (jest)
npm run test:e2e # e2e tests
npm run test:cov # coverage report