Skip to content

Commit 8cd103f

Browse files
committed
✨ add getCommentTitle, getCommentContent and getCallDuration
1 parent 7c2686d commit 8cd103f

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"cors": "^2.8.5",
7272
"express": "^4.18.1",
7373
"lru-cache": "^7.13.1",
74+
"moment": "^2.29.4",
7475
"redis": "^4.2.0"
7576
}
7677
}

src/util/call-comment.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { CallDirection, CallState } from "../models";
2+
import moment from "moment";
3+
4+
export function getCommentTitle(
5+
state: CallState,
6+
direction: CallDirection,
7+
locale: string,
8+
htmlOpen = "",
9+
htmlClose = ""
10+
) {
11+
const isGerman = locale.startsWith("de");
12+
const isIncoming = direction == CallDirection.IN;
13+
const directionString = isGerman
14+
? isIncoming
15+
? "eingehender"
16+
: "ausgehender"
17+
: isIncoming
18+
? "incoming"
19+
: "outgoing";
20+
21+
const titleEndGerman = `${directionString} Anruf (CLINQ)`;
22+
const titleEndEnglish = `${directionString} Call (CLINQ)`;
23+
24+
switch (state) {
25+
case CallState.CONNECTED:
26+
return isGerman
27+
? `${htmlOpen}Getätigter ${titleEndGerman}${htmlClose}`
28+
: `${htmlOpen}Connected ${titleEndEnglish}${htmlClose}`;
29+
case CallState.BUSY:
30+
return isGerman
31+
? `${htmlOpen}Nicht angenommener ${titleEndGerman}${htmlClose}`
32+
: `${htmlOpen}Busy ${titleEndEnglish}${htmlClose}`;
33+
case CallState.MISSED:
34+
return isGerman
35+
? `${htmlOpen}Verpasster ${titleEndGerman}${htmlClose}`
36+
: `${htmlOpen}Missed ${titleEndEnglish}${htmlClose}`;
37+
default:
38+
return isGerman
39+
? `${htmlOpen}Getätigter ${titleEndGerman}${htmlClose}`
40+
: `${htmlOpen}Connected ${titleEndEnglish}${htmlClose}`;
41+
}
42+
}
43+
44+
function createCallEventCommentHeader(locale: string) {
45+
const isGerman = locale.startsWith("de");
46+
return `<h1>${isGerman ? "Notizen" : "Note"} (CLINQ):</h1>`;
47+
}
48+
49+
export function getCommentContent(note: string, locale: string) {
50+
return `${createCallEventCommentHeader(locale)}${note}`;
51+
}
52+
53+
export function getCallDuration(
54+
startTime: number,
55+
endTime: number,
56+
locale: string
57+
) {
58+
const start = moment(startTime);
59+
const end = moment(endTime);
60+
61+
const diff = end.diff(start);
62+
63+
return `${locale.startsWith("de") ? "Dauer" : "Duration"}: ${moment
64+
.utc(diff)
65+
.format("HH:mm:ss")}`;
66+
}

src/util/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./phone-number-utils";
22
export * from "./anonymize-key";
33
export * from "./logger.util";
4+
export * from "./call-comment";

0 commit comments

Comments
 (0)