@twentyhq/meet 0.0.0-stage → 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.
Files changed (172) hide show
  1. package/README.md +48 -2
  2. package/dependencies/yarn.lock +1863 -0
  3. package/manifest.json +1901 -0
  4. package/package.json +44 -4
  5. package/public/gallery/meet-cover-image-1.png +0 -0
  6. package/public/gallery/meet-cover-image-2.png +0 -0
  7. package/public/gallery/meet-cover-image-3.png +0 -0
  8. package/public/logo.svg +1 -0
  9. package/src/constants/meet-call-summary-prompt.constant.ts +54 -0
  10. package/src/constants/meet.constant.ts +17 -0
  11. package/src/constants/universal-identifiers.ts +35 -0
  12. package/src/logic-functions/constants/calendar-event-matching.constant.ts +3 -0
  13. package/src/logic-functions/constants/google-docs-api.constant.ts +10 -0
  14. package/src/logic-functions/constants/google-drive-api.constant.ts +1 -0
  15. package/src/logic-functions/constants/google-pubsub-push.constant.ts +7 -0
  16. package/src/logic-functions/constants/google-user-info.constant.ts +2 -0
  17. package/src/logic-functions/constants/google-workspace-events.constant.ts +17 -0
  18. package/src/logic-functions/constants/meet-api.constant.ts +9 -0
  19. package/src/logic-functions/constants/meet-call-summary.constant.ts +3 -0
  20. package/src/logic-functions/constants/meet-import.constant.ts +7 -0
  21. package/src/logic-functions/constants/meet-recording-import.constant.ts +7 -0
  22. package/src/logic-functions/constants/restricted-field-placeholder.constant.ts +2 -0
  23. package/src/logic-functions/meet-events-resolver.mjs +1345 -0
  24. package/src/logic-functions/meet-events-resolver.mjs.map +7 -0
  25. package/src/logic-functions/meet-events-resolver.ts +89 -0
  26. package/src/logic-functions/meet-handle-event.mjs +665 -0
  27. package/src/logic-functions/meet-handle-event.mjs.map +7 -0
  28. package/src/logic-functions/meet-handle-event.ts +86 -0
  29. package/src/logic-functions/meet-identify-account.mjs +369 -0
  30. package/src/logic-functions/meet-identify-account.mjs.map +7 -0
  31. package/src/logic-functions/meet-identify-account.ts +42 -0
  32. package/src/logic-functions/meet-import-conference.mjs +1465 -0
  33. package/src/logic-functions/meet-import-conference.mjs.map +7 -0
  34. package/src/logic-functions/meet-import-conference.ts +101 -0
  35. package/src/logic-functions/meet-import-recording.mjs +794 -0
  36. package/src/logic-functions/meet-import-recording.mjs.map +7 -0
  37. package/src/logic-functions/meet-import-recording.ts +99 -0
  38. package/src/logic-functions/meet-queue-conference-imports.mjs +711 -0
  39. package/src/logic-functions/meet-queue-conference-imports.mjs.map +7 -0
  40. package/src/logic-functions/meet-queue-conference-imports.ts +62 -0
  41. package/src/logic-functions/meet-refresh-connections.mjs +457 -0
  42. package/src/logic-functions/meet-refresh-connections.mjs.map +7 -0
  43. package/src/logic-functions/meet-refresh-connections.ts +64 -0
  44. package/src/logic-functions/meet-register-connection.mjs +837 -0
  45. package/src/logic-functions/meet-register-connection.mjs.map +7 -0
  46. package/src/logic-functions/meet-register-connection.ts +81 -0
  47. package/src/logic-functions/meet-summarize-call-recording.mjs +645 -0
  48. package/src/logic-functions/meet-summarize-call-recording.mjs.map +7 -0
  49. package/src/logic-functions/meet-summarize-call-recording.ts +111 -0
  50. package/src/logic-functions/meet-unregister-connection.mjs +610 -0
  51. package/src/logic-functions/meet-unregister-connection.mjs.map +7 -0
  52. package/src/logic-functions/meet-unregister-connection.ts +57 -0
  53. package/src/logic-functions/types/calendar-event-candidate.type.ts +6 -0
  54. package/src/logic-functions/types/call-recording-for-summary.type.ts +5 -0
  55. package/src/logic-functions/types/call-recording-sync-fields.type.ts +12 -0
  56. package/src/logic-functions/types/call-recording-upsert-outcome.type.ts +4 -0
  57. package/src/logic-functions/types/google-doc-lists.type.ts +4 -0
  58. package/src/logic-functions/types/google-doc-markdown-segment.type.ts +5 -0
  59. package/src/logic-functions/types/google-doc-paragraph-element.type.ts +8 -0
  60. package/src/logic-functions/types/google-doc-paragraph.type.ts +7 -0
  61. package/src/logic-functions/types/google-doc-tab.type.ts +10 -0
  62. package/src/logic-functions/types/google-doc.type.ts +6 -0
  63. package/src/logic-functions/types/google-pubsub-push-body.type.ts +6 -0
  64. package/src/logic-functions/types/google-request-method.type.ts +1 -0
  65. package/src/logic-functions/types/google-user-info.type.ts +4 -0
  66. package/src/logic-functions/types/google-workspace-events-operation.type.ts +8 -0
  67. package/src/logic-functions/types/meet-call-summary-outcome.type.ts +6 -0
  68. package/src/logic-functions/types/meet-collection-page.type.ts +3 -0
  69. package/src/logic-functions/types/meet-conference-record.type.ts +7 -0
  70. package/src/logic-functions/types/meet-conference-sync-outcome.type.ts +5 -0
  71. package/src/logic-functions/types/meet-conference-sync-result.type.ts +7 -0
  72. package/src/logic-functions/types/meet-daily-job-name.type.ts +1 -0
  73. package/src/logic-functions/types/meet-event-data.type.ts +5 -0
  74. package/src/logic-functions/types/meet-event-outcome.type.ts +4 -0
  75. package/src/logic-functions/types/meet-event-subscription.type.ts +8 -0
  76. package/src/logic-functions/types/meet-event.type.ts +5 -0
  77. package/src/logic-functions/types/meet-exception-code.type.ts +12 -0
  78. package/src/logic-functions/types/meet-exception.type.ts +25 -0
  79. package/src/logic-functions/types/meet-participant.type.ts +8 -0
  80. package/src/logic-functions/types/meet-recording-import-outcome.type.ts +6 -0
  81. package/src/logic-functions/types/meet-recording.type.ts +7 -0
  82. package/src/logic-functions/types/meet-smart-note.type.ts +7 -0
  83. package/src/logic-functions/types/meet-space.type.ts +5 -0
  84. package/src/logic-functions/types/meet-transcript-entry.type.ts +8 -0
  85. package/src/logic-functions/types/meet-transcript.type.ts +7 -0
  86. package/src/logic-functions/types/transcript-entry.type.ts +7 -0
  87. package/src/logic-functions/utils/build-google-api-url-or-throw.util.ts +30 -0
  88. package/src/logic-functions/utils/build-google-doc-markdown-segment.util.ts +67 -0
  89. package/src/logic-functions/utils/build-meet-artifact-import-job.util.ts +25 -0
  90. package/src/logic-functions/utils/build-meet-call-recording-sync-fields.util.ts +48 -0
  91. package/src/logic-functions/utils/build-meet-call-summary-job.util.ts +19 -0
  92. package/src/logic-functions/utils/build-meet-call-summary-prompt.util.ts +50 -0
  93. package/src/logic-functions/utils/build-meet-conference-import-job.util.ts +26 -0
  94. package/src/logic-functions/utils/build-meet-conference-import-payload.util.ts +18 -0
  95. package/src/logic-functions/utils/build-meet-conference-record-filter.util.ts +8 -0
  96. package/src/logic-functions/utils/build-meet-daily-job.util.ts +17 -0
  97. package/src/logic-functions/utils/build-meet-recording-import-job.util.ts +20 -0
  98. package/src/logic-functions/utils/build-meet-url-or-throw.util.ts +15 -0
  99. package/src/logic-functions/utils/build-meet-user-target-resource.util.ts +2 -0
  100. package/src/logic-functions/utils/can-renew-meet-event-subscription.util.ts +18 -0
  101. package/src/logic-functions/utils/chunk-into-batches.util.ts +10 -0
  102. package/src/logic-functions/utils/claim-meet-event-subscription.util.ts +10 -0
  103. package/src/logic-functions/utils/compute-call-recording-id-for-meet-conference.util.ts +16 -0
  104. package/src/logic-functions/utils/convert-google-doc-paragraph-to-markdown.util.ts +62 -0
  105. package/src/logic-functions/utils/convert-google-doc-tab-to-markdown.util.ts +49 -0
  106. package/src/logic-functions/utils/create-meet-event-subscription-or-throw.util.ts +41 -0
  107. package/src/logic-functions/utils/delete-meet-event-subscription.util.ts +22 -0
  108. package/src/logic-functions/utils/enqueue-meet-conference-imports-or-throw.util.ts +39 -0
  109. package/src/logic-functions/utils/enqueue-meet-daily-jobs-or-throw.util.ts +35 -0
  110. package/src/logic-functions/utils/ensure-meet-event-subscription-or-throw.util.ts +51 -0
  111. package/src/logic-functions/utils/escape-markdown-text.util.ts +4 -0
  112. package/src/logic-functions/utils/escape-sql-like-pattern.util.ts +2 -0
  113. package/src/logic-functions/utils/extract-bearer-token.util.ts +23 -0
  114. package/src/logic-functions/utils/extract-meet-name-from-doc-title.util.ts +16 -0
  115. package/src/logic-functions/utils/fetch-meet-json.util.ts +107 -0
  116. package/src/logic-functions/utils/find-call-recording-for-summary.util.ts +38 -0
  117. package/src/logic-functions/utils/find-call-recording-video-state.util.ts +25 -0
  118. package/src/logic-functions/utils/find-meet-calendar-event.util.ts +74 -0
  119. package/src/logic-functions/utils/find-meet-conference-title.util.ts +38 -0
  120. package/src/logic-functions/utils/find-meet-event-subscription.util.ts +32 -0
  121. package/src/logic-functions/utils/find-meet-smart-notes-markdown.util.ts +32 -0
  122. package/src/logic-functions/utils/format-seconds-as-clock-timestamp.util.ts +20 -0
  123. package/src/logic-functions/utils/get-conference-record-name-from-artifact-name.util.ts +6 -0
  124. package/src/logic-functions/utils/get-connection-access-token-or-throw.util.ts +18 -0
  125. package/src/logic-functions/utils/get-google-doc-title.util.ts +31 -0
  126. package/src/logic-functions/utils/get-google-doc.util.ts +30 -0
  127. package/src/logic-functions/utils/get-google-drive-file-size-bytes-or-throw.util.ts +31 -0
  128. package/src/logic-functions/utils/get-meet-conference-record.util.ts +18 -0
  129. package/src/logic-functions/utils/get-meet-connection-subscription-key.util.ts +3 -0
  130. package/src/logic-functions/utils/get-meet-event-subscription-key.util.ts +2 -0
  131. package/src/logic-functions/utils/get-meet-participant-display-name.util.ts +20 -0
  132. package/src/logic-functions/utils/get-meet-recording-drive-file-id.util.ts +16 -0
  133. package/src/logic-functions/utils/get-meet-recording.util.ts +18 -0
  134. package/src/logic-functions/utils/get-meet-space.util.ts +15 -0
  135. package/src/logic-functions/utils/get-random-delay-milliseconds.util.ts +4 -0
  136. package/src/logic-functions/utils/is-google-doc-unreadable-error.util.ts +9 -0
  137. package/src/logic-functions/utils/is-google-pubsub-push-authorized.util.ts +31 -0
  138. package/src/logic-functions/utils/is-meet-ai-summary-enabled-for-member.util.ts +22 -0
  139. package/src/logic-functions/utils/is-transcript-entry-list.util.ts +16 -0
  140. package/src/logic-functions/utils/join-google-doc-markdown-segments.util.ts +102 -0
  141. package/src/logic-functions/utils/list-calendar-events-in-window.util.ts +142 -0
  142. package/src/logic-functions/utils/list-meet-collection.util.ts +79 -0
  143. package/src/logic-functions/utils/list-meet-conference-records.util.ts +22 -0
  144. package/src/logic-functions/utils/list-meet-participants.util.ts +15 -0
  145. package/src/logic-functions/utils/list-meet-recordings.util.ts +15 -0
  146. package/src/logic-functions/utils/list-meet-smart-notes.util.ts +15 -0
  147. package/src/logic-functions/utils/list-meet-transcript-entries.util.ts +15 -0
  148. package/src/logic-functions/utils/list-meet-transcripts.util.ts +15 -0
  149. package/src/logic-functions/utils/map-meet-transcript-entries.util.ts +64 -0
  150. package/src/logic-functions/utils/normalize-meeting-url.util.ts +18 -0
  151. package/src/logic-functions/utils/open-google-drive-file-download-or-throw.util.ts +36 -0
  152. package/src/logic-functions/utils/parse-meet-call-summary-response.util.ts +36 -0
  153. package/src/logic-functions/utils/parse-meet-event-data-or-throw.util.ts +36 -0
  154. package/src/logic-functions/utils/parse-meet-event-or-throw.util.ts +35 -0
  155. package/src/logic-functions/utils/parse-retry-after-milliseconds.util.ts +27 -0
  156. package/src/logic-functions/utils/put-stream-to-upload-url-or-throw.util.ts +73 -0
  157. package/src/logic-functions/utils/read-meet-event-subscription-or-throw.util.ts +24 -0
  158. package/src/logic-functions/utils/release-meet-event-subscription.util.ts +29 -0
  159. package/src/logic-functions/utils/renew-meet-event-subscription-or-throw.util.ts +32 -0
  160. package/src/logic-functions/utils/run-meet-call-summarizer-or-throw.util.ts +28 -0
  161. package/src/logic-functions/utils/save-call-recording-summary-if-empty.util.ts +29 -0
  162. package/src/logic-functions/utils/save-call-recording-video.util.ts +23 -0
  163. package/src/logic-functions/utils/should-generate-meet-ai-summary.util.ts +17 -0
  164. package/src/logic-functions/utils/sleep-for-milliseconds.util.ts +2 -0
  165. package/src/logic-functions/utils/split-surrounding-whitespace.util.ts +10 -0
  166. package/src/logic-functions/utils/store-meet-connection-subscription.util.ts +46 -0
  167. package/src/logic-functions/utils/sync-meet-conference-or-throw.util.ts +129 -0
  168. package/src/logic-functions/utils/upload-google-drive-file-as-call-recording-video-or-throw.util.ts +73 -0
  169. package/src/logic-functions/utils/upsert-call-recording-or-throw.util.ts +104 -0
  170. package/src/logic-functions/utils/verify-google-pubsub-push-token-or-throw.util.ts +71 -0
  171. package/src/logic-functions/utils/wait-for-google-workspace-events-operation-or-throw.util.ts +53 -0
  172. package/tsconfig.json +39 -0
