Skip to content

The open alternative to Salesforce, designed for AI.

Let the Teams assistant work with CRM records (#28832)

Abdul Rahman5fd0116addcf
diff --git a/packages/twenty-apps/public/teams/src/__tests__/schema.integration-test.ts b/packages/twenty-apps/public/teams/src/__tests__/schema.integration-test.ts
index e50de4ae2f6..5f983656362 100644
--- a/packages/twenty-apps/public/teams/src/__tests__/schema.integration-test.ts
+++ b/packages/twenty-apps/public/teams/src/__tests__/schema.integration-test.ts
@@ -1,8 +1,11 @@
import { MetadataApiClient } from 'twenty-client-sdk/metadata';
import { isDefined } from 'twenty-sdk/utils';
-import { APPLICATION_UNIVERSAL_IDENTIFIER } from 'src/constants/universal-identifiers';
-import { TEAMS_ASSISTANT_ROLE_UNIVERSAL_IDENTIFIER } from 'src/features/chat/constants/universal-identifiers';
+import {
+ APPLICATION_UNIVERSAL_IDENTIFIER,
+ DEFAULT_ROLE_UNIVERSAL_IDENTIFIER,
+} from 'src/constants/universal-identifiers';
+import { TEAMS_ASSISTANT_CRM_OBJECT_UNIVERSAL_IDENTIFIERS } from 'src/features/chat/constants/teams-assistant-crm-object-universal-identifiers';
import { describe, expect, it } from 'vitest';
describe('App installation', () => {
@@ -16,7 +19,7 @@ describe('App installation', () => {
).toContain('teams-list-organizer-transcripts');
});
- it('installs the Teams assistant agent bound to a role that grants nothing', async () => {
+ it('installs the Teams assistant agent bound to the app role', async () => {
const client = new MetadataApiClient();
const { findManyAgents } = await client.query({
@@ -41,16 +44,25 @@ describe('App installation', () => {
canSoftDeleteAllObjectRecords: true,
canDestroyAllObjectRecords: true,
canUpdateAllSettings: true,
- objectPermissions: { objectMetadataId: true },
- permissionFlags: { id: true },
+ objectPermissions: {
+ objectMetadataId: true,
+ canReadObjectRecords: true,
+ canUpdateObjectRecords: true,
+ canSoftDeleteObjectRecords: true,
+ canDestroyObjectRecords: true,
+ },
},
});
const role = getRoles.find((role) => role.id === agent.roleId);
+ if (!isDefined(role)) {
+ throw new Error('The Teams assistant agent has no role.');
+ }
+
expect(role).toEqual(
expect.objectContaining({
- universalIdentifier: TEAMS_ASSISTANT_ROLE_UNIVERSAL_IDENTIFIER,
+ universalIdentifier: DEFAULT_ROLE_UNIVERSAL_IDENTIFIER,
canBeAssignedToAgents: true,
canReadAllObjectRecords: false,
canUpdateAllObjectRecords: false,
@@ -59,8 +71,36 @@ describe('App installation', () => {
canUpdateAllSettings: false,
}),
);
- expect(role?.objectPermissions ?? []).toHaveLength(0);
- expect(role?.permissionFlags ?? []).toHaveLength(0);
+
+ const { objects } = await client.query({
+ objects: {
+ __args: { paging: { first: 200 }, filter: {} },
+ edges: { node: { id: true, universalIdentifier: true } },
+ },
+ });
+
+ const objectUniversalIdentifierById = new Map(
+ objects.edges.map((edge) => [
+ edge.node.id,
+ edge.node.universalIdentifier,
+ ]),
+ );
+
+ const editableObjectUniversalIdentifiers = (role.objectPermissions ?? [])
+ .filter(
+ (objectPermission) =>
+ objectPermission.canReadObjectRecords &&
+ objectPermission.canUpdateObjectRecords &&
+ objectPermission.canSoftDeleteObjectRecords &&
+ !objectPermission.canDestroyObjectRecords,
+ )
+ .map((objectPermission) =>
+ objectUniversalIdentifierById.get(objectPermission.objectMetadataId),
+ );
+
+ expect(editableObjectUniversalIdentifiers).toEqual(
+ expect.arrayContaining(TEAMS_ASSISTANT_CRM_OBJECT_UNIVERSAL_IDENTIFIERS),
+ );
});
it('registers Microsoft OAuth under Teams without configured credentials', async () => {
diff --git a/packages/twenty-apps/public/teams/src/features/chat/agents/teams-assistant.agent.ts b/packages/twenty-apps/public/teams/src/features/chat/agents/teams-assistant.agent.ts
index a2184f8c874..f555a7186b4 100644
--- a/packages/twenty-apps/public/teams/src/features/chat/agents/teams-assistant.agent.ts
+++ b/packages/twenty-apps/public/teams/src/features/chat/agents/teams-assistant.agent.ts
@@ -1,10 +1,8 @@
import { defineAgent } from 'twenty-sdk/define';
+import { DEFAULT_ROLE_UNIVERSAL_IDENTIFIER } from 'src/constants/universal-identifiers';
import { DEFAULT_TEAMS_ASSISTANT_PROMPT } from 'src/features/chat/constants/default-teams-assistant-prompt';
-import {
- TEAMS_ASSISTANT_AGENT_UNIVERSAL_IDENTIFIER,
- TEAMS_ASSISTANT_ROLE_UNIVERSAL_IDENTIFIER,
-} from 'src/features/chat/constants/universal-identifiers';
+import { TEAMS_ASSISTANT_AGENT_UNIVERSAL_IDENTIFIER } from 'src/features/chat/constants/universal-identifiers';
export default defineAgent({
universalIdentifier: TEAMS_ASSISTANT_AGENT_UNIVERSAL_IDENTIFIER,
@@ -15,5 +13,5 @@ export default defineAgent({
'Conversational CRM assistant reached from Microsoft Teams. Answers questions and acts on workspace data as the workspace member who made the request.',
prompt: DEFAULT_TEAMS_ASSISTANT_PROMPT,
responseFormat: { type: 'text' },
- roleUniversalIdentifier: TEAMS_ASSISTANT_ROLE_UNIVERSAL_IDENTIFIER,
+ roleUniversalIdentifier: DEFAULT_ROLE_UNIVERSAL_IDENTIFIER,
});
diff --git a/packages/twenty-apps/public/teams/src/features/chat/constants/teams-assistant-crm-object-universal-identifiers.ts b/packages/twenty-apps/public/teams/src/features/chat/constants/teams-assistant-crm-object-universal-identifiers.ts
new file mode 100644
index 00000000000..e516961d4a0
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/chat/constants/teams-assistant-crm-object-universal-identifiers.ts
@@ -0,0 +1,11 @@
+import { STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS } from 'twenty-sdk/define';
+
+export const TEAMS_ASSISTANT_CRM_OBJECT_UNIVERSAL_IDENTIFIERS = [
+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.person.universalIdentifier,
+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.company.universalIdentifier,
+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.opportunity.universalIdentifier,
+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.note.universalIdentifier,
+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.noteTarget.universalIdentifier,
+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.task.universalIdentifier,
+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.taskTarget.universalIdentifier,
+];
diff --git a/packages/twenty-apps/public/teams/src/features/chat/constants/universal-identifiers.ts b/packages/twenty-apps/public/teams/src/features/chat/constants/universal-identifiers.ts
index 9a03da34fb0..ba3e8cd714d 100644
--- a/packages/twenty-apps/public/teams/src/features/chat/constants/universal-identifiers.ts
+++ b/packages/twenty-apps/public/teams/src/features/chat/constants/universal-identifiers.ts
@@ -13,9 +13,6 @@ export const TEAMS_ACTIVITIES_ENQUEUE_UNIVERSAL_IDENTIFIER =
export const TEAMS_ASSISTANT_AGENT_UNIVERSAL_IDENTIFIER =
'b14f0c9d-d283-4969-8cca-1da280fc9937';
-export const TEAMS_ASSISTANT_ROLE_UNIVERSAL_IDENTIFIER =
- 'f8b953df-832a-48d8-81ca-2100fdecc9f1';
-
export const TEAMS_ASSISTANT_WORKER_UNIVERSAL_IDENTIFIER =
'cd3f1e58-d315-4e10-9a50-780b300d3977';
diff --git a/packages/twenty-apps/public/teams/src/features/chat/roles/teams-assistant.role.ts b/packages/twenty-apps/public/teams/src/features/chat/roles/teams-assistant.role.ts
deleted file mode 100644
index 07d0b038336..00000000000
--- a/packages/twenty-apps/public/teams/src/features/chat/roles/teams-assistant.role.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { defineRole } from 'twenty-sdk/define';
-
-import { TEAMS_ASSISTANT_ROLE_UNIVERSAL_IDENTIFIER } from 'src/features/chat/constants/universal-identifiers';
-
-export default defineRole({
- universalIdentifier: TEAMS_ASSISTANT_ROLE_UNIVERSAL_IDENTIFIER,
- label: 'Teams Assistant',
- description:
- 'Role of the Teams assistant agent. Grants nothing on its own: the agent always runs as the workspace member who sent the message, and its CRM tools follow the role of that member.',
- canReadAllObjectRecords: false,
- canUpdateAllObjectRecords: false,
- canSoftDeleteAllObjectRecords: false,
- canDestroyAllObjectRecords: false,
- canUpdateAllSettings: false,
- canBeAssignedToAgents: true,
- canBeAssignedToUsers: false,
- canBeAssignedToApiKeys: false,
- objectPermissions: [],
- fieldPermissions: [],
- permissionFlagUniversalIdentifiers: [],
-});
diff --git a/packages/twenty-apps/public/teams/src/roles/default-function.role.ts b/packages/twenty-apps/public/teams/src/roles/default-function.role.ts
index 106fbcc7a56..ce620338cc9 100644
--- a/packages/twenty-apps/public/teams/src/roles/default-function.role.ts
+++ b/packages/twenty-apps/public/teams/src/roles/default-function.role.ts
@@ -5,6 +5,7 @@ import {
} from 'twenty-sdk/define';
import { DEFAULT_ROLE_UNIVERSAL_IDENTIFIER } from 'src/constants/universal-identifiers';
+import { TEAMS_ASSISTANT_CRM_OBJECT_UNIVERSAL_IDENTIFIERS } from 'src/features/chat/constants/teams-assistant-crm-object-universal-identifiers';
import {
TEAMS_ASSISTANT_REQUEST_OBJECT_UNIVERSAL_IDENTIFIER,
TEAMS_USER_LINK_OBJECT_UNIVERSAL_IDENTIFIER,
@@ -14,13 +15,13 @@ export default defineApplicationRole({
universalIdentifier: DEFAULT_ROLE_UNIVERSAL_IDENTIFIER,
label: 'Twenty Microsoft Teams tools role',
description:
- 'Reads calendar events and their calendar channel associations to match Teams meetings, writes imported transcripts to Call Recordings, and writes the summary from the Teams Transcript Summarizer agent on them. Tracks assistant requests received from Teams, reads workspace members to match a Teams sender by email, keeps Teams user links so a matched sender is remembered and can be unlinked, and runs the Teams Assistant agent as that member, with the permissions of that member. Chat tools only forward requests to Microsoft Teams using the configured bot credentials. Saves the Microsoft Teams settings of this workspace.',
+ 'Reads calendar events and their calendar channel associations to match Teams meetings, writes imported transcripts to Call Recordings, and writes the summary from the Teams Transcript Summarizer agent on them. Tracks assistant requests received from Teams, reads workspace members to match a Teams sender by email, keeps Teams user links so a matched sender is remembered and can be unlinked, and runs the Teams Assistant agent as that member, reading and editing people, companies, opportunities, notes and tasks within the permissions of that member. Chat tools only forward requests to Microsoft Teams using the configured bot credentials. Saves the Microsoft Teams settings of this workspace.',
canReadAllObjectRecords: false,
canUpdateAllObjectRecords: false,
canSoftDeleteAllObjectRecords: false,
canDestroyAllObjectRecords: false,
canUpdateAllSettings: false,
- canBeAssignedToAgents: false,
+ canBeAssignedToAgents: true,
canBeAssignedToUsers: false,
canBeAssignedToApiKeys: false,
objectPermissions: [
@@ -73,6 +74,15 @@ export default defineApplicationRole({
canSoftDeleteObjectRecords: false,
canDestroyObjectRecords: true,
},
+ ...TEAMS_ASSISTANT_CRM_OBJECT_UNIVERSAL_IDENTIFIERS.map(
+ (objectUniversalIdentifier) => ({
+ objectUniversalIdentifier,
+ canReadObjectRecords: true,
+ canUpdateObjectRecords: true,
+ canSoftDeleteObjectRecords: true,
+ canDestroyObjectRecords: false,
+ }),
+ ),
],
fieldPermissions: [],
permissionFlagUniversalIdentifiers: [