@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,39 @@
1
+ import { enqueueJobs } from 'twenty-sdk/logic-function';
2
+
3
+ import { MEET_IMPORT_CONFERENCE_UNIVERSAL_IDENTIFIER } from 'src/constants/universal-identifiers';
4
+ import { MEET_IMPORT_JOB_BATCH_SIZE } from 'src/logic-functions/constants/meet-import.constant';
5
+ import { type MeetConferenceRecord } from 'src/logic-functions/types/meet-conference-record.type';
6
+ import { buildMeetConferenceImportJob } from 'src/logic-functions/utils/build-meet-conference-import-job.util';
7
+ import { chunkIntoBatches } from 'src/logic-functions/utils/chunk-into-batches.util';
8
+
9
+ export const enqueueMeetConferenceImportsOrThrow = async ({
10
+ connectedAccountId,
11
+ conferenceRecords,
12
+ now,
13
+ }: {
14
+ connectedAccountId: string;
15
+ conferenceRecords: Pick<
16
+ MeetConferenceRecord,
17
+ 'name' | 'startTime' | 'endTime' | 'space'
18
+ >[];
19
+ now: Date;
20
+ }): Promise<void> => {
21
+ const jobBatches = chunkIntoBatches({
22
+ items: conferenceRecords.map((conferenceRecord) =>
23
+ buildMeetConferenceImportJob({
24
+ connectedAccountId,
25
+ conferenceRecord,
26
+ now,
27
+ }),
28
+ ),
29
+ batchSize: MEET_IMPORT_JOB_BATCH_SIZE,
30
+ });
31
+
32
+ for (const jobs of jobBatches) {
33
+ await enqueueJobs({
34
+ logicFunctionUniversalIdentifier:
35
+ MEET_IMPORT_CONFERENCE_UNIVERSAL_IDENTIFIER,
36
+ jobs,
37
+ });
38
+ }
39
+ };
@@ -0,0 +1,35 @@
1
+ import { enqueueJobs } from 'twenty-sdk/logic-function';
2
+
3
+ import { MEET_IMPORT_JOB_BATCH_SIZE } from 'src/logic-functions/constants/meet-import.constant';
4
+ import { type MeetDailyJobName } from 'src/logic-functions/types/meet-daily-job-name.type';
5
+ import { buildMeetDailyJob } from 'src/logic-functions/utils/build-meet-daily-job.util';
6
+ import { chunkIntoBatches } from 'src/logic-functions/utils/chunk-into-batches.util';
7
+
8
+ export const enqueueMeetDailyJobsOrThrow = async ({
9
+ logicFunctionUniversalIdentifier,
10
+ jobName,
11
+ connectedAccountIds,
12
+ now,
13
+ delayMilliseconds,
14
+ }: {
15
+ logicFunctionUniversalIdentifier: string;
16
+ jobName: MeetDailyJobName;
17
+ connectedAccountIds: string[];
18
+ now: Date;
19
+ delayMilliseconds: number;
20
+ }): Promise<void> => {
21
+ const jobBatches = chunkIntoBatches({
22
+ items: connectedAccountIds.map((connectedAccountId) =>
23
+ buildMeetDailyJob({ jobName, connectedAccountId, now }),
24
+ ),
25
+ batchSize: MEET_IMPORT_JOB_BATCH_SIZE,
26
+ });
27
+
28
+ for (const jobs of jobBatches) {
29
+ await enqueueJobs({
30
+ logicFunctionUniversalIdentifier,
31
+ jobs,
32
+ delayMs: delayMilliseconds,
33
+ });
34
+ }
35
+ };
@@ -0,0 +1,51 @@
1
+ import { isDefined } from 'twenty-sdk/utils';
2
+
3
+ import { type MeetEventSubscription } from 'src/logic-functions/types/meet-event-subscription.type';
4
+ import { canRenewMeetEventSubscription } from 'src/logic-functions/utils/can-renew-meet-event-subscription.util';
5
+ import { createMeetEventSubscriptionOrThrow } from 'src/logic-functions/utils/create-meet-event-subscription-or-throw.util';
6
+ import { deleteMeetEventSubscription } from 'src/logic-functions/utils/delete-meet-event-subscription.util';
7
+ import { renewMeetEventSubscriptionOrThrow } from 'src/logic-functions/utils/renew-meet-event-subscription-or-throw.util';
8
+
9
+ export const ensureMeetEventSubscriptionOrThrow = async ({
10
+ accessToken,
11
+ googleUserId,
12
+ pubsubTopic,
13
+ existingSubscription,
14
+ }: {
15
+ accessToken: string;
16
+ googleUserId: string;
17
+ pubsubTopic: string;
18
+ existingSubscription: MeetEventSubscription | undefined;
19
+ }): Promise<MeetEventSubscription> => {
20
+ if (!isDefined(existingSubscription)) {
21
+ return createMeetEventSubscriptionOrThrow({
22
+ accessToken,
23
+ googleUserId,
24
+ pubsubTopic,
25
+ });
26
+ }
27
+
28
+ if (
29
+ canRenewMeetEventSubscription({
30
+ subscription: existingSubscription,
31
+ pubsubTopic,
32
+ })
33
+ ) {
34
+ return renewMeetEventSubscriptionOrThrow({
35
+ accessToken,
36
+ subscriptionName: existingSubscription.name,
37
+ });
38
+ }
39
+
40
+ // Renewing only extends a subscription: it cannot change its topic or event types, or resume a suspended one.
41
+ await deleteMeetEventSubscription({
42
+ accessToken,
43
+ subscriptionName: existingSubscription.name,
44
+ });
45
+
46
+ return createMeetEventSubscriptionOrThrow({
47
+ accessToken,
48
+ googleUserId,
49
+ pubsubTopic,
50
+ });
51
+ };
@@ -0,0 +1,4 @@
1
+ const MARKDOWN_SPECIAL_CHARACTER_PATTERN = /[\\`*_[\]]/g;
2
+
3
+ export const escapeMarkdownText = (text: string): string =>
4
+ text.replace(MARKDOWN_SPECIAL_CHARACTER_PATTERN, '\\$&');
@@ -0,0 +1,2 @@
1
+ export const escapeSqlLikePattern = (value: string): string =>
2
+ value.replace(/[\\%_]/g, (wildcard) => `\\${wildcard}`);
@@ -0,0 +1,23 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+
3
+ export const extractBearerToken = (
4
+ authorizationHeader: string | undefined,
5
+ ): string | undefined => {
6
+ if (!isNonEmptyString(authorizationHeader)) {
7
+ return undefined;
8
+ }
9
+
10
+ const [scheme, token, ...otherParts] = authorizationHeader
11
+ .trim()
12
+ .split(/\s+/);
13
+
14
+ if (
15
+ scheme.toLowerCase() !== 'bearer' ||
16
+ !isNonEmptyString(token) ||
17
+ otherParts.length > 0
18
+ ) {
19
+ return undefined;
20
+ }
21
+
22
+ return token;
23
+ };
@@ -0,0 +1,16 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+
3
+ export const extractMeetNameFromDocTitle = (
4
+ docTitle: string | undefined,
5
+ ): string | undefined => {
6
+ if (!isNonEmptyString(docTitle)) {
7
+ return undefined;
8
+ }
9
+
10
+ const suffixStart = docTitle.lastIndexOf(' - ');
11
+ const meetingName = (
12
+ suffixStart === -1 ? docTitle : docTitle.slice(0, suffixStart)
13
+ ).trim();
14
+
15
+ return isNonEmptyString(meetingName) ? meetingName : undefined;
16
+ };
@@ -0,0 +1,107 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+ import { isDefined } from 'twenty-sdk/utils';
3
+
4
+ import {
5
+ MEET_REQUEST_MAX_ATTEMPTS,
6
+ MEET_REQUEST_RETRY_BASE_DELAY_MILLISECONDS,
7
+ MEET_REQUEST_RETRY_BUDGET_MILLISECONDS,
8
+ MEET_RETRYABLE_STATUSES,
9
+ } from 'src/logic-functions/constants/meet-api.constant';
10
+ import { MeetException } from 'src/logic-functions/types/meet-exception.type';
11
+ import { type GoogleRequestMethod } from 'src/logic-functions/types/google-request-method.type';
12
+ import { parseRetryAfterMilliseconds } from 'src/logic-functions/utils/parse-retry-after-milliseconds.util';
13
+ import { sleepForMilliseconds } from 'src/logic-functions/utils/sleep-for-milliseconds.util';
14
+
15
+ type MeetErrorBody = {
16
+ error?: { message?: unknown; status?: unknown };
17
+ };
18
+
19
+ type MeetRequest = {
20
+ accessToken: string;
21
+ url: string;
22
+ method?: GoogleRequestMethod;
23
+ body?: object;
24
+ };
25
+
26
+ const fetchMeetResponseWithRetriesOrThrow = async ({
27
+ accessToken,
28
+ url,
29
+ method,
30
+ body,
31
+ attempt,
32
+ waitedMilliseconds,
33
+ }: MeetRequest & {
34
+ attempt: number;
35
+ waitedMilliseconds: number;
36
+ }): Promise<Response> => {
37
+ const response = await fetch(url, {
38
+ method,
39
+ redirect: 'error',
40
+ headers: {
41
+ Authorization: `Bearer ${accessToken}`,
42
+ Accept: 'application/json',
43
+ ...(isDefined(body) ? { 'Content-Type': 'application/json' } : {}),
44
+ },
45
+ body: isDefined(body) ? JSON.stringify(body) : undefined,
46
+ });
47
+
48
+ if (response.ok) {
49
+ return response;
50
+ }
51
+
52
+ const retryDelayMilliseconds =
53
+ parseRetryAfterMilliseconds({
54
+ retryAfter: response.headers.get('Retry-After'),
55
+ now: new Date(),
56
+ }) ?? MEET_REQUEST_RETRY_BASE_DELAY_MILLISECONDS * 2 ** attempt;
57
+
58
+ if (
59
+ method !== 'POST' &&
60
+ MEET_RETRYABLE_STATUSES.has(response.status) &&
61
+ attempt + 1 < MEET_REQUEST_MAX_ATTEMPTS &&
62
+ waitedMilliseconds + retryDelayMilliseconds <=
63
+ MEET_REQUEST_RETRY_BUDGET_MILLISECONDS
64
+ ) {
65
+ await sleepForMilliseconds(retryDelayMilliseconds);
66
+
67
+ return fetchMeetResponseWithRetriesOrThrow({
68
+ accessToken,
69
+ url,
70
+ method,
71
+ body,
72
+ attempt: attempt + 1,
73
+ waitedMilliseconds: waitedMilliseconds + retryDelayMilliseconds,
74
+ });
75
+ }
76
+
77
+ const errorBody: MeetErrorBody = await response
78
+ .json()
79
+ .catch(() => ({}));
80
+ const googleStatus = isNonEmptyString(errorBody.error?.status)
81
+ ? errorBody.error.status
82
+ : undefined;
83
+ const message = isNonEmptyString(errorBody.error?.message)
84
+ ? errorBody.error.message
85
+ : response.statusText;
86
+
87
+ throw new MeetException({
88
+ message: `Google Meet request failed (${response.status}${isNonEmptyString(googleStatus) ? ` ${googleStatus}` : ''}): ${message}`,
89
+ code: 'REQUEST_FAILED',
90
+ httpStatus: response.status,
91
+ googleStatus,
92
+ });
93
+ };
94
+
95
+ export const fetchMeetJson = async <TResponse>(
96
+ request: MeetRequest,
97
+ ): Promise<TResponse> => {
98
+ const response = await fetchMeetResponseWithRetriesOrThrow({
99
+ ...request,
100
+ attempt: 0,
101
+ waitedMilliseconds: 0,
102
+ });
103
+
104
+ const responseBody: TResponse = await response.json();
105
+
106
+ return responseBody;
107
+ };
@@ -0,0 +1,38 @@
1
+ import { type CoreApiClient } from 'twenty-client-sdk/core';
2
+ import { isDefined } from 'twenty-sdk/utils';
3
+
4
+ import { type CallRecordingForSummary } from 'src/logic-functions/types/call-recording-for-summary.type';
5
+
6
+ export const findCallRecordingForSummary = async ({
7
+ coreApiClient,
8
+ callRecordingId,
9
+ }: {
10
+ coreApiClient: Pick<CoreApiClient, 'query'>;
11
+ callRecordingId: string;
12
+ }): Promise<CallRecordingForSummary | undefined> => {
13
+ const queryResult = await coreApiClient.query({
14
+ callRecordings: {
15
+ __args: { filter: { id: { eq: callRecordingId } }, first: 1 },
16
+ edges: {
17
+ node: {
18
+ id: true,
19
+ title: true,
20
+ transcript: true,
21
+ summary: { markdown: true },
22
+ },
23
+ },
24
+ },
25
+ });
26
+
27
+ const node = queryResult.callRecordings?.edges?.[0]?.node;
28
+
29
+ if (!isDefined(node)) {
30
+ return undefined;
31
+ }
32
+
33
+ return {
34
+ title: node.title ?? undefined,
35
+ transcript: node.transcript,
36
+ summaryMarkdown: node.summary?.markdown ?? undefined,
37
+ };
38
+ };
@@ -0,0 +1,25 @@
1
+ import { isNonEmptyArray } from '@sniptt/guards';
2
+ import { type CoreApiClient } from 'twenty-client-sdk/core';
3
+ import { isDefined } from 'twenty-sdk/utils';
4
+
5
+ export const findCallRecordingVideoState = async ({
6
+ coreApiClient,
7
+ callRecordingId,
8
+ }: {
9
+ coreApiClient: Pick<CoreApiClient, 'query'>;
10
+ callRecordingId: string;
11
+ }): Promise<{ hasVideo: boolean } | undefined> => {
12
+ const queryResult = await coreApiClient.query({
13
+ callRecordings: {
14
+ __args: { filter: { id: { eq: callRecordingId } }, first: 1 },
15
+ edges: { node: { id: true, video: { fileId: true } } },
16
+ },
17
+ });
18
+ const node = queryResult.callRecordings?.edges?.[0]?.node;
19
+
20
+ if (!isDefined(node)) {
21
+ return undefined;
22
+ }
23
+
24
+ return { hasVideo: isNonEmptyArray(node.video) };
25
+ };
@@ -0,0 +1,74 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+ import { type CoreApiClient } from 'twenty-client-sdk/core';
3
+ import { isDefined } from 'twenty-sdk/utils';
4
+
5
+ import { CALENDAR_EVENT_MATCHING_WINDOW_MILLISECONDS } from 'src/logic-functions/constants/calendar-event-matching.constant';
6
+ import { type CalendarEventCandidate } from 'src/logic-functions/types/calendar-event-candidate.type';
7
+ import { type MeetConferenceRecord } from 'src/logic-functions/types/meet-conference-record.type';
8
+ import { type MeetSpace } from 'src/logic-functions/types/meet-space.type';
9
+ import { listCalendarEventsInWindow } from 'src/logic-functions/utils/list-calendar-events-in-window.util';
10
+ import { normalizeMeetingUrl } from 'src/logic-functions/utils/normalize-meeting-url.util';
11
+
12
+ export const findMeetCalendarEvent = async ({
13
+ coreApiClient,
14
+ conferenceRecord,
15
+ space,
16
+ }: {
17
+ coreApiClient: Pick<CoreApiClient, 'query'>;
18
+ conferenceRecord: Pick<MeetConferenceRecord, 'startTime'>;
19
+ space: Pick<MeetSpace, 'meetingUri'>;
20
+ }): Promise<Pick<CalendarEventCandidate, 'id' | 'title'> | undefined> => {
21
+ const meetingUrl = normalizeMeetingUrl(space.meetingUri);
22
+
23
+ if (!isDefined(meetingUrl)) {
24
+ return undefined;
25
+ }
26
+
27
+ const meetingCode = meetingUrl.slice(meetingUrl.lastIndexOf('/') + 1);
28
+
29
+ if (!isNonEmptyString(meetingCode)) {
30
+ return undefined;
31
+ }
32
+
33
+ const conferenceStartMilliseconds = Date.parse(conferenceRecord.startTime);
34
+ const calendarEvents = await listCalendarEventsInWindow({
35
+ coreApiClient,
36
+ earliestStart: new Date(
37
+ conferenceStartMilliseconds - CALENDAR_EVENT_MATCHING_WINDOW_MILLISECONDS,
38
+ ).toISOString(),
39
+ latestStart: new Date(
40
+ conferenceStartMilliseconds + CALENDAR_EVENT_MATCHING_WINDOW_MILLISECONDS,
41
+ ).toISOString(),
42
+ conferenceLinkFragment: meetingCode,
43
+ });
44
+
45
+ if (!isDefined(calendarEvents)) {
46
+ return undefined;
47
+ }
48
+
49
+ const [closestCandidate, nextCandidate] = calendarEvents
50
+ .filter(
51
+ ({ conferenceLink }) =>
52
+ normalizeMeetingUrl(conferenceLink?.primaryLinkUrl) === meetingUrl,
53
+ )
54
+ .map(({ id, title, startsAt }) => ({
55
+ id,
56
+ title,
57
+ startDifference: Math.abs(
58
+ Date.parse(startsAt) - conferenceStartMilliseconds,
59
+ ),
60
+ }))
61
+ .sort(
62
+ (firstCandidate, secondCandidate) =>
63
+ firstCandidate.startDifference - secondCandidate.startDifference,
64
+ );
65
+
66
+ if (
67
+ !isDefined(closestCandidate) ||
68
+ closestCandidate.startDifference === nextCandidate?.startDifference
69
+ ) {
70
+ return undefined;
71
+ }
72
+
73
+ return { id: closestCandidate.id, title: closestCandidate.title };
74
+ };
@@ -0,0 +1,38 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+
3
+ import { type CalendarEventCandidate } from 'src/logic-functions/types/calendar-event-candidate.type';
4
+ import { type MeetSmartNote } from 'src/logic-functions/types/meet-smart-note.type';
5
+ import { type MeetTranscript } from 'src/logic-functions/types/meet-transcript.type';
6
+ import { extractMeetNameFromDocTitle } from 'src/logic-functions/utils/extract-meet-name-from-doc-title.util';
7
+ import { getGoogleDocTitle } from 'src/logic-functions/utils/get-google-doc-title.util';
8
+
9
+ export const findMeetConferenceTitle = async ({
10
+ accessToken,
11
+ calendarEvent,
12
+ artifacts,
13
+ }: {
14
+ accessToken: string;
15
+ calendarEvent: Pick<CalendarEventCandidate, 'title'> | undefined;
16
+ artifacts: Pick<
17
+ MeetTranscript | MeetSmartNote,
18
+ 'docsDestination'
19
+ >[];
20
+ }): Promise<string | undefined> => {
21
+ const calendarEventTitle = calendarEvent?.title?.trim();
22
+
23
+ if (isNonEmptyString(calendarEventTitle)) {
24
+ return calendarEventTitle;
25
+ }
26
+
27
+ const documentId = artifacts
28
+ .map(({ docsDestination }) => docsDestination?.document)
29
+ .find(isNonEmptyString);
30
+
31
+ if (!isNonEmptyString(documentId)) {
32
+ return undefined;
33
+ }
34
+
35
+ return extractMeetNameFromDocTitle(
36
+ await getGoogleDocTitle({ accessToken, documentId }),
37
+ );
38
+ };
@@ -0,0 +1,32 @@
1
+ import {
2
+ MEET_TRANSCRIPT_GENERATED_EVENT_TYPE,
3
+ GOOGLE_WORKSPACE_EVENTS_API_BASE_URL,
4
+ } from 'src/logic-functions/constants/google-workspace-events.constant';
5
+ import { type MeetCollectionPage } from 'src/logic-functions/types/meet-collection-page.type';
6
+ import { type MeetEventSubscription } from 'src/logic-functions/types/meet-event-subscription.type';
7
+ import { buildGoogleApiUrlOrThrow } from 'src/logic-functions/utils/build-google-api-url-or-throw.util';
8
+ import { buildMeetUserTargetResource } from 'src/logic-functions/utils/build-meet-user-target-resource.util';
9
+ import { fetchMeetJson } from 'src/logic-functions/utils/fetch-meet-json.util';
10
+
11
+ export const findMeetEventSubscription = async ({
12
+ accessToken,
13
+ googleUserId,
14
+ }: {
15
+ accessToken: string;
16
+ googleUserId: string;
17
+ }): Promise<MeetEventSubscription | undefined> => {
18
+ const { subscriptions } = await fetchMeetJson<
19
+ MeetCollectionPage<'subscriptions', MeetEventSubscription>
20
+ >({
21
+ accessToken,
22
+ url: buildGoogleApiUrlOrThrow({
23
+ baseUrl: GOOGLE_WORKSPACE_EVENTS_API_BASE_URL,
24
+ path: 'subscriptions',
25
+ queryParameters: {
26
+ filter: `event_types:"${MEET_TRANSCRIPT_GENERATED_EVENT_TYPE}" AND target_resource="${buildMeetUserTargetResource(googleUserId)}"`,
27
+ },
28
+ }),
29
+ });
30
+
31
+ return subscriptions?.[0];
32
+ };
@@ -0,0 +1,32 @@
1
+ import { isNonEmptyString } from '@sniptt/guards';
2
+ import { isDefined } from 'twenty-sdk/utils';
3
+
4
+ import { type MeetSmartNote } from 'src/logic-functions/types/meet-smart-note.type';
5
+ import { convertGoogleDocTabToMarkdown } from 'src/logic-functions/utils/convert-google-doc-tab-to-markdown.util';
6
+ import { getGoogleDoc } from 'src/logic-functions/utils/get-google-doc.util';
7
+
8
+ export const findMeetSmartNotesMarkdown = async ({
9
+ accessToken,
10
+ smartNotes,
11
+ }: {
12
+ accessToken: string;
13
+ smartNotes: Pick<MeetSmartNote, 'docsDestination'>[];
14
+ }): Promise<string | undefined> => {
15
+ const documentId = smartNotes
16
+ .map(({ docsDestination }) => docsDestination?.document)
17
+ .find(isNonEmptyString);
18
+
19
+ if (!isNonEmptyString(documentId)) {
20
+ return undefined;
21
+ }
22
+
23
+ const [notesTab] =
24
+ (await getGoogleDoc({ accessToken, documentId }))?.tabs ?? [];
25
+ if (!isDefined(notesTab)) {
26
+ return undefined;
27
+ }
28
+
29
+ const markdown = convertGoogleDocTabToMarkdown(notesTab);
30
+
31
+ return isNonEmptyString(markdown) ? markdown : undefined;
32
+ };
@@ -0,0 +1,20 @@
1
+ const SECONDS_PER_MINUTE = 60;
2
+ const SECONDS_PER_HOUR = 3600;
3
+
4
+ export const formatSecondsAsClockTimestamp = (totalSeconds: number): string => {
5
+ const wholeSeconds = Math.max(0, Math.floor(totalSeconds));
6
+ const hours = Math.floor(wholeSeconds / SECONDS_PER_HOUR);
7
+ const minutes = Math.floor(
8
+ (wholeSeconds % SECONDS_PER_HOUR) / SECONDS_PER_MINUTE,
9
+ );
10
+ const paddedSeconds = String(wholeSeconds % SECONDS_PER_MINUTE).padStart(
11
+ 2,
12
+ '0',
13
+ );
14
+
15
+ if (hours > 0) {
16
+ return `${hours}:${String(minutes).padStart(2, '0')}:${paddedSeconds}`;
17
+ }
18
+
19
+ return `${minutes}:${paddedSeconds}`;
20
+ };
@@ -0,0 +1,6 @@
1
+ const ARTIFACT_NAME_PATTERN =
2
+ /^(conferenceRecords\/[^/]+)\/(?:transcripts|smartNotes|recordings)\/[^/]+$/;
3
+
4
+ export const getConferenceRecordNameFromArtifactName = (
5
+ artifactName: string,
6
+ ): string | undefined => ARTIFACT_NAME_PATTERN.exec(artifactName)?.[1];
@@ -0,0 +1,18 @@
1
+ import { type AppConnection } from 'twenty-sdk/logic-function';
2
+ import { isDefined } from 'twenty-sdk/utils';
3
+
4
+ import { MeetException } from 'src/logic-functions/types/meet-exception.type';
5
+
6
+ export const getConnectionAccessTokenOrThrow = ({
7
+ id,
8
+ accessToken,
9
+ }: Pick<AppConnection, 'id' | 'accessToken'>): string => {
10
+ if (!isDefined(accessToken)) {
11
+ throw new MeetException({
12
+ message: `Connection ${id} has no access token`,
13
+ code: 'CONNECTION_WITHOUT_ACCESS_TOKEN',
14
+ });
15
+ }
16
+
17
+ return accessToken;
18
+ };
@@ -0,0 +1,31 @@
1
+ import { GOOGLE_DOCS_API_BASE_URL } from 'src/logic-functions/constants/google-docs-api.constant';
2
+ import { buildGoogleApiUrlOrThrow } from 'src/logic-functions/utils/build-google-api-url-or-throw.util';
3
+ import { fetchMeetJson } from 'src/logic-functions/utils/fetch-meet-json.util';
4
+ import { isGoogleDocUnreadableError } from 'src/logic-functions/utils/is-google-doc-unreadable-error.util';
5
+
6
+ export const getGoogleDocTitle = async ({
7
+ accessToken,
8
+ documentId,
9
+ }: {
10
+ accessToken: string;
11
+ documentId: string;
12
+ }): Promise<string | undefined> => {
13
+ try {
14
+ const document = await fetchMeetJson<{ title?: string }>({
15
+ accessToken,
16
+ url: buildGoogleApiUrlOrThrow({
17
+ baseUrl: GOOGLE_DOCS_API_BASE_URL,
18
+ path: `documents/${documentId}`,
19
+ queryParameters: { fields: 'title' },
20
+ }),
21
+ });
22
+
23
+ return document.title;
24
+ } catch (error) {
25
+ if (isGoogleDocUnreadableError(error)) {
26
+ return undefined;
27
+ }
28
+
29
+ throw error;
30
+ }
31
+ };
@@ -0,0 +1,30 @@
1
+ import { GOOGLE_DOCS_API_BASE_URL } from 'src/logic-functions/constants/google-docs-api.constant';
2
+ import { type GoogleDoc } from 'src/logic-functions/types/google-doc.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
+ import { isGoogleDocUnreadableError } from 'src/logic-functions/utils/is-google-doc-unreadable-error.util';
6
+
7
+ export const getGoogleDoc = async ({
8
+ accessToken,
9
+ documentId,
10
+ }: {
11
+ accessToken: string;
12
+ documentId: string;
13
+ }): Promise<GoogleDoc | undefined> => {
14
+ try {
15
+ return await fetchMeetJson<GoogleDoc>({
16
+ accessToken,
17
+ url: buildGoogleApiUrlOrThrow({
18
+ baseUrl: GOOGLE_DOCS_API_BASE_URL,
19
+ path: `documents/${documentId}`,
20
+ queryParameters: { includeTabsContent: 'true' },
21
+ }),
22
+ });
23
+ } catch (error) {
24
+ if (isGoogleDocUnreadableError(error)) {
25
+ return undefined;
26
+ }
27
+
28
+ throw error;
29
+ }
30
+ };
@@ -0,0 +1,31 @@
1
+ import { GOOGLE_DRIVE_API_BASE_URL } from 'src/logic-functions/constants/google-drive-api.constant';
2
+ import { MeetException } from 'src/logic-functions/types/meet-exception.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 getGoogleDriveFileSizeBytesOrThrow = async ({
7
+ accessToken,
8
+ driveFileId,
9
+ }: {
10
+ accessToken: string;
11
+ driveFileId: string;
12
+ }): Promise<number> => {
13
+ const driveFile = await fetchMeetJson<{ size?: string }>({
14
+ accessToken,
15
+ url: buildGoogleApiUrlOrThrow({
16
+ baseUrl: GOOGLE_DRIVE_API_BASE_URL,
17
+ path: `files/${driveFileId}`,
18
+ queryParameters: { fields: 'size' },
19
+ }),
20
+ });
21
+ const sizeBytes = Number(driveFile.size);
22
+
23
+ if (!Number.isSafeInteger(sizeBytes) || sizeBytes <= 0) {
24
+ throw new MeetException({
25
+ message: `Google Drive file ${driveFileId} has no readable size`,
26
+ code: 'DRIVE_FILE_SIZE_UNREADABLE',
27
+ });
28
+ }
29
+
30
+ return sizeBytes;
31
+ };