@twentyhq/call-recorder 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +5 -0
- package/.nvmrc +1 -0
- package/.oxlintrc.json +20 -0
- package/.yarnrc.yml +1 -0
- package/AGENTS.md +67 -0
- package/CLAUDE.md +67 -0
- package/README.md +24 -0
- package/SETUP.md +95 -0
- package/package.json +42 -0
- package/public/gallery/call-recorder-cover.png +0 -0
- package/public/logo.svg +5 -0
- package/src/__tests__/global-setup.ts +100 -0
- package/src/__tests__/schema.integration-test.ts +104 -0
- package/src/application-config.ts +96 -0
- package/src/constants/__tests__/call-recording-field-universal-identifiers.test.ts +19 -0
- package/src/constants/app-description.ts +2 -0
- package/src/constants/app-display-name.ts +1 -0
- package/src/constants/application-universal-identifier.ts +2 -0
- package/src/constants/calendar-event-reconciliation-logic-function-universal-identifier.ts +2 -0
- package/src/constants/calendar-event-record-page-layout-universal-identifier.ts +2 -0
- package/src/constants/calendar-event-recording-front-component-universal-identifier.ts +2 -0
- package/src/constants/calendar-event-recording-page-layout-tab-universal-identifier.ts +2 -0
- package/src/constants/calendar-event-recording-page-layout-widget-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-everyone-left-timeout-seconds-app-variable-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-failure-reason-on-call-recording-field-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-join-early-minutes-app-variable-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-name-app-variable-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-noone-joined-timeout-seconds-app-variable-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-preference-off-option-id.ts +2 -0
- package/src/constants/call-recorder-preference-on-calendar-event-field-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-preference-on-calendar-event-view-field-universal-identifier.ts +2 -0
- package/src/constants/call-recorder-preference-on-option-id.ts +2 -0
- package/src/constants/call-recorder-preference.ts +4 -0
- package/src/constants/call-recorder-waiting-room-timeout-seconds-app-variable-universal-identifier.ts +2 -0
- package/src/constants/call-recording-audio-field-universal-identifier.ts +2 -0
- package/src/constants/call-recording-video-field-universal-identifier.ts +2 -0
- package/src/constants/default-role-universal-identifier.ts +2 -0
- package/src/constants/process-recall-webhook-logic-function-universal-identifier.ts +2 -0
- package/src/constants/recall-webhook-logic-function-universal-identifier.ts +2 -0
- package/src/constants/stale-bot-state-logic-function-universal-identifier.ts +2 -0
- package/src/default-role.ts +69 -0
- package/src/fields/call-recorder-failure-reason-on-call-recording.field.ts +22 -0
- package/src/fields/call-recorder-preference-on-calendar-event.field.ts +41 -0
- package/src/front-components/calendar-event-recording.front-component.tsx +13 -0
- package/src/front-components/components/CalendarEventRecording.tsx +39 -0
- package/src/front-components/components/CalendarEventRecordingBody.tsx +96 -0
- package/src/front-components/components/CalendarEventRecordingContent.tsx +111 -0
- package/src/front-components/components/RecordingTranscript.tsx +92 -0
- package/src/front-components/components/RecordingVideoPlayer.tsx +52 -0
- package/src/front-components/components/TranscriptEntryList.tsx +61 -0
- package/src/front-components/components/TranscriptEntryListItem.tsx +115 -0
- package/src/front-components/components/TranscriptErrorBox.tsx +48 -0
- package/src/front-components/components/TranscriptSpeakerAvatar.tsx +141 -0
- package/src/front-components/components/TranscriptSpeakerChip.tsx +51 -0
- package/src/front-components/constants/recording-theme-css-variables.ts +40 -0
- package/src/front-components/hooks/use-calendar-event-participants.ts +172 -0
- package/src/front-components/hooks/use-calendar-event-recording.ts +155 -0
- package/src/front-components/types/calendar-event-participant-by-speaker-name.type.ts +6 -0
- package/src/front-components/types/calendar-event-recording-participant.type.ts +7 -0
- package/src/front-components/types/transcript-entry.type.ts +13 -0
- package/src/front-components/utils/__tests__/find-active-transcript-entry-index.test.ts +66 -0
- package/src/front-components/utils/__tests__/format-transcript-timestamp.test.ts +29 -0
- package/src/front-components/utils/__tests__/get-speaker-name-match-keys.test.ts +22 -0
- package/src/front-components/utils/__tests__/parse-transcript-entries.test.ts +162 -0
- package/src/front-components/utils/build-calendar-event-participant-by-speaker-name.util.ts +45 -0
- package/src/front-components/utils/find-active-transcript-entry-index.util.ts +77 -0
- package/src/front-components/utils/format-transcript-timestamp.util.ts +16 -0
- package/src/front-components/utils/get-absolute-avatar-url.util.ts +48 -0
- package/src/front-components/utils/get-calendar-event-participant-for-speaker-name.util.ts +24 -0
- package/src/front-components/utils/get-speaker-name-match-keys.util.ts +64 -0
- package/src/front-components/utils/get-video-file-extension.util.ts +23 -0
- package/src/front-components/utils/parse-transcript-entries.util.ts +85 -0
- package/src/logic-functions/__tests__/process-recall-webhook.test.ts +62 -0
- package/src/logic-functions/__tests__/recall-webhook.test.ts +180 -0
- package/src/logic-functions/constants/call-recorder-everyone-left-timeout-seconds-env-var-name.ts +2 -0
- package/src/logic-functions/constants/call-recorder-everyone-left-timeout-seconds.ts +1 -0
- package/src/logic-functions/constants/call-recorder-join-early-minutes-env-var-name.ts +2 -0
- package/src/logic-functions/constants/call-recorder-name-env-var-name.ts +1 -0
- package/src/logic-functions/constants/call-recorder-noone-joined-timeout-seconds-env-var-name.ts +2 -0
- package/src/logic-functions/constants/call-recorder-noone-joined-timeout-seconds.ts +1 -0
- package/src/logic-functions/constants/call-recorder-recording-retention-hours-env-var-name.ts +2 -0
- package/src/logic-functions/constants/call-recorder-waiting-room-timeout-seconds-env-var-name.ts +2 -0
- package/src/logic-functions/constants/call-recorder-waiting-room-timeout-seconds.ts +1 -0
- package/src/logic-functions/constants/call-recording-micro-credits-per-hour.ts +1 -0
- package/src/logic-functions/constants/call-recording-request-status.ts +5 -0
- package/src/logic-functions/constants/call-recording-status.ts +9 -0
- package/src/logic-functions/constants/default-call-recorder-join-early-minutes.ts +1 -0
- package/src/logic-functions/constants/default-call-recorder-name.ts +1 -0
- package/src/logic-functions/constants/default-call-recorder-recording-retention-hours.ts +2 -0
- package/src/logic-functions/constants/default-recall-region.ts +1 -0
- package/src/logic-functions/constants/milliseconds-per-minute.ts +1 -0
- package/src/logic-functions/constants/non-terminal-call-recording-statuses.ts +8 -0
- package/src/logic-functions/constants/recall-api-key-env-var-name.ts +1 -0
- package/src/logic-functions/constants/recall-api-max-attempts.ts +1 -0
- package/src/logic-functions/constants/recall-api-retry-delay-ms.ts +1 -0
- package/src/logic-functions/constants/recall-bot-automatic-leave.ts +74 -0
- package/src/logic-functions/constants/recall-bot-everyone-left-min-activate-after-seconds.ts +1 -0
- package/src/logic-functions/constants/recall-bot-recording-config.ts +34 -0
- package/src/logic-functions/constants/recall-region-env-var-name.ts +1 -0
- package/src/logic-functions/constants/recall-webhook-secret-env-var-name.ts +1 -0
- package/src/logic-functions/constants/restricted-field-placeholder.ts +3 -0
- package/src/logic-functions/constants/stale-bot-state-cron-pattern.ts +1 -0
- package/src/logic-functions/constants/twenty-page-size.ts +1 -0
- package/src/logic-functions/data/__tests__/complete-call-recording-ingestion.test.ts +55 -0
- package/src/logic-functions/data/__tests__/fetch-all-nodes.test.ts +43 -0
- package/src/logic-functions/data/__tests__/get-current-workspace-id.test.ts +38 -0
- package/src/logic-functions/data/__tests__/strip-restricted-field-value.test.ts +22 -0
- package/src/logic-functions/data/complete-call-recording-ingestion.util.ts +24 -0
- package/src/logic-functions/data/create-call-recording.util.ts +41 -0
- package/src/logic-functions/data/fetch-all-nodes.util.ts +44 -0
- package/src/logic-functions/data/fetch-calendar-events-by-filter.util.ts +80 -0
- package/src/logic-functions/data/fetch-calendar-events-by-ids.util.ts +20 -0
- package/src/logic-functions/data/fetch-calendar-events-by-starts-at-values.util.ts +19 -0
- package/src/logic-functions/data/find-call-recordings-by-calendar-event-ids.util.ts +17 -0
- package/src/logic-functions/data/find-call-recordings-by-filter.util.ts +102 -0
- package/src/logic-functions/data/find-call-recordings-by-ids.util.ts +17 -0
- package/src/logic-functions/data/find-open-scheduled-call-recordings.util.ts +14 -0
- package/src/logic-functions/data/get-current-workspace-id.util.ts +36 -0
- package/src/logic-functions/data/strip-restricted-field-value.util.ts +6 -0
- package/src/logic-functions/data/update-call-recording.util.ts +24 -0
- package/src/logic-functions/domain/__tests__/build-call-recorder-policy-result.test.ts +47 -0
- package/src/logic-functions/domain/__tests__/compute-call-recording-charge.test.ts +71 -0
- package/src/logic-functions/domain/__tests__/compute-call-recording-id-for-meeting.test.ts +37 -0
- package/src/logic-functions/domain/__tests__/compute-real-meeting-key.test.ts +88 -0
- package/src/logic-functions/domain/__tests__/is-call-recording-ingestion-complete.test.ts +59 -0
- package/src/logic-functions/domain/__tests__/is-call-recording-status-downgrade.test.ts +37 -0
- package/src/logic-functions/domain/__tests__/resolve-call-recorder-policy-result.test.ts +120 -0
- package/src/logic-functions/domain/__tests__/should-complete-call-recording-ingestion.test.ts +102 -0
- package/src/logic-functions/domain/aggregate-call-recorder-policy-results-by-meeting.util.ts +42 -0
- package/src/logic-functions/domain/build-call-recorder-policy-result.util.ts +53 -0
- package/src/logic-functions/domain/build-failed-transcript-marker.util.ts +13 -0
- package/src/logic-functions/domain/build-pending-transcript-marker.util.ts +13 -0
- package/src/logic-functions/domain/build-recall-routing-metadata.util.ts +12 -0
- package/src/logic-functions/domain/build-transcript-failure-reason.util.ts +7 -0
- package/src/logic-functions/domain/compute-call-recording-charge.util.ts +41 -0
- package/src/logic-functions/domain/compute-call-recording-id-for-meeting.util.ts +16 -0
- package/src/logic-functions/domain/compute-real-meeting-key.util.ts +48 -0
- package/src/logic-functions/domain/compute-recall-bot-join-at.util.ts +34 -0
- package/src/logic-functions/domain/is-call-recording-ingestion-complete.util.ts +19 -0
- package/src/logic-functions/domain/is-call-recording-status-downgrade.util.ts +37 -0
- package/src/logic-functions/domain/is-recall-recording-done-signal.util.ts +13 -0
- package/src/logic-functions/domain/map-recall-status-code-to-call-recording-status.util.ts +26 -0
- package/src/logic-functions/domain/parse-transcript-marker.util.ts +29 -0
- package/src/logic-functions/domain/resolve-call-recorder-policy-result.util.ts +72 -0
- package/src/logic-functions/domain/should-complete-call-recording-ingestion.util.ts +32 -0
- package/src/logic-functions/flows/__tests__/charge-completed-call-recording.test.ts +45 -0
- package/src/logic-functions/flows/__tests__/complete-and-charge-call-recording.test.ts +61 -0
- package/src/logic-functions/flows/__tests__/converge-diverged-call-recordings.test.ts +727 -0
- package/src/logic-functions/flows/__tests__/download-transcript.test.ts +74 -0
- package/src/logic-functions/flows/__tests__/handle-recall-webhook.test.ts +1301 -0
- package/src/logic-functions/flows/__tests__/heal-call-recordings-missing-bot.test.ts +225 -0
- package/src/logic-functions/flows/__tests__/ingest-call-recording-media.test.ts +153 -0
- package/src/logic-functions/flows/__tests__/reap-orphaned-call-recorders.test.ts +425 -0
- package/src/logic-functions/flows/__tests__/reconcile-call-recorder.test.ts +1007 -0
- package/src/logic-functions/flows/cancel-call-recording-request.util.ts +46 -0
- package/src/logic-functions/flows/charge-completed-call-recording.util.ts +31 -0
- package/src/logic-functions/flows/complete-and-charge-call-recording.util.ts +29 -0
- package/src/logic-functions/flows/converge-diverged-call-recordings-result.type.ts +8 -0
- package/src/logic-functions/flows/converge-diverged-call-recordings.util.ts +447 -0
- package/src/logic-functions/flows/download-transcript.util.ts +67 -0
- package/src/logic-functions/flows/ensure-call-recorder.util.ts +73 -0
- package/src/logic-functions/flows/handle-recall-webhook.util.ts +672 -0
- package/src/logic-functions/flows/heal-call-recordings-missing-bot.util.ts +82 -0
- package/src/logic-functions/flows/ingest-call-recording-media.util.ts +128 -0
- package/src/logic-functions/flows/persist-call-recording-progress.util.ts +58 -0
- package/src/logic-functions/flows/reap-orphaned-call-recorders.util.ts +183 -0
- package/src/logic-functions/flows/reconcile-call-recorder.util.ts +495 -0
- package/src/logic-functions/flows/reconcile-call-recording-transcript-artifact-result.type.ts +11 -0
- package/src/logic-functions/flows/reconcile-call-recording-transcript-artifact.util.ts +182 -0
- package/src/logic-functions/flows/reschedule-call-recording-bot.util.ts +69 -0
- package/src/logic-functions/process-recall-webhook.ts +23 -0
- package/src/logic-functions/recall-api/__tests__/extract-recall-bot-convergence.test.ts +153 -0
- package/src/logic-functions/recall-api/__tests__/extract-recall-media-urls.test.ts +67 -0
- package/src/logic-functions/recall-api/__tests__/recall-bot-api.test.ts +744 -0
- package/src/logic-functions/recall-api/__tests__/verify-recall-webhook-signature.test.ts +122 -0
- package/src/logic-functions/recall-api/cancel-recall-bot.util.ts +28 -0
- package/src/logic-functions/recall-api/create-async-recall-transcript.util.ts +47 -0
- package/src/logic-functions/recall-api/eject-recall-bot.util.ts +28 -0
- package/src/logic-functions/recall-api/extract-recall-bot-convergence.util.ts +149 -0
- package/src/logic-functions/recall-api/extract-recall-bot-id.util.ts +10 -0
- package/src/logic-functions/recall-api/extract-recall-media-urls.util.ts +30 -0
- package/src/logic-functions/recall-api/extract-twenty-workspace-id-from-recall-webhook.util.ts +8 -0
- package/src/logic-functions/recall-api/get-recall-api-config.util.ts +59 -0
- package/src/logic-functions/recall-api/get-recall-bot.util.ts +42 -0
- package/src/logic-functions/recall-api/get-recall-recording.util.ts +31 -0
- package/src/logic-functions/recall-api/get-recall-webhook-bot-metadata.util.ts +18 -0
- package/src/logic-functions/recall-api/list-recall-transcripts.util.ts +141 -0
- package/src/logic-functions/recall-api/list-scheduled-recall-bots.util.ts +106 -0
- package/src/logic-functions/recall-api/normalize-recall-timestamp.util.ts +14 -0
- package/src/logic-functions/recall-api/parse-recall-webhook-event.util.ts +88 -0
- package/src/logic-functions/recall-api/recall-bot-api-request.util.ts +165 -0
- package/src/logic-functions/recall-api/recall-transcript-summary.type.ts +5 -0
- package/src/logic-functions/recall-api/reschedule-recall-bot.util.ts +56 -0
- package/src/logic-functions/recall-api/retrieve-recall-transcript.util.ts +71 -0
- package/src/logic-functions/recall-api/schedule-recall-bot.util.ts +68 -0
- package/src/logic-functions/recall-api/verify-recall-webhook-signature.util.ts +109 -0
- package/src/logic-functions/recall-webhook.ts +90 -0
- package/src/logic-functions/reconcile-call-recorder-calendar-event.ts +178 -0
- package/src/logic-functions/reconcile-stale-bot-state.ts +106 -0
- package/src/logic-functions/types/calendar-event-record.type.ts +5 -0
- package/src/logic-functions/types/call-recorder-policy-calendar-event-input.type.ts +10 -0
- package/src/logic-functions/types/call-recorder-policy-input.type.ts +9 -0
- package/src/logic-functions/types/call-recorder-policy-not-required-reason.type.ts +5 -0
- package/src/logic-functions/types/call-recorder-policy-required-reason.type.ts +1 -0
- package/src/logic-functions/types/call-recorder-policy-result-for-calendar-event.type.ts +9 -0
- package/src/logic-functions/types/call-recorder-policy-result-for-meeting.type.ts +6 -0
- package/src/logic-functions/types/call-recorder-policy-result.type.ts +12 -0
- package/src/logic-functions/types/call-recorder-reconciliation-result.type.ts +16 -0
- package/src/logic-functions/types/call-recording-media-file.type.ts +1 -0
- package/src/logic-functions/types/call-recording-record.type.ts +15 -0
- package/src/logic-functions/types/call-recording-update-fields.type.ts +20 -0
- package/src/logic-functions/types/files-field-value.type.ts +1 -0
- package/src/logic-functions/types/meeting-recording.type.ts +7 -0
- package/src/logic-functions/types/recall-bot-operation-result.type.ts +19 -0
- package/src/logic-functions/types/recall-routing-metadata.type.ts +4 -0
- package/src/logic-functions/types/removed-call-recorder-occurrence.type.ts +6 -0
- package/src/logic-functions/types/transcript-marker.type.ts +6 -0
- package/src/logic-functions/utils/as-record.util.ts +6 -0
- package/src/logic-functions/utils/get-application-variable-value.util.ts +3 -0
- package/src/logic-functions/utils/get-record-at-path.util.ts +10 -0
- package/src/logic-functions/utils/get-string.util.ts +4 -0
- package/src/logic-functions/utils/get-unique-sorted-ids.util.ts +8 -0
- package/src/logic-functions/utils/is-non-empty-string.util.ts +5 -0
- package/src/page-layouts/calendar-event-recording-tab.ts +33 -0
- package/src/view-fields/call-recorder-preference-on-calendar-event.view-field.ts +27 -0
- package/tsconfig.json +42 -0
- package/tsconfig.spec.json +9 -0
- package/vitest.config.ts +31 -0
- package/vitest.unit.config.ts +14 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { type CoreApiClient } from 'twenty-client-sdk/core';
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { healCallRecordingsMissingBot } from 'src/logic-functions/flows/heal-call-recordings-missing-bot.util';
|
|
5
|
+
|
|
6
|
+
const scheduleRecallBotMock = vi.hoisted(() => vi.fn());
|
|
7
|
+
const getCurrentWorkspaceIdMock = vi.hoisted(() => vi.fn());
|
|
8
|
+
|
|
9
|
+
vi.mock('src/logic-functions/data/get-current-workspace-id.util', () => ({
|
|
10
|
+
getCurrentWorkspaceId: getCurrentWorkspaceIdMock,
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
vi.mock('src/logic-functions/recall-api/schedule-recall-bot.util', () => ({
|
|
14
|
+
scheduleRecallBot: scheduleRecallBotMock,
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
const NOW = new Date('2026-01-01T12:00:00.000Z');
|
|
18
|
+
const WORKSPACE_ID = '123e4567-e89b-12d3-a456-426614174000';
|
|
19
|
+
const UPCOMING_STARTS_AT = '2026-01-01T13:00:00.000Z';
|
|
20
|
+
const UPCOMING_ENDS_AT = '2026-01-01T14:00:00.000Z';
|
|
21
|
+
const PAST_STARTS_AT = '2026-01-01T10:00:00.000Z';
|
|
22
|
+
const PAST_ENDS_AT = '2026-01-01T11:00:00.000Z';
|
|
23
|
+
|
|
24
|
+
type CallRecordingNode = {
|
|
25
|
+
id: string;
|
|
26
|
+
status?: string;
|
|
27
|
+
recordingRequestStatus?: string | null;
|
|
28
|
+
calendarEventId?: string | null;
|
|
29
|
+
externalBotId?: string | null;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type CalendarEventNode = {
|
|
33
|
+
id: string;
|
|
34
|
+
startsAt?: string | null;
|
|
35
|
+
endsAt?: string | null;
|
|
36
|
+
iCalUid?: string | null;
|
|
37
|
+
conferenceLink?: { primaryLinkUrl?: string | null } | null;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
class FakeCoreApiClient {
|
|
41
|
+
callRecordings: CallRecordingNode[];
|
|
42
|
+
calendarEvents: CalendarEventNode[];
|
|
43
|
+
|
|
44
|
+
constructor({
|
|
45
|
+
callRecordings = [],
|
|
46
|
+
calendarEvents = [],
|
|
47
|
+
}: {
|
|
48
|
+
callRecordings?: CallRecordingNode[];
|
|
49
|
+
calendarEvents?: CalendarEventNode[];
|
|
50
|
+
}) {
|
|
51
|
+
this.callRecordings = callRecordings;
|
|
52
|
+
this.calendarEvents = calendarEvents;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async query(query: any): Promise<any> {
|
|
56
|
+
if (query.callRecordings !== undefined) {
|
|
57
|
+
const filter = query.callRecordings.__args.filter;
|
|
58
|
+
const matches =
|
|
59
|
+
filter.id?.in !== undefined
|
|
60
|
+
? this.callRecordings.filter((callRecording) =>
|
|
61
|
+
filter.id.in.includes(callRecording.id),
|
|
62
|
+
)
|
|
63
|
+
: this.callRecordings.filter(
|
|
64
|
+
(callRecording) =>
|
|
65
|
+
callRecording.recordingRequestStatus ===
|
|
66
|
+
filter.recordingRequestStatus.eq &&
|
|
67
|
+
callRecording.status === filter.status.eq,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return { callRecordings: buildConnection(matches) };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (query.calendarEvents !== undefined) {
|
|
74
|
+
const calendarEventIds = query.calendarEvents.__args.filter.id.in;
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
calendarEvents: buildConnection(
|
|
78
|
+
this.calendarEvents.filter((calendarEvent) =>
|
|
79
|
+
calendarEventIds.includes(calendarEvent.id),
|
|
80
|
+
),
|
|
81
|
+
),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
throw new Error(`Unhandled query: ${JSON.stringify(query)}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async mutation(mutation: any): Promise<any> {
|
|
89
|
+
if (mutation.updateCallRecording !== undefined) {
|
|
90
|
+
const { id, data } = mutation.updateCallRecording.__args;
|
|
91
|
+
const callRecording = this.callRecordings.find(
|
|
92
|
+
(candidate) => candidate.id === id,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
if (callRecording !== undefined) {
|
|
96
|
+
Object.assign(callRecording, data);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return { updateCallRecording: { id } };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
throw new Error(`Unhandled mutation: ${JSON.stringify(mutation)}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const buildConnection = <Node>(nodes: Node[]) => ({
|
|
107
|
+
pageInfo: { hasNextPage: false, endCursor: undefined },
|
|
108
|
+
edges: nodes.map((node) => ({ node })),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const buildBotlessCallRecording = (
|
|
112
|
+
overrides: Partial<CallRecordingNode> = {},
|
|
113
|
+
): CallRecordingNode => ({
|
|
114
|
+
id: 'call-recording-1',
|
|
115
|
+
status: 'SCHEDULED',
|
|
116
|
+
recordingRequestStatus: 'REQUESTED',
|
|
117
|
+
calendarEventId: 'calendar-event-1',
|
|
118
|
+
externalBotId: null,
|
|
119
|
+
...overrides,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const buildCalendarEvent = (
|
|
123
|
+
overrides: Partial<CalendarEventNode> = {},
|
|
124
|
+
): CalendarEventNode => ({
|
|
125
|
+
id: 'calendar-event-1',
|
|
126
|
+
startsAt: UPCOMING_STARTS_AT,
|
|
127
|
+
endsAt: UPCOMING_ENDS_AT,
|
|
128
|
+
iCalUid: 'calendar-event-uid',
|
|
129
|
+
conferenceLink: { primaryLinkUrl: 'https://meet.example.com/customer-sync' },
|
|
130
|
+
...overrides,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('healCallRecordingsMissingBot', () => {
|
|
134
|
+
beforeEach(() => {
|
|
135
|
+
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
136
|
+
getCurrentWorkspaceIdMock.mockReset();
|
|
137
|
+
getCurrentWorkspaceIdMock.mockReturnValue(WORKSPACE_ID);
|
|
138
|
+
scheduleRecallBotMock.mockReset();
|
|
139
|
+
scheduleRecallBotMock.mockResolvedValue({
|
|
140
|
+
ok: true,
|
|
141
|
+
externalBotId: 'recall-bot-1',
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('schedules a bot and writes the id for an upcoming botless recording', async () => {
|
|
146
|
+
const client = new FakeCoreApiClient({
|
|
147
|
+
callRecordings: [buildBotlessCallRecording()],
|
|
148
|
+
calendarEvents: [buildCalendarEvent()],
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const result = await healCallRecordingsMissingBot({
|
|
152
|
+
client: client as unknown as CoreApiClient,
|
|
153
|
+
now: NOW,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
expect(result.scheduledCallRecordingIds).toEqual(['call-recording-1']);
|
|
157
|
+
expect(scheduleRecallBotMock).toHaveBeenCalledTimes(1);
|
|
158
|
+
expect(scheduleRecallBotMock).toHaveBeenCalledWith(
|
|
159
|
+
expect.objectContaining({
|
|
160
|
+
metadata: expect.objectContaining({
|
|
161
|
+
twentyWorkspaceId: WORKSPACE_ID,
|
|
162
|
+
}),
|
|
163
|
+
}),
|
|
164
|
+
);
|
|
165
|
+
expect(client.callRecordings[0].externalBotId).toBe('recall-bot-1');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('does not report a recording as scheduled when Recall scheduling fails', async () => {
|
|
169
|
+
scheduleRecallBotMock.mockResolvedValue({
|
|
170
|
+
ok: false,
|
|
171
|
+
status: 500,
|
|
172
|
+
errorMessage: 'Recall API responded with HTTP 500',
|
|
173
|
+
});
|
|
174
|
+
const client = new FakeCoreApiClient({
|
|
175
|
+
callRecordings: [buildBotlessCallRecording()],
|
|
176
|
+
calendarEvents: [buildCalendarEvent()],
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const result = await healCallRecordingsMissingBot({
|
|
180
|
+
client: client as unknown as CoreApiClient,
|
|
181
|
+
now: NOW,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
expect(result.scheduledCallRecordingIds).toEqual([]);
|
|
185
|
+
expect(scheduleRecallBotMock).toHaveBeenCalledTimes(1);
|
|
186
|
+
expect(client.callRecordings[0].externalBotId).toBeNull();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('skips a recording whose meeting has already ended', async () => {
|
|
190
|
+
const client = new FakeCoreApiClient({
|
|
191
|
+
callRecordings: [buildBotlessCallRecording()],
|
|
192
|
+
calendarEvents: [
|
|
193
|
+
buildCalendarEvent({
|
|
194
|
+
startsAt: PAST_STARTS_AT,
|
|
195
|
+
endsAt: PAST_ENDS_AT,
|
|
196
|
+
}),
|
|
197
|
+
],
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const result = await healCallRecordingsMissingBot({
|
|
201
|
+
client: client as unknown as CoreApiClient,
|
|
202
|
+
now: NOW,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
expect(result.scheduledCallRecordingIds).toEqual([]);
|
|
206
|
+
expect(scheduleRecallBotMock).not.toHaveBeenCalled();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('does nothing when every scheduled recording already has a bot', async () => {
|
|
210
|
+
const client = new FakeCoreApiClient({
|
|
211
|
+
callRecordings: [
|
|
212
|
+
buildBotlessCallRecording({ externalBotId: 'recall-bot-existing' }),
|
|
213
|
+
],
|
|
214
|
+
calendarEvents: [buildCalendarEvent()],
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const result = await healCallRecordingsMissingBot({
|
|
218
|
+
client: client as unknown as CoreApiClient,
|
|
219
|
+
now: NOW,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
expect(result.scheduledCallRecordingIds).toEqual([]);
|
|
223
|
+
expect(scheduleRecallBotMock).not.toHaveBeenCalled();
|
|
224
|
+
});
|
|
225
|
+
});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { ingestCallRecordingMedia } from 'src/logic-functions/flows/ingest-call-recording-media.util';
|
|
4
|
+
|
|
5
|
+
const uploadFileMock = vi.hoisted(() => vi.fn());
|
|
6
|
+
const getRecallRecordingMock = vi.hoisted(() => vi.fn());
|
|
7
|
+
|
|
8
|
+
vi.mock('twenty-client-sdk/metadata', () => ({
|
|
9
|
+
MetadataApiClient: class {
|
|
10
|
+
uploadFile = uploadFileMock;
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
vi.mock('src/logic-functions/recall-api/get-recall-recording.util', () => ({
|
|
15
|
+
getRecallRecording: getRecallRecordingMock,
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
const RECORDING_WITH_MEDIA = {
|
|
19
|
+
id: 'recall-recording-1',
|
|
20
|
+
media_shortcuts: {
|
|
21
|
+
video_mixed: { download_url: 'https://media.example.com/video.mp4' },
|
|
22
|
+
audio_mixed: { download_url: 'https://media.example.com/audio.mp3' },
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const buildFetchResponse = () => ({
|
|
27
|
+
ok: true,
|
|
28
|
+
headers: { get: () => 'video/mp4' },
|
|
29
|
+
arrayBuffer: async () => new ArrayBuffer(8),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('ingestCallRecordingMedia', () => {
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
35
|
+
uploadFileMock.mockReset();
|
|
36
|
+
getRecallRecordingMock.mockReset();
|
|
37
|
+
getRecallRecordingMock.mockResolvedValue({
|
|
38
|
+
ok: true,
|
|
39
|
+
recording: RECORDING_WITH_MEDIA,
|
|
40
|
+
});
|
|
41
|
+
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(buildFetchResponse()));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
afterEach(() => {
|
|
45
|
+
vi.unstubAllGlobals();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('downloads and uploads every missing artifact', async () => {
|
|
49
|
+
uploadFileMock
|
|
50
|
+
.mockResolvedValueOnce({ id: 'file-video-1' })
|
|
51
|
+
.mockResolvedValueOnce({ id: 'file-audio-1' });
|
|
52
|
+
|
|
53
|
+
const updateFields = await ingestCallRecordingMedia({
|
|
54
|
+
callRecordingId: 'call-recording-1',
|
|
55
|
+
externalRecordingId: 'recall-recording-1',
|
|
56
|
+
hasAudio: false,
|
|
57
|
+
hasVideo: false,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(updateFields).toEqual({
|
|
61
|
+
video: [{ fileId: 'file-video-1', label: 'video.mp4' }],
|
|
62
|
+
audio: [{ fileId: 'file-audio-1', label: 'audio.mp3' }],
|
|
63
|
+
});
|
|
64
|
+
expect(uploadFileMock).toHaveBeenCalledTimes(2);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('skips artifacts already on the record', async () => {
|
|
68
|
+
uploadFileMock.mockResolvedValue({ id: 'file-audio-1' });
|
|
69
|
+
|
|
70
|
+
const updateFields = await ingestCallRecordingMedia({
|
|
71
|
+
callRecordingId: 'call-recording-1',
|
|
72
|
+
externalRecordingId: 'recall-recording-1',
|
|
73
|
+
hasAudio: false,
|
|
74
|
+
hasVideo: true,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
expect(updateFields).toEqual({
|
|
78
|
+
audio: [{ fileId: 'file-audio-1', label: 'audio.mp3' }],
|
|
79
|
+
});
|
|
80
|
+
expect(uploadFileMock).toHaveBeenCalledTimes(1);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('does not fetch the recording when both artifacts are present', async () => {
|
|
84
|
+
const updateFields = await ingestCallRecordingMedia({
|
|
85
|
+
callRecordingId: 'call-recording-1',
|
|
86
|
+
externalRecordingId: 'recall-recording-1',
|
|
87
|
+
hasAudio: true,
|
|
88
|
+
hasVideo: true,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(updateFields).toEqual({});
|
|
92
|
+
expect(getRecallRecordingMock).not.toHaveBeenCalled();
|
|
93
|
+
expect(uploadFileMock).not.toHaveBeenCalled();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('omits an artifact and warns when its transfer fails', async () => {
|
|
97
|
+
uploadFileMock.mockRejectedValueOnce(new Error('upload exploded'));
|
|
98
|
+
uploadFileMock.mockResolvedValueOnce({ id: 'file-audio-1' });
|
|
99
|
+
|
|
100
|
+
const updateFields = await ingestCallRecordingMedia({
|
|
101
|
+
callRecordingId: 'call-recording-1',
|
|
102
|
+
externalRecordingId: 'recall-recording-1',
|
|
103
|
+
hasAudio: false,
|
|
104
|
+
hasVideo: false,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(updateFields).toEqual({
|
|
108
|
+
audio: [{ fileId: 'file-audio-1', label: 'audio.mp3' }],
|
|
109
|
+
});
|
|
110
|
+
expect(Object.keys(updateFields)).toEqual(['audio']);
|
|
111
|
+
expect(console.warn).toHaveBeenCalledWith(
|
|
112
|
+
expect.stringContaining('upload exploded'),
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('returns nothing when the recording exposes no media urls', async () => {
|
|
117
|
+
getRecallRecordingMock.mockResolvedValue({
|
|
118
|
+
ok: true,
|
|
119
|
+
recording: { id: 'recall-recording-1' },
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const updateFields = await ingestCallRecordingMedia({
|
|
123
|
+
callRecordingId: 'call-recording-1',
|
|
124
|
+
externalRecordingId: 'recall-recording-1',
|
|
125
|
+
hasAudio: false,
|
|
126
|
+
hasVideo: false,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(updateFields).toEqual({});
|
|
130
|
+
expect(uploadFileMock).not.toHaveBeenCalled();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('warns and returns nothing when the recording fetch fails', async () => {
|
|
134
|
+
getRecallRecordingMock.mockResolvedValue({
|
|
135
|
+
ok: false,
|
|
136
|
+
status: 500,
|
|
137
|
+
errorMessage: 'recording boom',
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const updateFields = await ingestCallRecordingMedia({
|
|
141
|
+
callRecordingId: 'call-recording-1',
|
|
142
|
+
externalRecordingId: 'recall-recording-1',
|
|
143
|
+
hasAudio: false,
|
|
144
|
+
hasVideo: false,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
expect(updateFields).toEqual({});
|
|
148
|
+
expect(uploadFileMock).not.toHaveBeenCalled();
|
|
149
|
+
expect(console.warn).toHaveBeenCalledWith(
|
|
150
|
+
expect.stringContaining('recording boom'),
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
});
|