@twentyhq/teams 1.1.2 → 1.2.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/dependencies/yarn.lock +723 -3
- package/manifest.json +46 -29
- package/package.json +4 -2
- package/src/features/chat/logic-functions/teams-activities-enqueue.mjs +366 -152
- package/src/features/chat/logic-functions/teams-activities-enqueue.mjs.map +4 -4
- package/src/features/chat/logic-functions/teams-activities-enqueue.ts +1 -1
- package/src/features/chat/logic-functions/teams-activities-resolver.mjs +500 -40
- package/src/features/chat/logic-functions/teams-activities-resolver.mjs.map +4 -4
- package/src/features/chat/logic-functions/teams-activities-resolver.ts +13 -2
- package/src/features/chat/logic-functions/teams-list-unlinked-users.mjs +95 -61
- package/src/features/chat/logic-functions/teams-list-unlinked-users.mjs.map +4 -4
- package/src/features/chat/logic-functions/teams-match-user-links.mjs +105 -86
- package/src/features/chat/logic-functions/teams-match-user-links.mjs.map +4 -4
- package/src/features/chat/logic-functions/teams-register-connection.mjs +119 -101
- package/src/features/chat/logic-functions/teams-register-connection.mjs.map +4 -4
- package/src/features/chat/logic-functions/teams-register-connection.ts +1 -1
- package/src/features/chat/logic-functions/teams-search-users.mjs +96 -62
- package/src/features/chat/logic-functions/teams-search-users.mjs.map +4 -4
- package/src/features/chat/logic-functions/teams-set-user-link.mjs +88 -54
- package/src/features/chat/logic-functions/teams-set-user-link.mjs.map +4 -4
- package/src/features/chat/logic-functions/teams-tenant-release.mjs +72 -41
- package/src/features/chat/logic-functions/teams-tenant-release.mjs.map +4 -4
- package/src/features/transcripts/logic-functions/teams-count-transcript-history.mjs +99 -68
- package/src/features/transcripts/logic-functions/teams-count-transcript-history.mjs.map +4 -4
- package/src/features/transcripts/logic-functions/teams-import-transcript-history.mjs +99 -68
- package/src/features/transcripts/logic-functions/teams-import-transcript-history.mjs.map +4 -4
- package/src/features/transcripts/logic-functions/teams-import-transcript.mjs +96 -65
- package/src/features/transcripts/logic-functions/teams-import-transcript.mjs.map +4 -4
- package/src/features/transcripts/logic-functions/teams-list-organizer-transcripts.mjs +89 -58
- package/src/features/transcripts/logic-functions/teams-list-organizer-transcripts.mjs.map +4 -4
- package/src/features/transcripts/logic-functions/teams-sync-transcript.mjs +96 -65
- package/src/features/transcripts/logic-functions/teams-sync-transcript.mjs.map +4 -4
- package/src/features/transcripts/logic-functions/teams-transcript-history-count.mjs +0 -1
- package/src/features/transcripts/logic-functions/teams-transcript-history-count.mjs.map +2 -2
- package/src/features/transcripts/logic-functions/teams-transcript-history-import.mjs +0 -1
- package/src/features/transcripts/logic-functions/teams-transcript-history-import.mjs.map +2 -2
- package/src/features/transcripts/logic-functions/teams-transcript-history-status.mjs +0 -1
- package/src/features/transcripts/logic-functions/teams-transcript-history-status.mjs.map +2 -2
- package/src/features/transcripts/logic-functions/teams-transcripts-webhook.mjs +104 -73
- package/src/features/transcripts/logic-functions/teams-transcripts-webhook.mjs.map +4 -4
- package/src/features/transcripts/logic-functions/teams-uninstall.mjs +72 -41
- package/src/features/transcripts/logic-functions/teams-uninstall.mjs.map +4 -4
- package/src/front-components/settings.front-component.mjs +113 -113
- package/src/front-components/settings.front-component.mjs.map +4 -4
- package/src/logic-functions/teams-health-check.mjs +46 -25
- package/src/logic-functions/teams-health-check.mjs.map +4 -4
- package/src/logic-functions/teams-health-check.ts +21 -6
- package/src/logic-functions/teams-post-install.mjs +1270 -0
- package/src/logic-functions/teams-post-install.mjs.map +7 -0
- package/src/logic-functions/teams-post-install.ts +15 -0
|
@@ -124,10 +124,10 @@ var require_convenience = __commonJS({
|
|
|
124
124
|
return structural_1.isArray(term) && term.length > 0;
|
|
125
125
|
};
|
|
126
126
|
exports.isNonEmptyArray = isNonEmptyArray3;
|
|
127
|
-
var
|
|
127
|
+
var isNonEmptyString20 = (term) => {
|
|
128
128
|
return primitives_1.isString(term) && term.length > 0;
|
|
129
129
|
};
|
|
130
|
-
exports.isNonEmptyString =
|
|
130
|
+
exports.isNonEmptyString = isNonEmptyString20;
|
|
131
131
|
var isNumberOrNaN = (term) => {
|
|
132
132
|
return typeof term === "number";
|
|
133
133
|
};
|
|
@@ -228,7 +228,7 @@ var FAILURE_REPLY_RESERVE_SECONDS = 30;
|
|
|
228
228
|
var TEAMS_ASSISTANT_AGENT_BUDGET_SECONDS = TEAMS_ASSISTANT_REQUEST_TIMEOUT_SECONDS - FAILURE_REPLY_RESERVE_SECONDS;
|
|
229
229
|
|
|
230
230
|
// src/features/chat/logic-functions/utils/answer-teams-assistant-request.ts
|
|
231
|
-
var
|
|
231
|
+
var import_guards17 = __toESM(require_build());
|
|
232
232
|
import { CoreApiClient } from "twenty-client-sdk/core";
|
|
233
233
|
|
|
234
234
|
// src/features/chat/logic-functions/constants/teams-assistant-request-status.ts
|
|
@@ -239,6 +239,9 @@ var TEAMS_ASSISTANT_REQUEST_STATUS = {
|
|
|
239
239
|
FAILED: "FAILED"
|
|
240
240
|
};
|
|
241
241
|
|
|
242
|
+
// src/features/chat/logic-functions/constants/teams-assistant-unmatched-request-name.ts
|
|
243
|
+
var TEAMS_ASSISTANT_UNMATCHED_REQUEST_NAME = "Request from an unlinked Teams account";
|
|
244
|
+
|
|
242
245
|
// src/features/chat/logic-functions/constants/teams-assistant-unmatched-sender-text.ts
|
|
243
246
|
var TEAMS_ASSISTANT_UNMATCHED_SENDER_TEXT = "I could not match your Teams account to a member of this Twenty workspace. Ask an admin to invite you to Twenty with the same email address you use in Teams.";
|
|
244
247
|
|
|
@@ -280,7 +283,7 @@ var claimTeamsAssistantRequest = async ({
|
|
|
280
283
|
var import_guards3 = __toESM(require_build());
|
|
281
284
|
|
|
282
285
|
// src/features/chat/logic-functions/constants/teams-assistant-failure-text.ts
|
|
283
|
-
var TEAMS_ASSISTANT_FAILURE_TEXT = "
|
|
286
|
+
var TEAMS_ASSISTANT_FAILURE_TEXT = "That request failed. Try again, and if it keeps failing, an admin can find the details in Twenty.";
|
|
284
287
|
|
|
285
288
|
// src/features/chat/logic-functions/constants/teams-assistant-history-turn-limit.ts
|
|
286
289
|
var TEAMS_ASSISTANT_HISTORY_TURN_LIMIT = 10;
|
|
@@ -334,7 +337,9 @@ var updateTeamsAssistantRequest = async ({
|
|
|
334
337
|
status,
|
|
335
338
|
responseText,
|
|
336
339
|
errorMessage,
|
|
337
|
-
workspaceMemberId
|
|
340
|
+
workspaceMemberId,
|
|
341
|
+
requestText,
|
|
342
|
+
name
|
|
338
343
|
}) => {
|
|
339
344
|
await client.mutation({
|
|
340
345
|
updateTeamsAssistantRequest: {
|
|
@@ -344,7 +349,9 @@ var updateTeamsAssistantRequest = async ({
|
|
|
344
349
|
...o(status) ? { status } : {},
|
|
345
350
|
...o(responseText) ? { responseText: { blocknote: null, markdown: responseText } } : {},
|
|
346
351
|
...o(errorMessage) ? { errorMessage } : {},
|
|
347
|
-
...o(workspaceMemberId) ? { workspaceMemberId } : {}
|
|
352
|
+
...o(workspaceMemberId) ? { workspaceMemberId } : {},
|
|
353
|
+
...o(requestText) ? { requestText: { blocknote: null, markdown: requestText } } : {},
|
|
354
|
+
...o(name) ? { name } : {}
|
|
348
355
|
}
|
|
349
356
|
},
|
|
350
357
|
id: true
|
|
@@ -418,6 +425,26 @@ ${CODE_FENCE}`;
|
|
|
418
425
|
return `${keptText}${hasOpenCodeFence(keptText) ? closingFence : ""}${notice}`;
|
|
419
426
|
};
|
|
420
427
|
|
|
428
|
+
// src/features/chat/logic-functions/utils/build-teams-assistant-request-name.ts
|
|
429
|
+
var TEAMS_ASSISTANT_REQUEST_NAME_MAX_LENGTH = 60;
|
|
430
|
+
var graphemeSegmenter = new Intl.Segmenter(void 0, {
|
|
431
|
+
granularity: "grapheme"
|
|
432
|
+
});
|
|
433
|
+
var countCodePoints = (text) => [...text].length;
|
|
434
|
+
var buildTeamsAssistantRequestName = (requestText) => {
|
|
435
|
+
if (countCodePoints(requestText) <= TEAMS_ASSISTANT_REQUEST_NAME_MAX_LENGTH) {
|
|
436
|
+
return requestText;
|
|
437
|
+
}
|
|
438
|
+
const { truncatedText } = Array.from(
|
|
439
|
+
graphemeSegmenter.segment(requestText),
|
|
440
|
+
({ segment }) => segment
|
|
441
|
+
).reduce(
|
|
442
|
+
({ truncatedText: truncatedText2, isFull }, grapheme) => isFull || countCodePoints(truncatedText2 + grapheme) >= TEAMS_ASSISTANT_REQUEST_NAME_MAX_LENGTH ? { truncatedText: truncatedText2, isFull: true } : { truncatedText: truncatedText2 + grapheme, isFull: false },
|
|
443
|
+
{ truncatedText: "", isFull: false }
|
|
444
|
+
);
|
|
445
|
+
return `${truncatedText}\u2026`;
|
|
446
|
+
};
|
|
447
|
+
|
|
421
448
|
// src/features/chat/logic-functions/utils/fetch-workspace-base-url.ts
|
|
422
449
|
var import_guards5 = __toESM(require_build());
|
|
423
450
|
import { MetadataApiClient } from "twenty-client-sdk/metadata";
|
|
@@ -750,7 +777,7 @@ var getTeamsConnectorAccessTokenOrThrow = async () => {
|
|
|
750
777
|
};
|
|
751
778
|
|
|
752
779
|
// src/features/chat/logic-functions/utils/resolve-teams-sender-workspace-member-id.ts
|
|
753
|
-
var
|
|
780
|
+
var import_guards14 = __toESM(require_build());
|
|
754
781
|
|
|
755
782
|
// src/features/chat/logic-functions/constants/teams-user-link-source.ts
|
|
756
783
|
var TEAMS_USER_LINK_SOURCE = {
|
|
@@ -853,19 +880,66 @@ var parseTeamsConnectorResponseOrThrow = ({
|
|
|
853
880
|
};
|
|
854
881
|
|
|
855
882
|
// src/features/chat/logic-functions/utils/request-teams-connector.ts
|
|
856
|
-
var
|
|
883
|
+
var import_guards13 = __toESM(require_build());
|
|
884
|
+
|
|
885
|
+
// src/features/chat/logic-functions/constants/teams-connector-idempotent-retryable-statuses.ts
|
|
886
|
+
var TEAMS_CONNECTOR_IDEMPOTENT_RETRYABLE_STATUSES = /* @__PURE__ */ new Set([
|
|
887
|
+
502,
|
|
888
|
+
504
|
|
889
|
+
]);
|
|
890
|
+
|
|
891
|
+
// src/features/chat/logic-functions/constants/teams-connector-request-max-attempts.ts
|
|
892
|
+
var TEAMS_CONNECTOR_REQUEST_MAX_ATTEMPTS = 3;
|
|
857
893
|
|
|
858
894
|
// src/features/chat/logic-functions/constants/teams-connector-request-timeout-ms.ts
|
|
859
895
|
var TEAMS_CONNECTOR_REQUEST_TIMEOUT_MS = 1e4;
|
|
860
896
|
|
|
897
|
+
// src/features/chat/logic-functions/constants/teams-connector-retry-max-total-wait-ms.ts
|
|
898
|
+
var TEAMS_CONNECTOR_RETRY_MAX_TOTAL_WAIT_MS = 4e3;
|
|
899
|
+
|
|
900
|
+
// src/features/chat/logic-functions/constants/teams-connector-retryable-statuses.ts
|
|
901
|
+
var TEAMS_CONNECTOR_RETRYABLE_STATUSES = /* @__PURE__ */ new Set([412, 429, 503]);
|
|
902
|
+
|
|
903
|
+
// src/features/chat/logic-functions/types/teams-connector-request-error.ts
|
|
904
|
+
var TeamsConnectorRequestError = class extends Error {
|
|
905
|
+
constructor({ message, status }) {
|
|
906
|
+
super(message);
|
|
907
|
+
this.name = "TeamsConnectorRequestError";
|
|
908
|
+
this.status = status;
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
|
|
912
|
+
// src/features/chat/logic-functions/constants/teams-connector-retry-base-delay-ms.ts
|
|
913
|
+
var TEAMS_CONNECTOR_RETRY_BASE_DELAY_MS = 1e3;
|
|
914
|
+
|
|
915
|
+
// src/features/chat/logic-functions/constants/teams-connector-retry-jitter-ratio.ts
|
|
916
|
+
var TEAMS_CONNECTOR_RETRY_JITTER_RATIO = 0.25;
|
|
917
|
+
|
|
918
|
+
// src/features/chat/logic-functions/utils/get-teams-connector-retry-delay-ms.ts
|
|
919
|
+
var getTeamsConnectorRetryDelayMs = ({
|
|
920
|
+
attempt,
|
|
921
|
+
retryAfterMs,
|
|
922
|
+
maxDelayMs
|
|
923
|
+
}) => {
|
|
924
|
+
if (o(retryAfterMs)) {
|
|
925
|
+
const delayMs = Math.max(retryAfterMs, TEAMS_CONNECTOR_RETRY_BASE_DELAY_MS);
|
|
926
|
+
return delayMs > maxDelayMs ? 0 : delayMs;
|
|
927
|
+
}
|
|
928
|
+
const backoffMs = TEAMS_CONNECTOR_RETRY_BASE_DELAY_MS * 2 ** attempt;
|
|
929
|
+
return Math.min(
|
|
930
|
+
backoffMs * (1 + Math.random() * TEAMS_CONNECTOR_RETRY_JITTER_RATIO),
|
|
931
|
+
maxDelayMs
|
|
932
|
+
);
|
|
933
|
+
};
|
|
934
|
+
|
|
861
935
|
// src/features/chat/logic-functions/constants/teams-connector-service-url-host-suffixes.ts
|
|
862
|
-
var TEAMS_CONNECTOR_SERVICE_URL_HOST_SUFFIXES = [
|
|
863
|
-
".botframework.com",
|
|
864
|
-
".botframework.azure.us"
|
|
865
|
-
];
|
|
936
|
+
var TEAMS_CONNECTOR_SERVICE_URL_HOST_SUFFIXES = [".botframework.com"];
|
|
866
937
|
|
|
867
938
|
// src/features/chat/logic-functions/constants/teams-connector-service-url-hosts.ts
|
|
868
|
-
var TEAMS_CONNECTOR_SERVICE_URL_HOSTS = [
|
|
939
|
+
var TEAMS_CONNECTOR_SERVICE_URL_HOSTS = [
|
|
940
|
+
"smba.trafficmanager.net",
|
|
941
|
+
"smba.infra.gcc.teams.microsoft.com"
|
|
942
|
+
];
|
|
869
943
|
|
|
870
944
|
// src/features/chat/logic-functions/utils/is-teams-connector-service-url.ts
|
|
871
945
|
var isTeamsConnectorServiceUrl = (serviceUrl) => {
|
|
@@ -889,13 +963,65 @@ var normalizeTeamsServiceUrl = (serviceUrl) => {
|
|
|
889
963
|
}
|
|
890
964
|
};
|
|
891
965
|
|
|
966
|
+
// src/utils/parse-retry-after-ms.ts
|
|
967
|
+
var import_guards12 = __toESM(require_build());
|
|
968
|
+
var parseRetryAfterMs = (retryAfter) => {
|
|
969
|
+
if (!(0, import_guards12.isNonEmptyString)(retryAfter)) {
|
|
970
|
+
return void 0;
|
|
971
|
+
}
|
|
972
|
+
const retryAfterSeconds = Number(retryAfter);
|
|
973
|
+
if (Number.isFinite(retryAfterSeconds)) {
|
|
974
|
+
return Math.max(retryAfterSeconds * 1e3, 0);
|
|
975
|
+
}
|
|
976
|
+
const retryAtMs = Date.parse(retryAfter);
|
|
977
|
+
return Number.isNaN(retryAtMs) ? void 0 : Math.max(retryAtMs - Date.now(), 0);
|
|
978
|
+
};
|
|
979
|
+
|
|
980
|
+
// src/utils/sleep-for-milliseconds.ts
|
|
981
|
+
var sleepForMilliseconds = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
982
|
+
|
|
983
|
+
// src/utils/fetch-with-retries.ts
|
|
984
|
+
var fetchWithRetries = async ({
|
|
985
|
+
sendRequest,
|
|
986
|
+
maxAttempts,
|
|
987
|
+
isRetryableStatus,
|
|
988
|
+
getRetryDelayMs,
|
|
989
|
+
retryAbortSignal
|
|
990
|
+
}) => {
|
|
991
|
+
const sendAttempt = async ({
|
|
992
|
+
attempt,
|
|
993
|
+
waitedMs
|
|
994
|
+
}) => {
|
|
995
|
+
const response = await sendRequest();
|
|
996
|
+
if (response.ok || !isRetryableStatus(response.status) || attempt + 1 >= maxAttempts) {
|
|
997
|
+
return response;
|
|
998
|
+
}
|
|
999
|
+
const delayMs = getRetryDelayMs({
|
|
1000
|
+
attempt,
|
|
1001
|
+
retryAfterMs: parseRetryAfterMs(response.headers.get("retry-after")),
|
|
1002
|
+
waitedMs
|
|
1003
|
+
});
|
|
1004
|
+
if (!o(delayMs)) {
|
|
1005
|
+
return response;
|
|
1006
|
+
}
|
|
1007
|
+
await sleepForMilliseconds(delayMs);
|
|
1008
|
+
if (o(retryAbortSignal) && retryAbortSignal.aborted) {
|
|
1009
|
+
return response;
|
|
1010
|
+
}
|
|
1011
|
+
await response.body?.cancel();
|
|
1012
|
+
return sendAttempt({ attempt: attempt + 1, waitedMs: waitedMs + delayMs });
|
|
1013
|
+
};
|
|
1014
|
+
return sendAttempt({ attempt: 0, waitedMs: 0 });
|
|
1015
|
+
};
|
|
1016
|
+
|
|
892
1017
|
// src/features/chat/logic-functions/utils/request-teams-connector.ts
|
|
893
1018
|
var requestTeamsConnector = async ({
|
|
894
1019
|
serviceUrl,
|
|
895
1020
|
path,
|
|
896
1021
|
method,
|
|
897
1022
|
accessToken,
|
|
898
|
-
body
|
|
1023
|
+
body,
|
|
1024
|
+
retryAbortSignal
|
|
899
1025
|
}) => {
|
|
900
1026
|
const normalizedServiceUrl = normalizeTeamsServiceUrl(serviceUrl);
|
|
901
1027
|
if (!isTeamsConnectorServiceUrl(normalizedServiceUrl)) {
|
|
@@ -903,22 +1029,37 @@ var requestTeamsConnector = async ({
|
|
|
903
1029
|
`Refused to send the bot credentials to ${normalizedServiceUrl}, which is not a Bot Connector host`
|
|
904
1030
|
);
|
|
905
1031
|
}
|
|
906
|
-
const
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
1032
|
+
const deadlineAtMs = Date.now() + TEAMS_CONNECTOR_REQUEST_TIMEOUT_MS;
|
|
1033
|
+
const response = await fetchWithRetries({
|
|
1034
|
+
sendRequest: () => fetch(`${normalizedServiceUrl}${path}`, {
|
|
1035
|
+
method,
|
|
1036
|
+
headers: {
|
|
1037
|
+
authorization: `Bearer ${accessToken}`,
|
|
1038
|
+
...o(body) ? { "content-type": "application/json" } : {}
|
|
1039
|
+
},
|
|
1040
|
+
...o(body) ? { body: JSON.stringify(body) } : {},
|
|
1041
|
+
signal: AbortSignal.timeout(Math.max(deadlineAtMs - Date.now(), 1))
|
|
1042
|
+
}),
|
|
1043
|
+
maxAttempts: TEAMS_CONNECTOR_REQUEST_MAX_ATTEMPTS,
|
|
1044
|
+
isRetryableStatus: (status) => TEAMS_CONNECTOR_RETRYABLE_STATUSES.has(status) || method !== "POST" && TEAMS_CONNECTOR_IDEMPOTENT_RETRYABLE_STATUSES.has(status),
|
|
1045
|
+
getRetryDelayMs: ({ attempt, retryAfterMs, waitedMs }) => {
|
|
1046
|
+
const delayMs = getTeamsConnectorRetryDelayMs({
|
|
1047
|
+
attempt,
|
|
1048
|
+
retryAfterMs,
|
|
1049
|
+
maxDelayMs: TEAMS_CONNECTOR_RETRY_MAX_TOTAL_WAIT_MS - waitedMs
|
|
1050
|
+
});
|
|
1051
|
+
return delayMs <= 0 || Date.now() + delayMs >= deadlineAtMs ? void 0 : delayMs;
|
|
911
1052
|
},
|
|
912
|
-
|
|
913
|
-
signal: AbortSignal.timeout(TEAMS_CONNECTOR_REQUEST_TIMEOUT_MS)
|
|
1053
|
+
retryAbortSignal
|
|
914
1054
|
});
|
|
915
1055
|
const responseBody = await response.text();
|
|
916
|
-
if (
|
|
917
|
-
|
|
918
|
-
`Bot Connector ${method} ${path} failed: ${response.status} ${response.statusText}${(0, import_guards12.isNonEmptyString)(responseBody) ? ` - ${responseBody}` : ""}`
|
|
919
|
-
);
|
|
1056
|
+
if (response.ok) {
|
|
1057
|
+
return responseBody;
|
|
920
1058
|
}
|
|
921
|
-
|
|
1059
|
+
throw new TeamsConnectorRequestError({
|
|
1060
|
+
message: `Bot Connector ${method} ${path} failed: ${response.status} ${response.statusText}${(0, import_guards13.isNonEmptyString)(responseBody) ? ` - ${responseBody}` : ""}`,
|
|
1061
|
+
status: response.status
|
|
1062
|
+
});
|
|
922
1063
|
};
|
|
923
1064
|
|
|
924
1065
|
// src/features/chat/logic-functions/utils/request-teams-connector-json.ts
|
|
@@ -964,7 +1105,7 @@ var resolveTeamsSenderWorkspaceMemberId = async ({
|
|
|
964
1105
|
return void 0;
|
|
965
1106
|
}
|
|
966
1107
|
const teamsUserAadObjectId = member.objectId;
|
|
967
|
-
if ((0,
|
|
1108
|
+
if ((0, import_guards14.isNonEmptyString)(teamsUserAadObjectId)) {
|
|
968
1109
|
const linkedWorkspaceMemberId = await findTeamsUserLinkWorkspaceMemberId({
|
|
969
1110
|
client,
|
|
970
1111
|
teamsTenantId,
|
|
@@ -974,7 +1115,7 @@ var resolveTeamsSenderWorkspaceMemberId = async ({
|
|
|
974
1115
|
return linkedWorkspaceMemberId;
|
|
975
1116
|
}
|
|
976
1117
|
}
|
|
977
|
-
const email = [member.email, member.userPrincipalName].find(
|
|
1118
|
+
const email = [member.email, member.userPrincipalName].find(import_guards14.isNonEmptyString);
|
|
978
1119
|
if (!o(email)) {
|
|
979
1120
|
return void 0;
|
|
980
1121
|
}
|
|
@@ -982,7 +1123,7 @@ var resolveTeamsSenderWorkspaceMemberId = async ({
|
|
|
982
1123
|
client,
|
|
983
1124
|
email
|
|
984
1125
|
});
|
|
985
|
-
if (o(workspaceMemberId) && (0,
|
|
1126
|
+
if (o(workspaceMemberId) && (0, import_guards14.isNonEmptyString)(teamsUserAadObjectId)) {
|
|
986
1127
|
await createTeamsUserLink({
|
|
987
1128
|
client,
|
|
988
1129
|
name: member.name,
|
|
@@ -1001,12 +1142,12 @@ var resolveTeamsSenderWorkspaceMemberId = async ({
|
|
|
1001
1142
|
};
|
|
1002
1143
|
|
|
1003
1144
|
// src/features/chat/logic-functions/utils/run-teams-assistant-agent-or-throw.ts
|
|
1004
|
-
var
|
|
1145
|
+
var import_guards16 = __toESM(require_build());
|
|
1005
1146
|
|
|
1006
1147
|
// src/features/chat/logic-functions/utils/build-teams-assistant-messages.ts
|
|
1007
|
-
var
|
|
1148
|
+
var import_guards15 = __toESM(require_build());
|
|
1008
1149
|
var buildRecordReferenceSection = (workspaceBaseUrl) => {
|
|
1009
|
-
if (!(0,
|
|
1150
|
+
if (!(0, import_guards15.isNonEmptyString)(workspaceBaseUrl)) {
|
|
1010
1151
|
return "This workspace URL could not be resolved, so record links are unavailable. Name records in plain text and never write a Twenty URL, not even a guessed one.";
|
|
1011
1152
|
}
|
|
1012
1153
|
return [
|
|
@@ -1088,7 +1229,7 @@ var runTeamsAssistantAgentOrThrow = async ({
|
|
|
1088
1229
|
throw new Error(agentResult.error ?? "Agent run failed");
|
|
1089
1230
|
}
|
|
1090
1231
|
const responseText = hasResponseText(agentResult.result) ? agentResult.result.response.trim() : "";
|
|
1091
|
-
if (!(0,
|
|
1232
|
+
if (!(0, import_guards16.isNonEmptyString)(responseText)) {
|
|
1092
1233
|
throw new TeamsAssistantEmptyResponseError(
|
|
1093
1234
|
"Agent returned an empty response"
|
|
1094
1235
|
);
|
|
@@ -1142,6 +1283,7 @@ var startTeamsAssistantStream = async ({
|
|
|
1142
1283
|
text
|
|
1143
1284
|
}) => {
|
|
1144
1285
|
let streamSequence = 1;
|
|
1286
|
+
const streamClosing = new AbortController();
|
|
1145
1287
|
const { id: streamId } = await sendTeamsActivity({
|
|
1146
1288
|
serviceUrl,
|
|
1147
1289
|
conversationId,
|
|
@@ -1154,36 +1296,48 @@ var startTeamsAssistantStream = async ({
|
|
|
1154
1296
|
]
|
|
1155
1297
|
}
|
|
1156
1298
|
});
|
|
1157
|
-
const sendStreamActivity = async (
|
|
1299
|
+
const sendStreamActivity = async ({
|
|
1300
|
+
activity,
|
|
1301
|
+
retryAbortSignal
|
|
1302
|
+
}) => {
|
|
1158
1303
|
await requestTeamsConnector({
|
|
1159
1304
|
serviceUrl,
|
|
1160
1305
|
path: buildTeamsActivityPath({ conversationId }),
|
|
1161
1306
|
method: "POST",
|
|
1162
1307
|
accessToken: await getTeamsConnectorAccessTokenOrThrow(),
|
|
1163
|
-
body: activity
|
|
1308
|
+
body: activity,
|
|
1309
|
+
retryAbortSignal
|
|
1164
1310
|
});
|
|
1165
1311
|
};
|
|
1166
1312
|
return {
|
|
1167
1313
|
update: (text2) => {
|
|
1168
1314
|
streamSequence += 1;
|
|
1169
1315
|
return sendStreamActivity({
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1316
|
+
activity: {
|
|
1317
|
+
type: "typing",
|
|
1318
|
+
text: text2,
|
|
1319
|
+
entities: [
|
|
1320
|
+
{
|
|
1321
|
+
type: "streaminfo",
|
|
1322
|
+
streamId,
|
|
1323
|
+
streamType: "informative",
|
|
1324
|
+
streamSequence
|
|
1325
|
+
}
|
|
1326
|
+
]
|
|
1327
|
+
},
|
|
1328
|
+
retryAbortSignal: streamClosing.signal
|
|
1180
1329
|
});
|
|
1181
1330
|
},
|
|
1182
|
-
finish: (text2) =>
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1331
|
+
finish: (text2) => {
|
|
1332
|
+
streamClosing.abort();
|
|
1333
|
+
return sendStreamActivity({
|
|
1334
|
+
activity: {
|
|
1335
|
+
type: "message",
|
|
1336
|
+
text: text2,
|
|
1337
|
+
entities: [{ type: "streaminfo", streamId, streamType: "final" }]
|
|
1338
|
+
}
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1187
1341
|
};
|
|
1188
1342
|
};
|
|
1189
1343
|
|
|
@@ -1286,7 +1440,7 @@ var answerTeamsAssistantRequest = async ({
|
|
|
1286
1440
|
teamsTenantId,
|
|
1287
1441
|
requestText
|
|
1288
1442
|
} = request;
|
|
1289
|
-
if (!(0,
|
|
1443
|
+
if (!(0, import_guards17.isNonEmptyString)(teamsServiceUrl) || !(0, import_guards17.isNonEmptyString)(teamsConversationId) || !(0, import_guards17.isNonEmptyString)(teamsConversationType) || !(0, import_guards17.isNonEmptyString)(teamsUserId) || !(0, import_guards17.isNonEmptyString)(teamsTenantId) || !(0, import_guards17.isNonEmptyString)(requestText)) {
|
|
1290
1444
|
return { status: "skipped", reason: "Request record is missing fields" };
|
|
1291
1445
|
}
|
|
1292
1446
|
const client = new CoreApiClient();
|
|
@@ -1313,14 +1467,17 @@ var answerTeamsAssistantRequest = async ({
|
|
|
1313
1467
|
client,
|
|
1314
1468
|
id: request.id,
|
|
1315
1469
|
status: TEAMS_ASSISTANT_REQUEST_STATUS.DONE,
|
|
1316
|
-
responseText: TEAMS_ASSISTANT_UNMATCHED_SENDER_TEXT
|
|
1470
|
+
responseText: TEAMS_ASSISTANT_UNMATCHED_SENDER_TEXT,
|
|
1471
|
+
name: TEAMS_ASSISTANT_UNMATCHED_REQUEST_NAME
|
|
1317
1472
|
}).catch(() => void 0);
|
|
1318
1473
|
return { status: "declined", reason: "Sender is not a workspace member" };
|
|
1319
1474
|
}
|
|
1320
1475
|
await updateTeamsAssistantRequest({
|
|
1321
1476
|
client,
|
|
1322
1477
|
id: request.id,
|
|
1323
|
-
workspaceMemberId
|
|
1478
|
+
workspaceMemberId,
|
|
1479
|
+
requestText,
|
|
1480
|
+
name: buildTeamsAssistantRequestName(requestText)
|
|
1324
1481
|
});
|
|
1325
1482
|
const [history, workspaceBaseUrl] = await Promise.all([
|
|
1326
1483
|
findTeamsAssistantHistory({
|
|
@@ -1370,31 +1527,35 @@ var answerTeamsAssistantRequest = async ({
|
|
|
1370
1527
|
}
|
|
1371
1528
|
};
|
|
1372
1529
|
|
|
1530
|
+
// src/features/chat/logic-functions/constants/teams-assistant-chat-off-text.ts
|
|
1531
|
+
var TEAMS_ASSISTANT_CHAT_OFF_TEXT = "Chat is turned off for your Twenty workspace. Ask a Twenty admin to turn on Enable chat in Settings > Applications > Teams.";
|
|
1532
|
+
|
|
1533
|
+
// src/features/chat/logic-functions/constants/teams-assistant-help-text.ts
|
|
1534
|
+
var TEAMS_ASSISTANT_HELP_TEXT = [
|
|
1535
|
+
"Hi! Ask me anything about your CRM, for example:",
|
|
1536
|
+
[
|
|
1537
|
+
'- "How many open opportunities are in the pipeline?"',
|
|
1538
|
+
'- "What deals are closing this month?"',
|
|
1539
|
+
'- "Create a task to follow up on my newest lead"'
|
|
1540
|
+
].join("\n"),
|
|
1541
|
+
"Mention me with your question, or send it to me in a personal chat.",
|
|
1542
|
+
"My answers are generated by AI. Check anything important in Twenty."
|
|
1543
|
+
].join("\n\n");
|
|
1544
|
+
|
|
1545
|
+
// src/features/chat/logic-functions/constants/teams-assistant-notice-ttl-ms.ts
|
|
1546
|
+
var TEAMS_ASSISTANT_NOTICE_TTL_MS = 60 * 60 * 1e3;
|
|
1547
|
+
|
|
1548
|
+
// src/features/chat/logic-functions/constants/teams-assistant-welcome-ttl-ms.ts
|
|
1549
|
+
var TEAMS_ASSISTANT_WELCOME_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
1550
|
+
|
|
1373
1551
|
// src/features/chat/logic-functions/utils/enqueue-teams-assistant-request-record.ts
|
|
1374
1552
|
import { CoreApiClient as CoreApiClient2 } from "twenty-client-sdk/core";
|
|
1375
1553
|
|
|
1376
1554
|
// src/features/chat/logic-functions/data/create-teams-assistant-request.ts
|
|
1377
|
-
var
|
|
1555
|
+
var import_guards18 = __toESM(require_build());
|
|
1378
1556
|
|
|
1379
|
-
// src/features/chat/logic-functions/
|
|
1380
|
-
var
|
|
1381
|
-
var graphemeSegmenter = new Intl.Segmenter(void 0, {
|
|
1382
|
-
granularity: "grapheme"
|
|
1383
|
-
});
|
|
1384
|
-
var countCodePoints = (text) => [...text].length;
|
|
1385
|
-
var buildTeamsAssistantRequestName = (requestText) => {
|
|
1386
|
-
if (countCodePoints(requestText) <= TEAMS_ASSISTANT_REQUEST_NAME_MAX_LENGTH) {
|
|
1387
|
-
return requestText;
|
|
1388
|
-
}
|
|
1389
|
-
const { truncatedText } = Array.from(
|
|
1390
|
-
graphemeSegmenter.segment(requestText),
|
|
1391
|
-
({ segment }) => segment
|
|
1392
|
-
).reduce(
|
|
1393
|
-
({ truncatedText: truncatedText2, isFull }, grapheme) => isFull || countCodePoints(truncatedText2 + grapheme) >= TEAMS_ASSISTANT_REQUEST_NAME_MAX_LENGTH ? { truncatedText: truncatedText2, isFull: true } : { truncatedText: truncatedText2 + grapheme, isFull: false },
|
|
1394
|
-
{ truncatedText: "", isFull: false }
|
|
1395
|
-
);
|
|
1396
|
-
return `${truncatedText}\u2026`;
|
|
1397
|
-
};
|
|
1557
|
+
// src/features/chat/logic-functions/constants/teams-assistant-pending-request-name.ts
|
|
1558
|
+
var TEAMS_ASSISTANT_PENDING_REQUEST_NAME = "Teams request";
|
|
1398
1559
|
|
|
1399
1560
|
// src/features/chat/logic-functions/data/create-teams-assistant-request.ts
|
|
1400
1561
|
var createTeamsAssistantRequest = async ({
|
|
@@ -1406,15 +1567,14 @@ var createTeamsAssistantRequest = async ({
|
|
|
1406
1567
|
__args: {
|
|
1407
1568
|
data: {
|
|
1408
1569
|
...draft,
|
|
1409
|
-
name:
|
|
1410
|
-
requestText: { blocknote: null, markdown: draft.requestText }
|
|
1570
|
+
name: TEAMS_ASSISTANT_PENDING_REQUEST_NAME
|
|
1411
1571
|
}
|
|
1412
1572
|
},
|
|
1413
1573
|
id: true
|
|
1414
1574
|
}
|
|
1415
1575
|
});
|
|
1416
1576
|
const requestId = mutationResult.createTeamsAssistantRequest?.id;
|
|
1417
|
-
if (!(0,
|
|
1577
|
+
if (!(0, import_guards18.isNonEmptyString)(requestId)) {
|
|
1418
1578
|
throw new Error("createTeamsAssistantRequest did not return an id");
|
|
1419
1579
|
}
|
|
1420
1580
|
return requestId;
|
|
@@ -1446,17 +1606,12 @@ var findTeamsAssistantRequestByTeamsActivity = async ({
|
|
|
1446
1606
|
teamsTenantId: true,
|
|
1447
1607
|
teamsUserId: true,
|
|
1448
1608
|
teamsUserAadObjectId: true,
|
|
1449
|
-
requestText: { markdown: true },
|
|
1450
1609
|
updatedAt: true
|
|
1451
1610
|
}
|
|
1452
1611
|
}
|
|
1453
1612
|
}
|
|
1454
1613
|
});
|
|
1455
|
-
|
|
1456
|
-
if (!o(node)) {
|
|
1457
|
-
return void 0;
|
|
1458
|
-
}
|
|
1459
|
-
return { ...node, requestText: node.requestText?.markdown ?? void 0 };
|
|
1614
|
+
return queryResult.teamsAssistantRequests?.edges?.[0]?.node ?? void 0;
|
|
1460
1615
|
};
|
|
1461
1616
|
|
|
1462
1617
|
// src/features/chat/logic-functions/utils/is-duplicate-record-error.ts
|
|
@@ -1464,12 +1619,12 @@ var DUPLICATE_RECORD_MESSAGE_PATTERN = /duplicate (entry|key)/i;
|
|
|
1464
1619
|
var isDuplicateRecordError = (error) => error instanceof Error && DUPLICATE_RECORD_MESSAGE_PATTERN.test(error.message);
|
|
1465
1620
|
|
|
1466
1621
|
// src/features/chat/logic-functions/utils/is-teams-assistant-request-resumable.ts
|
|
1467
|
-
var
|
|
1622
|
+
var import_guards19 = __toESM(require_build());
|
|
1468
1623
|
var isTeamsAssistantRequestResumable = (record, { nowMs = Date.now() } = {}) => {
|
|
1469
1624
|
if (record.status === TEAMS_ASSISTANT_REQUEST_STATUS.PENDING) {
|
|
1470
1625
|
return true;
|
|
1471
1626
|
}
|
|
1472
|
-
if (record.status !== TEAMS_ASSISTANT_REQUEST_STATUS.PROCESSING || !(0,
|
|
1627
|
+
if (record.status !== TEAMS_ASSISTANT_REQUEST_STATUS.PROCESSING || !(0, import_guards19.isNonEmptyString)(record.updatedAt)) {
|
|
1473
1628
|
return false;
|
|
1474
1629
|
}
|
|
1475
1630
|
return new Date(record.updatedAt).getTime() < nowMs - TEAMS_ASSISTANT_REQUEST_TIMEOUT_SECONDS * 1e3;
|
|
@@ -1477,7 +1632,10 @@ var isTeamsAssistantRequestResumable = (record, { nowMs = Date.now() } = {}) =>
|
|
|
1477
1632
|
|
|
1478
1633
|
// src/features/chat/logic-functions/utils/enqueue-teams-assistant-request-record.ts
|
|
1479
1634
|
var ALREADY_QUEUED_SKIP_REASON = "Teams activity is already queued";
|
|
1480
|
-
var resolveExistingRequest = (
|
|
1635
|
+
var resolveExistingRequest = ({
|
|
1636
|
+
existingRequest,
|
|
1637
|
+
requestText
|
|
1638
|
+
}) => o(existingRequest) && isTeamsAssistantRequestResumable(existingRequest) ? { ok: true, request: { ...existingRequest, requestText } } : { ok: true, skipped: ALREADY_QUEUED_SKIP_REASON };
|
|
1481
1639
|
var enqueueTeamsAssistantRequestRecord = async (request) => {
|
|
1482
1640
|
const client = new CoreApiClient2();
|
|
1483
1641
|
const teamsActivityLookup = {
|
|
@@ -1486,13 +1644,14 @@ var enqueueTeamsAssistantRequestRecord = async (request) => {
|
|
|
1486
1644
|
teamsActivityId: request.teamsActivityId
|
|
1487
1645
|
};
|
|
1488
1646
|
const existingRequest = await findTeamsAssistantRequestByTeamsActivity(teamsActivityLookup);
|
|
1647
|
+
const { requestText, ...draftWithoutText } = request;
|
|
1489
1648
|
if (o(existingRequest)) {
|
|
1490
|
-
return resolveExistingRequest(existingRequest);
|
|
1649
|
+
return resolveExistingRequest({ existingRequest, requestText });
|
|
1491
1650
|
}
|
|
1492
1651
|
try {
|
|
1493
1652
|
const requestId = await createTeamsAssistantRequest({
|
|
1494
1653
|
client,
|
|
1495
|
-
draft:
|
|
1654
|
+
draft: draftWithoutText
|
|
1496
1655
|
});
|
|
1497
1656
|
return {
|
|
1498
1657
|
ok: true,
|
|
@@ -1504,46 +1663,48 @@ var enqueueTeamsAssistantRequestRecord = async (request) => {
|
|
|
1504
1663
|
};
|
|
1505
1664
|
} catch (error) {
|
|
1506
1665
|
if (isDuplicateRecordError(error)) {
|
|
1507
|
-
return resolveExistingRequest(
|
|
1508
|
-
await findTeamsAssistantRequestByTeamsActivity(teamsActivityLookup)
|
|
1509
|
-
|
|
1666
|
+
return resolveExistingRequest({
|
|
1667
|
+
existingRequest: await findTeamsAssistantRequestByTeamsActivity(teamsActivityLookup),
|
|
1668
|
+
requestText
|
|
1669
|
+
});
|
|
1510
1670
|
}
|
|
1511
1671
|
throw error;
|
|
1512
1672
|
}
|
|
1513
1673
|
};
|
|
1514
1674
|
|
|
1515
|
-
// src/constants/release-flags.ts
|
|
1516
|
-
var RELEASE_FLAGS = {
|
|
1517
|
-
IS_CHAT_ASSISTANT_RELEASED: false,
|
|
1518
|
-
IS_TRANSCRIPT_HISTORY_IMPORT_RELEASED: false
|
|
1519
|
-
};
|
|
1520
|
-
|
|
1521
1675
|
// src/features/chat/constants/chat-enabled-application-variable-key.ts
|
|
1522
1676
|
var CHAT_ENABLED_APPLICATION_VARIABLE_KEY = "TEAMS_CHAT_ENABLED";
|
|
1523
1677
|
|
|
1524
|
-
// src/utils/is-feature-enabled.ts
|
|
1525
|
-
var isFeatureEnabled = ({
|
|
1526
|
-
isAvailable,
|
|
1527
|
-
settingValue
|
|
1528
|
-
}) => isAvailable && settingValue === "true";
|
|
1529
|
-
|
|
1530
1678
|
// src/features/chat/logic-functions/utils/is-teams-chat-enabled.ts
|
|
1531
|
-
var isTeamsChatEnabled = () =>
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1679
|
+
var isTeamsChatEnabled = () => process.env[CHAT_ENABLED_APPLICATION_VARIABLE_KEY] === "true";
|
|
1680
|
+
|
|
1681
|
+
// src/features/chat/logic-functions/constants/teams-assistant-help-requests.ts
|
|
1682
|
+
var TEAMS_ASSISTANT_HELP_REQUESTS = /* @__PURE__ */ new Set([
|
|
1683
|
+
"help",
|
|
1684
|
+
"hi",
|
|
1685
|
+
"hello",
|
|
1686
|
+
"hey"
|
|
1687
|
+
]);
|
|
1688
|
+
|
|
1689
|
+
// src/features/chat/logic-functions/utils/is-teams-help-request.ts
|
|
1690
|
+
var isTeamsHelpRequest = (requestText) => TEAMS_ASSISTANT_HELP_REQUESTS.has(
|
|
1691
|
+
requestText.trim().toLowerCase().replace(/[!.?]+$/, "")
|
|
1692
|
+
);
|
|
1693
|
+
|
|
1694
|
+
// src/features/chat/logic-functions/utils/is-teams-install-activity.ts
|
|
1695
|
+
var isTeamsInstallActivity = (activity) => activity.type === "installationUpdate" && activity.action === "add";
|
|
1535
1696
|
|
|
1536
1697
|
// src/features/chat/logic-functions/utils/parse-teams-assistant-request.ts
|
|
1537
|
-
var
|
|
1698
|
+
var import_guards21 = __toESM(require_build());
|
|
1538
1699
|
|
|
1539
1700
|
// src/features/chat/logic-functions/utils/collect-teams-bot-mention-texts.ts
|
|
1540
|
-
var
|
|
1701
|
+
var import_guards20 = __toESM(require_build());
|
|
1541
1702
|
var collectTeamsBotMentionTexts = ({
|
|
1542
1703
|
entities,
|
|
1543
1704
|
recipient
|
|
1544
1705
|
}) => (entities ?? []).filter(
|
|
1545
|
-
(entity) => entity.type === "mention" && (0,
|
|
1546
|
-
).map((entity) => entity.text).filter(
|
|
1706
|
+
(entity) => entity.type === "mention" && (0, import_guards20.isNonEmptyString)(recipient?.id) && entity.mentioned?.id?.toLowerCase() === recipient.id.toLowerCase()
|
|
1707
|
+
).map((entity) => entity.text).filter(import_guards20.isNonEmptyString);
|
|
1547
1708
|
|
|
1548
1709
|
// src/features/chat/logic-functions/utils/normalize-teams-request-text.ts
|
|
1549
1710
|
var MENTION_TAG_PATTERN = /<at>(.*?)<\/at>/g;
|
|
@@ -1576,15 +1737,15 @@ var parseTeamsAssistantRequest = ({
|
|
|
1576
1737
|
return { request: null, skipReason: "Not a user message" };
|
|
1577
1738
|
}
|
|
1578
1739
|
const conversationId = activity.conversation?.id;
|
|
1579
|
-
if (!(0,
|
|
1740
|
+
if (!(0, import_guards21.isNonEmptyString)(activity.id) || !(0, import_guards21.isNonEmptyString)(conversationId) || !(0, import_guards21.isNonEmptyString)(senderId)) {
|
|
1580
1741
|
return { request: null, skipReason: "Activity is missing required fields" };
|
|
1581
1742
|
}
|
|
1582
1743
|
const conversationType = activity.conversation?.conversationType ?? TEAMS_PERSONAL_CONVERSATION_TYPE;
|
|
1583
|
-
if (conversationType !== TEAMS_PERSONAL_CONVERSATION_TYPE && !(0,
|
|
1744
|
+
if (conversationType !== TEAMS_PERSONAL_CONVERSATION_TYPE && !(0, import_guards21.isNonEmptyArray)(collectTeamsBotMentionTexts(activity))) {
|
|
1584
1745
|
return { request: null, skipReason: "Bot is not mentioned" };
|
|
1585
1746
|
}
|
|
1586
1747
|
const requestText = normalizeTeamsRequestText(activity);
|
|
1587
|
-
if (!(0,
|
|
1748
|
+
if (!(0, import_guards21.isNonEmptyString)(requestText)) {
|
|
1588
1749
|
return {
|
|
1589
1750
|
request: null,
|
|
1590
1751
|
skipReason: "Empty request text",
|
|
@@ -1609,68 +1770,121 @@ var parseTeamsAssistantRequest = ({
|
|
|
1609
1770
|
};
|
|
1610
1771
|
};
|
|
1611
1772
|
|
|
1612
|
-
// src/features/chat/logic-functions/
|
|
1613
|
-
var
|
|
1614
|
-
"Hi! Ask me anything about your CRM, for example:",
|
|
1615
|
-
[
|
|
1616
|
-
'- "How many open opportunities are in the pipeline?"',
|
|
1617
|
-
'- "What deals are closing this month?"',
|
|
1618
|
-
'- "Create a task to follow up on my newest lead"'
|
|
1619
|
-
].join("\n"),
|
|
1620
|
-
"Mention me with your question, or send it to me in a personal chat."
|
|
1621
|
-
].join("\n\n");
|
|
1622
|
-
|
|
1623
|
-
// src/features/chat/logic-functions/utils/build-teams-empty-request-reply-kv-key.ts
|
|
1624
|
-
var buildTeamsEmptyRequestReplyKvKey = ({
|
|
1773
|
+
// src/features/chat/logic-functions/utils/build-teams-help-reply-kv-key.ts
|
|
1774
|
+
var buildTeamsHelpReplyKvKey = ({
|
|
1625
1775
|
teamsConversationId,
|
|
1626
1776
|
teamsActivityId
|
|
1627
|
-
}) => `teams-
|
|
1777
|
+
}) => `teams-help-reply:${teamsConversationId}:${teamsActivityId}`;
|
|
1628
1778
|
|
|
1629
|
-
// src/features/chat/logic-functions/utils/
|
|
1630
|
-
var
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1779
|
+
// src/features/chat/logic-functions/utils/send-teams-reply-once.ts
|
|
1780
|
+
var sendTeamsReplyOnce = async ({
|
|
1781
|
+
kvKey,
|
|
1782
|
+
ttlMs,
|
|
1783
|
+
serviceUrl,
|
|
1784
|
+
conversationId,
|
|
1785
|
+
text
|
|
1786
|
+
}) => {
|
|
1787
|
+
const existingClaim = await ge.get(kvKey);
|
|
1634
1788
|
if (o(existingClaim) && existingClaim.expiresAt > Date.now()) {
|
|
1635
1789
|
return false;
|
|
1636
1790
|
}
|
|
1637
|
-
await ge.set(
|
|
1638
|
-
return true;
|
|
1639
|
-
};
|
|
1640
|
-
|
|
1641
|
-
// src/features/chat/logic-functions/utils/reply-to-empty-teams-assistant-request.ts
|
|
1642
|
-
var replyToEmptyTeamsAssistantRequest = async (emptyRequest) => {
|
|
1643
|
-
if (!await claimTeamsEmptyRequestReply(emptyRequest)) {
|
|
1644
|
-
return { ok: true, skipped: "Empty request was already answered" };
|
|
1645
|
-
}
|
|
1791
|
+
await ge.set(kvKey, { expiresAt: Date.now() + ttlMs });
|
|
1646
1792
|
try {
|
|
1647
1793
|
await sendTeamsActivity({
|
|
1648
|
-
serviceUrl
|
|
1649
|
-
conversationId
|
|
1794
|
+
serviceUrl,
|
|
1795
|
+
conversationId,
|
|
1650
1796
|
accessToken: await getTeamsConnectorAccessTokenOrThrow(),
|
|
1651
|
-
activity: { type: "message", text
|
|
1797
|
+
activity: { type: "message", text }
|
|
1652
1798
|
});
|
|
1653
1799
|
} catch (error) {
|
|
1654
|
-
await ge.delete(
|
|
1800
|
+
await ge.delete(kvKey).catch(
|
|
1655
1801
|
(releaseError) => console.warn(
|
|
1656
|
-
`[teams] could not release the
|
|
1802
|
+
`[teams] could not release the reply claim ${kvKey}`,
|
|
1657
1803
|
releaseError
|
|
1658
1804
|
)
|
|
1659
1805
|
);
|
|
1660
1806
|
throw error;
|
|
1661
1807
|
}
|
|
1662
|
-
return
|
|
1808
|
+
return true;
|
|
1809
|
+
};
|
|
1810
|
+
|
|
1811
|
+
// src/features/chat/logic-functions/utils/reply-with-teams-assistant-help.ts
|
|
1812
|
+
var replyWithTeamsAssistantHelp = async (request) => {
|
|
1813
|
+
const isSent = await sendTeamsReplyOnce({
|
|
1814
|
+
kvKey: buildTeamsHelpReplyKvKey(request),
|
|
1815
|
+
ttlMs: TEAMS_ASSISTANT_NOTICE_TTL_MS,
|
|
1816
|
+
serviceUrl: request.teamsServiceUrl,
|
|
1817
|
+
conversationId: request.teamsConversationId,
|
|
1818
|
+
text: TEAMS_ASSISTANT_HELP_TEXT
|
|
1819
|
+
});
|
|
1820
|
+
return isSent ? { ok: true } : { ok: true, skipped: "Help was already sent for this activity" };
|
|
1821
|
+
};
|
|
1822
|
+
|
|
1823
|
+
// src/features/chat/logic-functions/utils/send-teams-assistant-notice.ts
|
|
1824
|
+
var import_guards22 = __toESM(require_build());
|
|
1825
|
+
|
|
1826
|
+
// src/features/chat/logic-functions/utils/is-teams-activity-addressed-to-bot.ts
|
|
1827
|
+
var isTeamsActivityAddressedToBot = (payload) => {
|
|
1828
|
+
if (isTeamsInstallActivity(payload.activity)) {
|
|
1829
|
+
return true;
|
|
1830
|
+
}
|
|
1831
|
+
const parsed = parseTeamsAssistantRequest(payload);
|
|
1832
|
+
return parsed.request !== null || o(parsed.emptyRequest);
|
|
1833
|
+
};
|
|
1834
|
+
|
|
1835
|
+
// src/features/chat/logic-functions/utils/send-teams-assistant-notice.ts
|
|
1836
|
+
var sendTeamsAssistantNotice = async ({
|
|
1837
|
+
payload,
|
|
1838
|
+
kind,
|
|
1839
|
+
text,
|
|
1840
|
+
ttlMs
|
|
1841
|
+
}) => {
|
|
1842
|
+
const conversationId = payload.activity.conversation?.id;
|
|
1843
|
+
if (!(0, import_guards22.isNonEmptyString)(conversationId) || !isTeamsActivityAddressedToBot(payload)) {
|
|
1844
|
+
return false;
|
|
1845
|
+
}
|
|
1846
|
+
return sendTeamsReplyOnce({
|
|
1847
|
+
kvKey: `teams-notice:${kind}:${conversationId}`,
|
|
1848
|
+
ttlMs,
|
|
1849
|
+
serviceUrl: payload.serviceUrl,
|
|
1850
|
+
conversationId,
|
|
1851
|
+
text
|
|
1852
|
+
}).catch((error) => {
|
|
1853
|
+
console.warn(
|
|
1854
|
+
`[teams] could not post the ${kind} notice in ${conversationId}`,
|
|
1855
|
+
error
|
|
1856
|
+
);
|
|
1857
|
+
return false;
|
|
1858
|
+
});
|
|
1663
1859
|
};
|
|
1664
1860
|
|
|
1665
1861
|
// src/features/chat/logic-functions/utils/enqueue-teams-assistant-request.ts
|
|
1862
|
+
var CHAT_DISABLED_SKIP_REASON = "Chat is disabled";
|
|
1666
1863
|
var enqueueTeamsAssistantRequest = async (payload) => {
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1864
|
+
if (!isTeamsChatEnabled()) {
|
|
1865
|
+
await sendTeamsAssistantNotice({
|
|
1866
|
+
payload,
|
|
1867
|
+
kind: "chat-off",
|
|
1868
|
+
text: TEAMS_ASSISTANT_CHAT_OFF_TEXT,
|
|
1869
|
+
ttlMs: TEAMS_ASSISTANT_NOTICE_TTL_MS
|
|
1870
|
+
});
|
|
1871
|
+
return { ok: true, skipped: CHAT_DISABLED_SKIP_REASON };
|
|
1872
|
+
}
|
|
1873
|
+
if (isTeamsInstallActivity(payload.activity)) {
|
|
1874
|
+
const isWelcomeSent = await sendTeamsAssistantNotice({
|
|
1875
|
+
payload,
|
|
1876
|
+
kind: "welcome",
|
|
1877
|
+
text: TEAMS_ASSISTANT_HELP_TEXT,
|
|
1878
|
+
ttlMs: TEAMS_ASSISTANT_WELCOME_TTL_MS
|
|
1879
|
+
});
|
|
1880
|
+
return isWelcomeSent ? { ok: true } : { ok: true, skipped: "Welcome was not sent" };
|
|
1670
1881
|
}
|
|
1671
1882
|
const parsed = parseTeamsAssistantRequest(payload);
|
|
1672
1883
|
if (parsed.request === null) {
|
|
1673
|
-
return o(parsed.emptyRequest) ? await
|
|
1884
|
+
return o(parsed.emptyRequest) ? await replyWithTeamsAssistantHelp(parsed.emptyRequest) : { ok: true, skipped: parsed.skipReason };
|
|
1885
|
+
}
|
|
1886
|
+
if (isTeamsHelpRequest(parsed.request.requestText)) {
|
|
1887
|
+
return await replyWithTeamsAssistantHelp(parsed.request);
|
|
1674
1888
|
}
|
|
1675
1889
|
return await enqueueTeamsAssistantRequestRecord(parsed.request);
|
|
1676
1890
|
};
|
|
@@ -1690,7 +1904,7 @@ var teamsActivitiesEnqueueHandler = async (payload) => {
|
|
|
1690
1904
|
var teams_activities_enqueue_default = defineLogicFunction({
|
|
1691
1905
|
universalIdentifier: TEAMS_ACTIVITIES_ENQUEUE_UNIVERSAL_IDENTIFIER,
|
|
1692
1906
|
name: "teams-activities-enqueue",
|
|
1693
|
-
description: "Receives a verified Microsoft Teams message activity from the activities route, in the workspace that claimed its tenant.
|
|
1907
|
+
description: "Receives a verified Microsoft Teams message or install activity from the activities route, in the workspace that claimed its tenant. Posts a welcome when the bot is installed, the help text for help, hi and bare mentions, and a notice when chat is turned off. Otherwise, when chat is enabled, records the message as a Teams Assistant Request, once per conversation and activity id, then answers it: matches the sender to a workspace member by email, runs the Teams Assistant agent as that member and posts the answer back to the conversation.",
|
|
1694
1908
|
timeoutSeconds: TEAMS_ASSISTANT_REQUEST_TIMEOUT_SECONDS,
|
|
1695
1909
|
handler: teamsActivitiesEnqueueHandler
|
|
1696
1910
|
});
|