mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage-server
synced 2026-05-18 20:08:19 +00:00
Compare commits
4 Commits
9890559ec1
...
hardening/
| Author | SHA1 | Date | |
|---|---|---|---|
| a837c95d8c | |||
| ac76ef5487 | |||
| 99954c1ff2 | |||
| 4b84792619 |
@@ -10,7 +10,7 @@ export default defineConfig({
|
||||
fileName: () => 'widget.js',
|
||||
formats: ['iife'],
|
||||
},
|
||||
outDir: '../../helix-engage-server/public',
|
||||
outDir: './dist',
|
||||
emptyOutDir: false,
|
||||
minify: 'esbuild',
|
||||
rollupOptions: {
|
||||
|
||||
@@ -67,6 +67,7 @@ export class SetupStateController {
|
||||
uiFlags() {
|
||||
return {
|
||||
setupManaged: process.env.HELIX_SETUP_MANAGED === 'true',
|
||||
telephonyEnabled: process.env.TELEPHONY_ENABLED !== 'false', // default true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,11 @@ import { PlatformModule } from '../platform/platform.module';
|
||||
import { AuthModule } from '../auth/auth.module';
|
||||
import { ConfigThemeModule } from '../config/config-theme.module';
|
||||
import { CallerResolutionModule } from '../caller/caller-resolution.module';
|
||||
import { LeadsModule } from '../leads/leads.module';
|
||||
import { SupervisorModule } from '../supervisor/supervisor.module';
|
||||
|
||||
// WidgetKeysService lives in ConfigThemeModule now — injected here via the
|
||||
// module's exports. This module only owns the widget-facing API endpoints
|
||||
// (init / chat / book / lead) plus the NestJS guards that consume the keys.
|
||||
@Module({
|
||||
imports: [PlatformModule, AuthModule, ConfigThemeModule, forwardRef(() => CallerResolutionModule)],
|
||||
imports: [PlatformModule, AuthModule, ConfigThemeModule, forwardRef(() => CallerResolutionModule), LeadsModule, SupervisorModule],
|
||||
controllers: [WidgetController, WebhooksController],
|
||||
providers: [WidgetService, WidgetChatService],
|
||||
})
|
||||
|
||||
@@ -5,6 +5,8 @@ import type { WidgetInitResponse, WidgetBookRequest, WidgetLeadRequest } from '.
|
||||
import { ThemeService } from '../config/theme.service';
|
||||
import { DOCTOR_VISIT_SLOTS_FRAGMENT, normalizeDoctors, type NormalizedDoctor } from '../shared/doctor-utils';
|
||||
import { CallerResolutionService } from '../caller/caller-resolution.service';
|
||||
import { LeadAutoAssignService } from '../leads/lead-auto-assign.service';
|
||||
import { SupervisorService } from '../supervisor/supervisor.service';
|
||||
|
||||
// Dedup window: any lead created for this phone within the last 24h is
|
||||
// considered the same visitor's lead — chat + book + contact by the same
|
||||
@@ -15,6 +17,7 @@ export type FindOrCreateLeadOpts = {
|
||||
source?: string;
|
||||
status?: string;
|
||||
interestedService?: string;
|
||||
createPatient?: boolean; // default false — only booking creates patients
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
@@ -27,6 +30,8 @@ export class WidgetService {
|
||||
private theme: ThemeService,
|
||||
private config: ConfigService,
|
||||
private caller: CallerResolutionService,
|
||||
private autoAssign: LeadAutoAssignService,
|
||||
private supervisor: SupervisorService,
|
||||
) {
|
||||
this.apiKey = config.get<string>('platform.apiKey') ?? '';
|
||||
}
|
||||
@@ -56,10 +61,10 @@ export class WidgetService {
|
||||
const lastName = name.split(' ').slice(1).join(' ') || '';
|
||||
|
||||
if (resolved.isNew) {
|
||||
// Net-new visitor — create Patient + Lead with the widget-
|
||||
// collected name. Both records get the real name from the
|
||||
// first moment they exist.
|
||||
// Net-new visitor — create Lead. Patient is only created
|
||||
// when explicitly requested (e.g., booking an appointment).
|
||||
let patientId: string | undefined;
|
||||
if (opts.createPatient) {
|
||||
try {
|
||||
const p = await this.platform.queryWithAuth<any>(
|
||||
`mutation($data: PatientCreateInput!) { createPatient(data: $data) { id } }`,
|
||||
@@ -77,6 +82,7 @@ export class WidgetService {
|
||||
} catch (err) {
|
||||
this.logger.warn(`Widget patient create failed (${phone}): ${err}`);
|
||||
}
|
||||
}
|
||||
const created = await this.platform.queryWithAuth<any>(
|
||||
`mutation($data: LeadCreateInput!) { createLead(data: $data) { id } }`,
|
||||
{
|
||||
@@ -259,6 +265,7 @@ export class WidgetService {
|
||||
source: 'WEBSITE',
|
||||
status: 'APPOINTMENT_SET',
|
||||
interestedService: req.chiefComplaint ?? 'Appointment Booking',
|
||||
createPatient: true,
|
||||
});
|
||||
// Idempotent upgrade: if the lead was reused from an earlier chat/
|
||||
// contact, promote its status and reflect the new interest.
|
||||
@@ -274,6 +281,13 @@ export class WidgetService {
|
||||
const reference = appt.createAppointment.id.substring(0, 8).toUpperCase();
|
||||
this.logger.log(`Widget booking: ${req.patientName} → ${req.doctorId} at ${req.scheduledAt} (ref: ${reference})`);
|
||||
|
||||
// Emit SSE so agents see the new appointment immediately
|
||||
this.supervisor.emitWorklistUpdate({
|
||||
type: 'widget-appointment',
|
||||
callerPhone: this.normalizePhone(req.patientPhone),
|
||||
callerName: req.patientName,
|
||||
});
|
||||
|
||||
return { appointmentId: appt.createAppointment.id, reference };
|
||||
}
|
||||
|
||||
@@ -284,6 +298,18 @@ export class WidgetService {
|
||||
interestedService: req.interest ?? 'Website Enquiry',
|
||||
});
|
||||
this.logger.log(`Widget contact: ${req.name} (${this.normalizePhone(req.phone)}) — ${req.interest ?? 'general'}`);
|
||||
|
||||
// Trigger immediate auto-assign + SSE so agent sees the lead instantly
|
||||
this.autoAssign.runOnce().then((result) => {
|
||||
if (result.assigned > 0) {
|
||||
this.supervisor.emitWorklistUpdate({
|
||||
type: 'widget-lead',
|
||||
callerPhone: this.normalizePhone(req.phone),
|
||||
callerName: req.name,
|
||||
});
|
||||
}
|
||||
}).catch(() => {});
|
||||
|
||||
return { leadId };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["node_modules", "test", "dist", "widget-src", "public", "data", "**/*spec.ts"]
|
||||
"exclude": ["node_modules", "test", "dist", "widget-src", "packages", "public", "data", "**/*spec.ts"]
|
||||
}
|
||||
|
||||
@@ -22,5 +22,5 @@
|
||||
"strictBindCallApply": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"exclude": ["widget-src", "public", "data"]
|
||||
"exclude": ["widget-src", "packages", "public", "data"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user