@@ -0,0 +1,7 @@
1
+ export type MeetSmartNote = {
2
+ name: string;
3
+ state?: 'STATE_UNSPECIFIED' | 'STARTED' | 'ENDED' | 'FILE_GENERATED';
4
+ startTime?: string;
5
+ endTime?: string;
6
+ docsDestination?: { document?: string; exportUri?: string };
7
+ };
@@ -0,0 +1,5 @@
1
+ export type MeetSpace = {
2
+ name: string;
3
+ meetingUri?: string;
4
+ meetingCode?: string;
5
+ };
@@ -0,0 +1,8 @@
1
+ export type MeetTranscriptEntry = {
2
+ name: string;
3
+ participant?: string;
4
+ text?: string;
5
+ languageCode?: string;
6
+ startTime?: string;
7
+ endTime?: string;
8
+ };
@@ -0,0 +1,7 @@
1
+ export type MeetTranscript = {
2
+ name: string;
3
+ state?: 'STATE_UNSPECIFIED' | 'STARTED' | 'ENDED' | 'FILE_GENERATED';
4
+ startTime?: string;
5
+ endTime?: string;
6
+ docsDestination?: { document?: string; exportUri?: string };
7
+ };
@@ -0,0 +1,7 @@
1
+ export type TranscriptEntry = {
2
+ participant: { name: string | null };
3
+ words: Array<{
4
+ text: string;
5
+ start_timestamp: { relative: number };
6
+ }>;
7
+ };
@@ -0,0 +1,30 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+
3
+ import { MeetException } from 'src/logic-functions/types/meet-exception.type';
4
+
5
+ export const buildGoogleApiUrlOrThrow = ({
6
+ baseUrl,
7
+ path,
8
+ queryParameters,
9
+ }: {
10
+ baseUrl: string;
11
+ path: string;
12
+ queryParameters: Record<string, string | undefined>;
13
+ }): string => {
14
+ const url = new URL(`${baseUrl}/${path}`);
15
+
16
+ if (!url.href.startsWith(`${baseUrl}/`)) {
17
+ throw new MeetException({
18
+ message: `Google resource paths must stay under ${baseUrl}`,
19
+ code: 'INVALID_RESOURCE_PATH',
20
+ });
21
+ }
22
+
23
+ for (const [name, value] of Object.entries(queryParameters)) {
24
+ if (isNonEmptyString(value)) {
25
+ url.searchParams.set(name, value);
26
+ }
27
+ }
28
+
29
+ return url.toString();
30
+ };
@@ -0,0 +1,67 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+ import { isDefined } from 'twenty-sdk/utils';
3
+
4
+ import { type GoogleDocMarkdownSegment } from 'src/logic-functions/types/google-doc-markdown-segment.type';
5
+ import { type GoogleDocParagraphElement } from 'src/logic-functions/types/google-doc-paragraph-element.type';
6
+ import { escapeMarkdownText } from 'src/logic-functions/utils/escape-markdown-text.util';
7
+ import { splitSurroundingWhitespace } from 'src/logic-functions/utils/split-surrounding-whitespace.util';
8
+
9
+ const linkMarkdownText = ({
10
+ text,
11
+ url,
12
+ }: {
13
+ text: string;
14
+ url: string | undefined;
15
+ }): string => {
16
+ const { leading, content, trailing } = splitSurroundingWhitespace(text);
17
+
18
+ if (!isNonEmptyString(url) || !isNonEmptyString(content)) {
19
+ return text;
20
+ }
21
+
22
+ return `${leading}[${content}](${url})${trailing}`;
23
+ };
24
+
25
+ export const buildGoogleDocMarkdownSegment = (
26
+ element: GoogleDocParagraphElement,
27
+ ): GoogleDocMarkdownSegment => {
28
+ if (isDefined(element.textRun)) {
29
+ const { content, textStyle } = element.textRun;
30
+
31
+ return {
32
+ markdown: linkMarkdownText({
33
+ text: escapeMarkdownText(
34
+ (content ?? '').replace(/\n/g, '').replace(/\u000b/g, '\n'),
35
+ ),
36
+ url: textStyle?.link?.url,
37
+ }),
38
+ isBold: textStyle?.bold,
39
+ isItalic: textStyle?.italic,
40
+ };
41
+ }
42
+
43
+ const personProperties = element.person?.personProperties;
44
+
45
+ if (isDefined(personProperties)) {
46
+ return {
47
+ markdown: escapeMarkdownText(
48
+ personProperties.name ?? personProperties.email ?? '',
49
+ ),
50
+ };
51
+ }
52
+
53
+ const richLinkProperties = element.richLink?.richLinkProperties;
54
+
55
+ if (isNonEmptyString(richLinkProperties?.uri)) {
56
+ return {
57
+ markdown: linkMarkdownText({
58
+ text: escapeMarkdownText(
59
+ richLinkProperties.title ?? richLinkProperties.uri,
60
+ ),
61
+ url: richLinkProperties.uri,
62
+ }),
63
+ };
64
+ }
65
+
66
+ return { markdown: '' };
67
+ };
@@ -0,0 +1,25 @@
1
+ import { createHash } from 'crypto';
2
+ import { type EnqueueJobItem } from 'twenty-sdk/logic-function';
3
+
4
+ import { type MeetConferenceRecord } from 'src/logic-functions/types/meet-conference-record.type';
5
+ import { buildMeetConferenceImportPayload } from 'src/logic-functions/utils/build-meet-conference-import-payload.util';
6
+
7
+ export const buildMeetArtifactImportJob = ({
8
+ connectedAccountId,
9
+ conferenceRecord,
10
+ artifactName,
11
+ }: {
12
+ connectedAccountId: string;
13
+ conferenceRecord: Pick<
14
+ MeetConferenceRecord,
15
+ 'name' | 'startTime' | 'endTime' | 'space'
16
+ >;
17
+ artifactName: string;
18
+ }): EnqueueJobItem => ({
19
+ // One run per transcript or smart note: Pub/Sub can deliver the same event more than once.
20
+ jobId: `google-meet-artifact-${createHash('sha256').update(artifactName).digest('hex')}`,
21
+ payload: buildMeetConferenceImportPayload({
22
+ connectedAccountId,
23
+ conferenceRecord,
24
+ }),
25
+ });
@@ -0,0 +1,48 @@
1
+ import { isNonEmptyArray, isNonEmptyString } from '@sniptt/guards';
2
+ import { isDefined } from 'twenty-sdk/utils';
3
+
4
+ import { type CalendarEventCandidate } from 'src/logic-functions/types/calendar-event-candidate.type';
5
+ import { type CallRecordingSyncFields } from 'src/logic-functions/types/call-recording-sync-fields.type';
6
+ import { type MeetConferenceRecord } from 'src/logic-functions/types/meet-conference-record.type';
7
+ import { type TranscriptEntry } from 'src/logic-functions/types/transcript-entry.type';
8
+
9
+ export const buildMeetCallRecordingSyncFields = ({
10
+ conferenceRecord,
11
+ title,
12
+ summaryMarkdown,
13
+ transcriptEntries,
14
+ hasRecordingFile,
15
+ calendarEvent,
16
+ }: {
17
+ conferenceRecord: Pick<
18
+ MeetConferenceRecord,
19
+ 'name' | 'startTime' | 'endTime'
20
+ >;
21
+ title: string | undefined;
22
+ summaryMarkdown: string | undefined;
23
+ transcriptEntries: TranscriptEntry[];
24
+ hasRecordingFile: boolean;
25
+ calendarEvent: Pick<CalendarEventCandidate, 'id'> | undefined;
26
+ }): CallRecordingSyncFields => {
27
+ return {
28
+ ...(isNonEmptyString(title) ? { title } : {}),
29
+ status:
30
+ isNonEmptyArray(transcriptEntries) ||
31
+ isNonEmptyString(summaryMarkdown) ||
32
+ hasRecordingFile
33
+ ? 'COMPLETED'
34
+ : 'PROCESSING',
35
+ externalRecordingId: conferenceRecord.name,
36
+ startedAt: conferenceRecord.startTime,
37
+ ...(isNonEmptyString(conferenceRecord.endTime)
38
+ ? { endedAt: conferenceRecord.endTime }
39
+ : {}),
40
+ ...(isNonEmptyArray(transcriptEntries)
41
+ ? { transcript: transcriptEntries }
42
+ : {}),
43
+ ...(isNonEmptyString(summaryMarkdown)
44
+ ? { summary: { blocknote: null, markdown: summaryMarkdown } }
45
+ : {}),
46
+ ...(isDefined(calendarEvent) ? { calendarEventId: calendarEvent.id } : {}),
47
+ };
48
+ };
@@ -0,0 +1,19 @@
1
+ import { type EnqueueJobItem } from 'twenty-sdk/logic-function';
2
+
3
+ import { computeCallRecordingIdForMeetConference } from 'src/logic-functions/utils/compute-call-recording-id-for-meet-conference.util';
4
+
5
+ export const buildMeetCallSummaryJob = ({
6
+ conferenceRecordName,
7
+ userWorkspaceId,
8
+ }: {
9
+ conferenceRecordName: string;
10
+ userWorkspaceId: string | null;
11
+ }): EnqueueJobItem => {
12
+ const callRecordingId =
13
+ computeCallRecordingIdForMeetConference(conferenceRecordName);
14
+
15
+ return {
16
+ jobId: `google-meet-summary-${callRecordingId}`,
17
+ payload: { callRecordingId, userWorkspaceId },
18
+ };
19
+ };
@@ -0,0 +1,50 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+ import { isDefined } from 'twenty-sdk/utils';
3
+
4
+ import { MEET_UNKNOWN_SPEAKER_NAME } from 'src/logic-functions/constants/meet-call-summary.constant';
5
+ import { type TranscriptEntry } from 'src/logic-functions/types/transcript-entry.type';
6
+ import { formatSecondsAsClockTimestamp } from 'src/logic-functions/utils/format-seconds-as-clock-timestamp.util';
7
+
8
+ const formatStartTimestamp = (startSeconds: number | undefined): string => {
9
+ if (!isDefined(startSeconds)) {
10
+ return '';
11
+ }
12
+
13
+ return `[${formatSecondsAsClockTimestamp(startSeconds)}] `;
14
+ };
15
+
16
+ const buildTranscriptLine = ({
17
+ participant,
18
+ words,
19
+ }: TranscriptEntry): string | undefined => {
20
+ const text = words
21
+ .map((word) => word.text.trim())
22
+ .filter(isNonEmptyString)
23
+ .join(' ');
24
+
25
+ if (!isNonEmptyString(text)) {
26
+ return undefined;
27
+ }
28
+
29
+ return `${formatStartTimestamp(words[0]?.start_timestamp.relative)}${participant.name ?? MEET_UNKNOWN_SPEAKER_NAME}: ${text}`;
30
+ };
31
+
32
+ export const buildMeetCallSummaryPrompt = ({
33
+ title,
34
+ transcriptEntries,
35
+ }: {
36
+ title: string | undefined;
37
+ transcriptEntries: TranscriptEntry[];
38
+ }): string | undefined => {
39
+ const lines = transcriptEntries
40
+ .map(buildTranscriptLine)
41
+ .filter(isNonEmptyString);
42
+
43
+ if (lines.length === 0) {
44
+ return undefined;
45
+ }
46
+
47
+ const header = isNonEmptyString(title) ? `Meeting title: ${title}\n\n` : '';
48
+
49
+ return `${header}Transcript:\n${lines.join('\n')}`;
50
+ };
@@ -0,0 +1,26 @@
1
+ import { type EnqueueJobItem } from 'twenty-sdk/logic-function';
2
+
3
+ import { MILLISECONDS_PER_HOUR } from 'src/logic-functions/constants/meet-import.constant';
4
+ import { type MeetConferenceRecord } from 'src/logic-functions/types/meet-conference-record.type';
5
+ import { buildMeetConferenceImportPayload } from 'src/logic-functions/utils/build-meet-conference-import-payload.util';
6
+ import { computeCallRecordingIdForMeetConference } from 'src/logic-functions/utils/compute-call-recording-id-for-meet-conference.util';
7
+
8
+ export const buildMeetConferenceImportJob = ({
9
+ connectedAccountId,
10
+ conferenceRecord,
11
+ now,
12
+ }: {
13
+ connectedAccountId: string;
14
+ conferenceRecord: Pick<
15
+ MeetConferenceRecord,
16
+ 'name' | 'startTime' | 'endTime' | 'space'
17
+ >;
18
+ now: Date;
19
+ }): EnqueueJobItem => ({
20
+ // One run per conference and hour: a transcript published late is picked up by a later hour.
21
+ jobId: `google-meet-conference-${computeCallRecordingIdForMeetConference(conferenceRecord.name)}-${Math.floor(now.getTime() / MILLISECONDS_PER_HOUR)}`,
22
+ payload: buildMeetConferenceImportPayload({
23
+ connectedAccountId,
24
+ conferenceRecord,
25
+ }),
26
+ });
@@ -0,0 +1,18 @@
1
+ import { type MeetConferenceRecord } from 'src/logic-functions/types/meet-conference-record.type';
2
+
3
+ export const buildMeetConferenceImportPayload = ({
4
+ connectedAccountId,
5
+ conferenceRecord,
6
+ }: {
7
+ connectedAccountId: string;
8
+ conferenceRecord: Pick<
9
+ MeetConferenceRecord,
10
+ 'name' | 'startTime' | 'endTime' | 'space'
11
+ >;
12
+ }) => ({
13
+ connectedAccountId,
14
+ conferenceRecordName: conferenceRecord.name,
15
+ startTime: conferenceRecord.startTime,
16
+ endTime: conferenceRecord.endTime,
17
+ spaceName: conferenceRecord.space,
18
+ });
@@ -0,0 +1,8 @@
1
+ export const buildMeetConferenceRecordFilter = ({
2
+ startedAfter,
3
+ startedBefore,
4
+ }: {
5
+ startedAfter: Date;
6
+ startedBefore: Date;
7
+ }): string =>
8
+ `start_time>="${startedAfter.toISOString()}" AND start_time<="${startedBefore.toISOString()}"`;
@@ -0,0 +1,17 @@
1
+ import { type EnqueueJobItem } from 'twenty-sdk/logic-function';
2
+
3
+ import { MILLISECONDS_PER_DAY } from 'src/logic-functions/constants/meet-import.constant';
4
+ import { type MeetDailyJobName } from 'src/logic-functions/types/meet-daily-job-name.type';
5
+
6
+ export const buildMeetDailyJob = ({
7
+ jobName,
8
+ connectedAccountId,
9
+ now,
10
+ }: {
11
+ jobName: MeetDailyJobName;
12
+ connectedAccountId: string;
13
+ now: Date;
14
+ }): EnqueueJobItem => ({
15
+ jobId: `google-meet-${jobName}-${connectedAccountId}-${Math.floor(now.getTime() / MILLISECONDS_PER_DAY)}`,
16
+ payload: { connectedAccountId },
17
+ });
@@ -0,0 +1,20 @@
1
+ import { createHash } from 'crypto';
2
+ import { type EnqueueJobItem } from 'twenty-sdk/logic-function';
3
+
4
+ import { MILLISECONDS_PER_HOUR } from 'src/logic-functions/constants/meet-import.constant';
5
+
6
+ export const buildMeetRecordingImportJob = ({
7
+ connectedAccountId,
8
+ conferenceRecordName,
9
+ recordingName,
10
+ now,
11
+ }: {
12
+ connectedAccountId: string;
13
+ conferenceRecordName: string;
14
+ recordingName: string;
15
+ now: Date;
16
+ }): EnqueueJobItem => ({
17
+ // One run per recording and hour: the queue keeps a failed job for days, so a fixed id would block later retries.
18
+ jobId: `google-meet-recording-${createHash('sha256').update(recordingName).digest('hex')}-${Math.floor(now.getTime() / MILLISECONDS_PER_HOUR)}`,
19
+ payload: { connectedAccountId, conferenceRecordName, recordingName },
20
+ });
@@ -0,0 +1,15 @@
1
+ import { MEET_API_BASE_URL } from 'src/logic-functions/constants/meet-api.constant';
2
+ import { buildGoogleApiUrlOrThrow } from 'src/logic-functions/utils/build-google-api-url-or-throw.util';
3
+
4
+ export const buildMeetUrlOrThrow = ({
5
+ path,
6
+ queryParameters,
7
+ }: {
8
+ path: string;
9
+ queryParameters: Record<string, string | undefined>;
10
+ }): string =>
11
+ buildGoogleApiUrlOrThrow({
12
+ baseUrl: MEET_API_BASE_URL,
13
+ path,
14
+ queryParameters,
15
+ });
@@ -0,0 +1,2 @@
1
+ export const buildMeetUserTargetResource = (googleUserId: string) =>
2
+ `//cloudidentity.googleapis.com/users/${googleUserId}`;
@@ -0,0 +1,18 @@
1
+ import { MEET_EVENT_TYPES } from 'src/logic-functions/constants/google-workspace-events.constant';
2
+ import { type MeetEventSubscription } from 'src/logic-functions/types/meet-event-subscription.type';
3
+
4
+ export const canRenewMeetEventSubscription = ({
5
+ subscription,
6
+ pubsubTopic,
7
+ }: {
8
+ subscription: Pick<
9
+ MeetEventSubscription,
10
+ 'notificationEndpoint' | 'state' | 'eventTypes'
11
+ >;
12
+ pubsubTopic: string;
13
+ }): boolean =>
14
+ subscription.notificationEndpoint?.pubsubTopic === pubsubTopic &&
15
+ subscription.state !== 'SUSPENDED' &&
16
+ MEET_EVENT_TYPES.every((eventType) =>
17
+ subscription.eventTypes?.includes(eventType),
18
+ );
@@ -0,0 +1,10 @@
1
+ export const chunkIntoBatches = <TItem>({
2
+ items,
3
+ batchSize,
4
+ }: {
5
+ items: TItem[];
6
+ batchSize: number;
7
+ }): TItem[][] =>
8
+ Array.from({ length: Math.ceil(items.length / batchSize) }, (_, batchIndex) =>
9
+ items.slice(batchIndex * batchSize, (batchIndex + 1) * batchSize),
10
+ );
@@ -0,0 +1,10 @@
1
+ import { kv } from 'twenty-sdk/logic-function';
2
+
3
+ import { getMeetEventSubscriptionKey } from 'src/logic-functions/utils/get-meet-event-subscription-key.util';
4
+
5
+ export const claimMeetEventSubscription = (
6
+ subscriptionName: string,
7
+ ): Promise<void> =>
8
+ kv.set(getMeetEventSubscriptionKey(subscriptionName), null, {
9
+ scope: 'SERVER',
10
+ });
@@ -0,0 +1,16 @@
1
+ import { createHash } from 'crypto';
2
+
3
+ export const computeCallRecordingIdForMeetConference = (
4
+ conferenceRecordName: string,
5
+ ): string => {
6
+ const bytes = createHash('sha256')
7
+ .update(`google-meet-conference:${conferenceRecordName}`)
8
+ .digest();
9
+
10
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
11
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
12
+
13
+ const hexadecimalValue = bytes.subarray(0, 16).toString('hex');
14
+
15
+ return `${hexadecimalValue.slice(0, 8)}-${hexadecimalValue.slice(8, 12)}-${hexadecimalValue.slice(12, 16)}-${hexadecimalValue.slice(16, 20)}-${hexadecimalValue.slice(20)}`;
16
+ };
@@ -0,0 +1,62 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+ import { isDefined } from 'twenty-sdk/utils';
3
+
4
+ import { GOOGLE_DOC_ORDERED_GLYPH_TYPES } from 'src/logic-functions/constants/google-docs-api.constant';
5
+ import { type GoogleDocLists } from 'src/logic-functions/types/google-doc-lists.type';
6
+ import { type GoogleDocParagraph } from 'src/logic-functions/types/google-doc-paragraph.type';
7
+ import { buildGoogleDocMarkdownSegment } from 'src/logic-functions/utils/build-google-doc-markdown-segment.util';
8
+ import { joinGoogleDocMarkdownSegments } from 'src/logic-functions/utils/join-google-doc-markdown-segments.util';
9
+
10
+ const HEADING_STYLE_PATTERN = /^HEADING_([1-6])$/;
11
+
12
+ const getHeadingPrefix = (namedStyleType: string | undefined): string => {
13
+ if (namedStyleType === 'TITLE') {
14
+ return '# ';
15
+ }
16
+
17
+ const headingLevel = HEADING_STYLE_PATTERN.exec(namedStyleType ?? '')?.[1];
18
+
19
+ return isDefined(headingLevel) ? `${'#'.repeat(Number(headingLevel))} ` : '';
20
+ };
21
+
22
+ const getBulletPrefix = ({
23
+ bullet,
24
+ lists,
25
+ }: {
26
+ bullet: GoogleDocParagraph['bullet'];
27
+ lists: GoogleDocLists;
28
+ }): string => {
29
+ if (!isDefined(bullet)) {
30
+ return '';
31
+ }
32
+
33
+ const nestingLevel = bullet.nestingLevel ?? 0;
34
+ const indentation = ' '.repeat(nestingLevel);
35
+ const glyphType =
36
+ lists[bullet.listId]?.listProperties?.nestingLevels?.[nestingLevel]
37
+ ?.glyphType;
38
+
39
+ if (isDefined(glyphType) && GOOGLE_DOC_ORDERED_GLYPH_TYPES.has(glyphType)) {
40
+ return `${indentation}1. `;
41
+ }
42
+
43
+ return `${indentation}- `;
44
+ };
45
+
46
+ export const convertGoogleDocParagraphToMarkdown = ({
47
+ paragraph,
48
+ lists,
49
+ }: {
50
+ paragraph: GoogleDocParagraph;
51
+ lists: GoogleDocLists;
52
+ }): string | undefined => {
53
+ const text = joinGoogleDocMarkdownSegments(
54
+ (paragraph.elements ?? []).map(buildGoogleDocMarkdownSegment),
55
+ ).trim();
56
+
57
+ if (!isNonEmptyString(text)) {
58
+ return undefined;
59
+ }
60
+
61
+ return `${getBulletPrefix({ bullet: paragraph.bullet, lists })}${getHeadingPrefix(paragraph.paragraphStyle?.namedStyleType)}${text}`;
62
+ };
@@ -0,0 +1,49 @@
1
+ import { isDefined } from 'twenty-sdk/utils';
2
+
3
+ import { type GoogleDocTab } from 'src/logic-functions/types/google-doc-tab.type';
4
+ import { convertGoogleDocParagraphToMarkdown } from 'src/logic-functions/utils/convert-google-doc-paragraph-to-markdown.util';
5
+
6
+ type MarkdownBlock = { markdown: string; isListItem: boolean };
7
+
8
+ const getBlockSeparator = ({
9
+ previousBlock,
10
+ block,
11
+ }: {
12
+ previousBlock: MarkdownBlock | undefined;
13
+ block: MarkdownBlock;
14
+ }): string => {
15
+ if (!isDefined(previousBlock)) {
16
+ return '';
17
+ }
18
+
19
+ return previousBlock.isListItem && block.isListItem ? '\n' : '\n\n';
20
+ };
21
+
22
+ export const convertGoogleDocTabToMarkdown = (tab: GoogleDocTab): string => {
23
+ const lists = tab.documentTab?.lists ?? {};
24
+ const blocks = (tab.documentTab?.body?.content ?? []).flatMap(
25
+ ({ paragraph }): MarkdownBlock[] => {
26
+ if (!isDefined(paragraph)) {
27
+ return [];
28
+ }
29
+
30
+ const markdown = convertGoogleDocParagraphToMarkdown({
31
+ paragraph,
32
+ lists,
33
+ });
34
+
35
+ if (!isDefined(markdown)) {
36
+ return [];
37
+ }
38
+
39
+ return [{ markdown, isListItem: isDefined(paragraph.bullet) }];
40
+ },
41
+ );
42
+
43
+ return blocks
44
+ .map(
45
+ (block, index) =>
46
+ `${getBlockSeparator({ previousBlock: blocks[index - 1], block })}${block.markdown}`,
47
+ )
48
+ .join('');
49
+ };
@@ -0,0 +1,41 @@
1
+ import {
2
+ MEET_EVENT_TYPES,
3
+ GOOGLE_WORKSPACE_EVENTS_API_BASE_URL,
4
+ } from 'src/logic-functions/constants/google-workspace-events.constant';
5
+ import { type MeetEventSubscription } from 'src/logic-functions/types/meet-event-subscription.type';
6
+ import { type GoogleWorkspaceEventsOperation } from 'src/logic-functions/types/google-workspace-events-operation.type';
7
+ import { buildMeetUserTargetResource } from 'src/logic-functions/utils/build-meet-user-target-resource.util';
8
+ import { buildGoogleApiUrlOrThrow } from 'src/logic-functions/utils/build-google-api-url-or-throw.util';
9
+ import { fetchMeetJson } from 'src/logic-functions/utils/fetch-meet-json.util';
10
+ import { readMeetEventSubscriptionOrThrow } from 'src/logic-functions/utils/read-meet-event-subscription-or-throw.util';
11
+ import { waitForGoogleWorkspaceEventsOperationOrThrow } from 'src/logic-functions/utils/wait-for-google-workspace-events-operation-or-throw.util';
12
+
13
+ export const createMeetEventSubscriptionOrThrow = async ({
14
+ accessToken,
15
+ googleUserId,
16
+ pubsubTopic,
17
+ }: {
18
+ accessToken: string;
19
+ googleUserId: string;
20
+ pubsubTopic: string;
21
+ }): Promise<MeetEventSubscription> =>
22
+ readMeetEventSubscriptionOrThrow(
23
+ await waitForGoogleWorkspaceEventsOperationOrThrow({
24
+ accessToken,
25
+ pollCount: 0,
26
+ operation: await fetchMeetJson<GoogleWorkspaceEventsOperation>({
27
+ accessToken,
28
+ url: buildGoogleApiUrlOrThrow({
29
+ baseUrl: GOOGLE_WORKSPACE_EVENTS_API_BASE_URL,
30
+ path: 'subscriptions',
31
+ queryParameters: {},
32
+ }),
33
+ method: 'POST',
34
+ body: {
35
+ targetResource: buildMeetUserTargetResource(googleUserId),
36
+ eventTypes: MEET_EVENT_TYPES,
37
+ notificationEndpoint: { pubsubTopic },
38
+ },
39
+ }),
40
+ }),
41
+ );
@@ -0,0 +1,22 @@
1
+ import { GOOGLE_WORKSPACE_EVENTS_API_BASE_URL } from 'src/logic-functions/constants/google-workspace-events.constant';
2
+ import { type GoogleWorkspaceEventsOperation } from 'src/logic-functions/types/google-workspace-events-operation.type';
3
+ import { buildGoogleApiUrlOrThrow } from 'src/logic-functions/utils/build-google-api-url-or-throw.util';
4
+ import { fetchMeetJson } from 'src/logic-functions/utils/fetch-meet-json.util';
5
+
6
+ export const deleteMeetEventSubscription = async ({
7
+ accessToken,
8
+ subscriptionName,
9
+ }: {
10
+ accessToken: string;
11
+ subscriptionName: string;
12
+ }): Promise<void> => {
13
+ await fetchMeetJson<GoogleWorkspaceEventsOperation>({
14
+ accessToken,
15
+ url: buildGoogleApiUrlOrThrow({
16
+ baseUrl: GOOGLE_WORKSPACE_EVENTS_API_BASE_URL,
17
+ path: subscriptionName,
18
+ queryParameters: { allowMissing: 'true' },
19
+ }),
20
+ method: 'DELETE',
21
+ });
22
+ };