Skip to content

Commit 09e422e

Browse files
committed
✨ new route for call logging with entities
1 parent c6d1ea2 commit 09e422e

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ export function start(
6969
app.post("/events/calls", (req, res, next) =>
7070
controller.handleCallEvent(req, res, next)
7171
);
72+
app.post("/call-log", (req, res, next) =>
73+
controller.createCallLogForEntities(req, res, next)
74+
);
7275
app.put("/events/calls/:id", (req, res, next) =>
7376
controller.updateCallEvent(req, res, next)
7477
);

src/models/adapter.model.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import {
44
CalendarEventTemplate,
55
CalendarFilterOptions,
66
CallEvent,
7+
CallEventWithIntegrationEntities,
78
Config,
89
Contact,
910
ContactTemplate,
1011
ContactUpdate,
1112
LabeledIntegrationEntity,
13+
LoggedIntegrationEntity,
1214
} from ".";
1315
import { IntegrationEntityType } from "./integration-entity.model";
1416

@@ -45,6 +47,10 @@ export interface Adapter {
4547
) => Promise<void>;
4648
deleteCalendarEvent?: (config: Config, id: string) => Promise<void>;
4749
handleCallEvent?: (config: Config, event: CallEvent) => Promise<string>;
50+
createCallLogsForEntities?: (
51+
config: Config,
52+
event: CallEventWithIntegrationEntities
53+
) => Promise<LoggedIntegrationEntity[]>;
4854
getEntity?: (
4955
providerConfig: Config,
5056
id: string,

src/models/call-event.model.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CallDirection } from "./";
1+
import { CallDirection, IntegrationEntity } from "./";
22

33
/**
44
* The type of the call participant.
@@ -33,6 +33,10 @@ export interface CallEvent {
3333
state: CallState;
3434
}
3535

36+
export interface CallEventWithIntegrationEntities extends CallEvent {
37+
integrationEntities: IntegrationEntity[];
38+
}
39+
3640
export interface UpdateCallEventBody {
3741
note: string;
3842
}

src/models/controller.model.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
CalendarEvent,
77
CalendarEventTemplate,
88
CallEvent,
9+
CallEventWithIntegrationEntities,
910
Contact,
1011
ContactCache,
1112
ContactTemplate,
@@ -531,6 +532,47 @@ export class Controller {
531532
}
532533
}
533534

535+
public async createCallLogForEntities(
536+
req: BridgeRequest<CallEventWithIntegrationEntities>,
537+
res: Response,
538+
next: NextFunction
539+
): Promise<void> {
540+
const { providerConfig } = req;
541+
542+
try {
543+
if (!providerConfig) {
544+
throw new ServerError(400, "Missing config parameters");
545+
}
546+
547+
if (!this.adapter.createCallLogsForEntities) {
548+
throw new ServerError(501, "Creating call log is not implemented");
549+
}
550+
551+
if (shouldSkipCallEvent(req.body)) {
552+
infoLogger(
553+
`Skipping call log for call id ${req.body.id}`,
554+
providerConfig
555+
);
556+
res.status(200).send("Skipping call log");
557+
return;
558+
}
559+
560+
infoLogger(`Creating call Logs…`, providerConfig);
561+
562+
const entitiesWithCallLogReferences =
563+
await this.adapter.createCallLogsForEntities(providerConfig, req.body);
564+
565+
res.status(200).send(entitiesWithCallLogReferences);
566+
} catch (error) {
567+
errorLogger(
568+
"Could not create call logs:",
569+
providerConfig,
570+
error || "Unknown"
571+
);
572+
next(error);
573+
}
574+
}
575+
534576
public async handleConnectedEvent(
535577
req: BridgeRequest<unknown>,
536578
res: Response,

0 commit comments

Comments
 (0)