Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(workflow-integrations): microsoft teams scaling issues

Daniel Hougaardab6a2b7dbbde
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 8606bf0f29..545e0fb743 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -1784,6 +1784,10 @@ export const registerRoutes = async (
if (licenseSyncJob) {
cronJobs.push(licenseSyncJob);
}
+ const microsoftTeamsSyncJob = await microsoftTeamsService.initializeBackgroundSync();
+ if (microsoftTeamsSyncJob) {
+ cronJobs.push(microsoftTeamsSyncJob);
+ }
}
server.decorate<FastifyZodProvider["store"]>("store", {
diff --git a/backend/src/services/microsoft-teams/microsoft-teams-service.ts b/backend/src/services/microsoft-teams/microsoft-teams-service.ts
index 3712a0793e..1413a3199b 100644
--- a/backend/src/services/microsoft-teams/microsoft-teams-service.ts
+++ b/backend/src/services/microsoft-teams/microsoft-teams-service.ts
@@ -6,6 +6,7 @@ import {
Request,
Response
} from "botbuilder";
+import { CronJob } from "cron";
import { FastifyReply, FastifyRequest } from "fastify";
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
@@ -86,8 +87,17 @@ export const microsoftTeamsServiceFactory = ({
}: TMicrosoftTeamsServiceFactoryDep) => {
let teamsBot: TeamsBot | null = null;
let adapter: CloudAdapter | null = null;
-
- const initializeTeamsBot = async ({ botAppId, botAppPassword }: { botAppId: string; botAppPassword: string }) => {
+ let lastKnownUpdatedAt = new Date();
+
+ const initializeTeamsBot = async ({
+ botAppId,
+ botAppPassword,
+ lastUpdatedAt
+ }: {
+ botAppId: string;
+ botAppPassword: string;
+ lastUpdatedAt?: Date;
+ }) => {
logger.info("Initializing Microsoft Teams bot");
teamsBot = new TeamsBot({
botAppId,
@@ -106,6 +116,57 @@ export const microsoftTeamsServiceFactory = ({
})
)
);
+
+ if (lastUpdatedAt) {
+ lastKnownUpdatedAt = lastUpdatedAt;
+ }
+ };
+
+ const $syncMicrosoftTeamsIntegrationConfiguration = async () => {
+ try {
+ const serverCfg = await serverCfgDAL.findById(ADMIN_CONFIG_DB_UUID);
+ if (!serverCfg) {
+ throw new BadRequestError({
+ message: "Failed to get server configuration."
+ });
+ }
+
+ if (lastKnownUpdatedAt.getTime() === serverCfg.updatedAt.getTime()) {
+ logger.info("No changes to Microsoft Teams integration configuration, skipping sync");
+ return;
+ }
+
+ lastKnownUpdatedAt = serverCfg.updatedAt;
+
+ if (
+ serverCfg.encryptedMicrosoftTeamsAppId &&
+ serverCfg.encryptedMicrosoftTeamsClientSecret &&
+ serverCfg.encryptedMicrosoftTeamsBotId
+ ) {
+ const decryptWithRoot = kmsService.decryptWithRootKey();
+ const decryptedAppId = decryptWithRoot(serverCfg.encryptedMicrosoftTeamsAppId);
+ const decryptedAppPassword = decryptWithRoot(serverCfg.encryptedMicrosoftTeamsClientSecret);
+
+ await initializeTeamsBot({
+ botAppId: decryptedAppId.toString(),
+ botAppPassword: decryptedAppPassword.toString()
+ });
+ }
+ } catch (err) {
+ logger.error(err, "Error syncing Microsoft Teams integration configuration");
+ }
+ };
+
+ const initializeBackgroundSync = async () => {
+ logger.info("Setting up background sync process for Microsoft Teams workflow integration configuration");
+ // initial sync upon startup
+ await $syncMicrosoftTeamsIntegrationConfiguration();
+
+ // sync rate limits configuration every 5 minutes
+ const job = new CronJob("*/5 * * * *", $syncMicrosoftTeamsIntegrationConfiguration);
+ job.start();
+
+ return job;
};
const start = async () => {
@@ -703,6 +764,7 @@ export const microsoftTeamsServiceFactory = ({
getTeams,
handleMessageEndpoint,
start,
+ initializeBackgroundSync,
sendNotification,
checkInstallationStatus,
getClientId
diff --git a/backend/src/services/super-admin/super-admin-service.ts b/backend/src/services/super-admin/super-admin-service.ts
index 7c9ca4f38c..22fc51d1a1 100644
--- a/backend/src/services/super-admin/super-admin-service.ts
+++ b/backend/src/services/super-admin/super-admin-service.ts
@@ -246,7 +246,8 @@ export const superAdminServiceFactory = ({
await microsoftTeamsService.initializeTeamsBot({
botAppId: decryptedAppId.toString(),
- botAppPassword: decryptedAppPassword.toString()
+ botAppPassword: decryptedAppPassword.toString(),
+ lastUpdatedAt: updatedServerCfg.updatedAt
});
}
diff --git a/frontend/src/pages/admin/OverviewPage/components/MicrosoftTeamsIntegrationForm.tsx b/frontend/src/pages/admin/OverviewPage/components/MicrosoftTeamsIntegrationForm.tsx
index ecd8288f42..3e83879b16 100644
--- a/frontend/src/pages/admin/OverviewPage/components/MicrosoftTeamsIntegrationForm.tsx
+++ b/frontend/src/pages/admin/OverviewPage/components/MicrosoftTeamsIntegrationForm.tsx
@@ -52,7 +52,7 @@ export const MicrosoftTeamsIntegrationForm = ({ adminIntegrationsConfig }: Props
});
createNotification({
- text: "Updated admin Microsoft Teams configuration",
+ text: "Updated admin Microsoft Teams configuration. It can take up to 5 minutes to take effect.",
type: "success"
});
};