@guayaba/workflow-piece-googlechat 0.1.3
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/.eslintrc.json +33 -0
- package/README.md +5 -0
- package/assets/logo.png +0 -0
- package/package.json +22 -0
- package/src/i18n/de.json +52 -0
- package/src/i18n/es.json +52 -0
- package/src/i18n/fr.json +52 -0
- package/src/i18n/ja.json +52 -0
- package/src/i18n/nl.json +52 -0
- package/src/i18n/pt.json +52 -0
- package/src/i18n/translation.json +52 -0
- package/src/i18n/zh.json +52 -0
- package/src/index.ts +33 -0
- package/src/lib/actions/add-a-space-member.ts +31 -0
- package/src/lib/actions/find-member.ts +60 -0
- package/src/lib/actions/get-direct-message-details.ts +27 -0
- package/src/lib/actions/get-message.ts +30 -0
- package/src/lib/actions/search-messages.ts +45 -0
- package/src/lib/actions/send-a-message.ts +110 -0
- package/src/lib/common/constants.ts +22 -0
- package/src/lib/common/index.ts +17 -0
- package/src/lib/common/props.ts +332 -0
- package/src/lib/common/requests.ts +480 -0
- package/src/lib/common/schemas.ts +147 -0
- package/src/lib/triggers/new-mention.ts +111 -0
- package/src/lib/triggers/new-message.ts +86 -0
- package/tsconfig.json +20 -0
- package/tsconfig.lib.json +13 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createAction, Property } from '@guayaba/workflows-framework';
|
|
2
|
+
import { propsValidation } from '@guayaba/workflows-common';
|
|
3
|
+
import { googleChatApiAuth, googleChatCommon } from '../common';
|
|
4
|
+
import { directMessagesDropdown, spacesDropdown } from '../common/props';
|
|
5
|
+
import { googleChatAPIService } from '../common/requests';
|
|
6
|
+
|
|
7
|
+
export const getDirectMessageDetails = createAction({
|
|
8
|
+
auth: googleChatApiAuth,
|
|
9
|
+
name: 'getDirectMessageDetails',
|
|
10
|
+
displayName: 'Get Direct Message Details',
|
|
11
|
+
description: 'Retrieve details of a specific direct message by ID.',
|
|
12
|
+
props: {
|
|
13
|
+
directMessageId: directMessagesDropdown({ refreshers: ['auth'], required: true }),
|
|
14
|
+
},
|
|
15
|
+
async run({ auth, propsValue }) {
|
|
16
|
+
await propsValidation.validateZod(propsValue, googleChatCommon.getDirectMessageDetailsSchema);
|
|
17
|
+
|
|
18
|
+
const { directMessageId } = propsValue;
|
|
19
|
+
|
|
20
|
+
const response = await googleChatAPIService.getSpace({
|
|
21
|
+
accessToken: auth.access_token,
|
|
22
|
+
spaceId: directMessageId as string,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return response;
|
|
26
|
+
},
|
|
27
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createAction, Property } from '@guayaba/workflows-framework';
|
|
2
|
+
import { propsValidation } from '@guayaba/workflows-common';
|
|
3
|
+
import { googleChatApiAuth, googleChatCommon } from '../common';
|
|
4
|
+
import { googleChatAPIService } from '../common/requests';
|
|
5
|
+
|
|
6
|
+
export const getMessageDetails = createAction({
|
|
7
|
+
auth: googleChatApiAuth,
|
|
8
|
+
name: 'getMessageDetails',
|
|
9
|
+
displayName: 'Get Message Details',
|
|
10
|
+
description: 'Retrieve details of a specific message by ID. Supports both system-generated and custom message IDs.',
|
|
11
|
+
props: {
|
|
12
|
+
name: Property.ShortText({
|
|
13
|
+
displayName: 'Message Resource Name',
|
|
14
|
+
description: 'The full resource name of the message. Format: spaces/{space}/messages/{message}',
|
|
15
|
+
required: true,
|
|
16
|
+
}),
|
|
17
|
+
},
|
|
18
|
+
async run({ auth, propsValue }) {
|
|
19
|
+
await propsValidation.validateZod(propsValue, googleChatCommon.getMessageSchema);
|
|
20
|
+
|
|
21
|
+
const { name } = propsValue;
|
|
22
|
+
|
|
23
|
+
const message = await googleChatAPIService.getMessage(
|
|
24
|
+
auth.access_token,
|
|
25
|
+
name
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
return message;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createAction, Property } from '@guayaba/workflows-framework';
|
|
2
|
+
import { propsValidation } from '@guayaba/workflows-common';
|
|
3
|
+
import { googleChatApiAuth, googleChatCommon } from '../common';
|
|
4
|
+
import { allSpacesDropdown } from '../common/props';
|
|
5
|
+
import { googleChatAPIService } from '../common/requests';
|
|
6
|
+
|
|
7
|
+
export const searchMessages = createAction({
|
|
8
|
+
auth: googleChatApiAuth,
|
|
9
|
+
name: 'searchMessages',
|
|
10
|
+
displayName: 'Search Messages',
|
|
11
|
+
description: 'Search within Chat for messages matching keywords or filters.',
|
|
12
|
+
props: {
|
|
13
|
+
spaceId: allSpacesDropdown({ refreshers: ['auth'], required: true }),
|
|
14
|
+
keyword: Property.ShortText({
|
|
15
|
+
displayName: 'Keyword',
|
|
16
|
+
description: 'Search for messages containing this text',
|
|
17
|
+
required: true,
|
|
18
|
+
}),
|
|
19
|
+
limit: Property.Number({
|
|
20
|
+
displayName: 'Max Results',
|
|
21
|
+
description: 'Maximum number of messages to return',
|
|
22
|
+
required: false,
|
|
23
|
+
defaultValue: 50,
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
async run({ auth, propsValue }) {
|
|
27
|
+
await propsValidation.validateZod(propsValue, googleChatCommon.searchMessagesSchema);
|
|
28
|
+
|
|
29
|
+
const { spaceId, keyword, limit } = propsValue;
|
|
30
|
+
|
|
31
|
+
const response = await googleChatAPIService.listMessages(
|
|
32
|
+
auth.access_token,
|
|
33
|
+
spaceId as string,
|
|
34
|
+
limit
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const messages = response.messages || [];
|
|
38
|
+
|
|
39
|
+
const filtered = messages.filter((msg: any) =>
|
|
40
|
+
msg.text?.toLowerCase().includes(keyword.toLowerCase())
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return filtered;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createAction, Property } from '@guayaba/workflows-framework';
|
|
2
|
+
import { propsValidation } from '@guayaba/workflows-common';
|
|
3
|
+
import { googleChatApiAuth, googleChatCommon } from '../common';
|
|
4
|
+
import { allSpacesDropdown, spacesDropdown, peoplesDropdown, threadsDropdown } from '../common/props';
|
|
5
|
+
import { googleChatAPIService } from '../common/requests';
|
|
6
|
+
|
|
7
|
+
export const sendAMessage = createAction({
|
|
8
|
+
auth: googleChatApiAuth,
|
|
9
|
+
name: 'sendAMessage',
|
|
10
|
+
displayName: 'Send a Message',
|
|
11
|
+
description: 'Send a message to a space or direct conversation.',
|
|
12
|
+
props: {
|
|
13
|
+
spaceId: allSpacesDropdown({ refreshers: ['auth'], required: true }),
|
|
14
|
+
text: Property.LongText({
|
|
15
|
+
displayName: 'Message',
|
|
16
|
+
description: 'The message content to send. Supports basic formatting like *bold*, _italic_, and @mentions.',
|
|
17
|
+
required: true,
|
|
18
|
+
}),
|
|
19
|
+
thread: threadsDropdown({ refreshers: ['auth', 'spaceId'], required: false }),
|
|
20
|
+
messageReplyOption: Property.StaticDropdown({
|
|
21
|
+
displayName: 'Reply Behavior',
|
|
22
|
+
description: 'How to handle replies when thread ID is provided.',
|
|
23
|
+
required: false,
|
|
24
|
+
options: {
|
|
25
|
+
options: [
|
|
26
|
+
{
|
|
27
|
+
label: 'Reply or start new thread',
|
|
28
|
+
value: 'REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
label: 'Reply only (fail if thread not found)',
|
|
32
|
+
value: 'REPLY_MESSAGE_OR_FAIL',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
customMessageId: Property.ShortText({
|
|
38
|
+
displayName: 'Custom Message ID',
|
|
39
|
+
description: 'Optional unique ID for this message (auto-generated if empty). Useful for deduplication.',
|
|
40
|
+
required: false,
|
|
41
|
+
}),
|
|
42
|
+
isPrivate: Property.Checkbox({
|
|
43
|
+
displayName: 'Send as Private Message',
|
|
44
|
+
description: 'Send this message privately to a specific user. Requires app authentication.',
|
|
45
|
+
required: false,
|
|
46
|
+
}),
|
|
47
|
+
privateMessageViewer: Property.Dropdown({
|
|
48
|
+
displayName: 'Private Message Recipient',
|
|
49
|
+
description: 'Select the user who can view this private message.',
|
|
50
|
+
required: false,
|
|
51
|
+
refreshers: ['auth'],
|
|
52
|
+
auth: googleChatApiAuth,
|
|
53
|
+
async options({ auth }) {
|
|
54
|
+
if (!auth) {
|
|
55
|
+
return {
|
|
56
|
+
disabled: true,
|
|
57
|
+
placeholder: 'Connect your Google account first',
|
|
58
|
+
options: [],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const members = await googleChatAPIService.fetchPeople(
|
|
64
|
+
auth.access_token
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
options: members
|
|
69
|
+
.map((member: any) => {
|
|
70
|
+
const nameObj =
|
|
71
|
+
member.names?.find((n: any) => n.metadata.primary) ||
|
|
72
|
+
member.names?.[0];
|
|
73
|
+
if (!nameObj) return null;
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
label: nameObj.displayName,
|
|
77
|
+
value: member.resourceName,
|
|
78
|
+
};
|
|
79
|
+
})
|
|
80
|
+
.filter(Boolean),
|
|
81
|
+
};
|
|
82
|
+
} catch (e) {
|
|
83
|
+
console.error('Failed to fetch people', e);
|
|
84
|
+
return {
|
|
85
|
+
options: [],
|
|
86
|
+
placeholder: 'Unable to load people',
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
},
|
|
92
|
+
async run({ auth, propsValue }) {
|
|
93
|
+
await propsValidation.validateZod(propsValue, googleChatCommon.sendMessageSchema);
|
|
94
|
+
|
|
95
|
+
const { spaceId, text, thread, messageReplyOption, customMessageId, isPrivate, privateMessageViewer } = propsValue;
|
|
96
|
+
|
|
97
|
+
const response = await googleChatAPIService.sendMessage({
|
|
98
|
+
accessToken: auth.access_token,
|
|
99
|
+
spaceId: spaceId as string,
|
|
100
|
+
text,
|
|
101
|
+
thread,
|
|
102
|
+
messageReplyOption,
|
|
103
|
+
customMessageId,
|
|
104
|
+
isPrivate,
|
|
105
|
+
privateMessageViewer,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return response;
|
|
109
|
+
},
|
|
110
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PieceAuth } from "@guayaba/workflows-framework";
|
|
2
|
+
|
|
3
|
+
export const googleChatApiAuth = PieceAuth.OAuth2({
|
|
4
|
+
authUrl: 'https://accounts.google.com/o/oauth2/auth',
|
|
5
|
+
tokenUrl: 'https://oauth2.googleapis.com/token',
|
|
6
|
+
required: true,
|
|
7
|
+
scope: [
|
|
8
|
+
'https://www.googleapis.com/auth/chat.messages',
|
|
9
|
+
'https://www.googleapis.com/auth/chat.spaces',
|
|
10
|
+
'https://www.googleapis.com/auth/chat.memberships',
|
|
11
|
+
'https://www.googleapis.com/auth/cloud-platform',
|
|
12
|
+
'https://www.googleapis.com/auth/directory.readonly',
|
|
13
|
+
],
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const GOOGLE_SERVICE_ENTITIES = {
|
|
17
|
+
chat: 'chat',
|
|
18
|
+
cloudresourcemanager: 'cloudresourcemanager',
|
|
19
|
+
pubsub: 'pubsub',
|
|
20
|
+
workspaceevents: 'workspaceevents',
|
|
21
|
+
people: 'people',
|
|
22
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './schemas';
|
|
2
|
+
export * from './constants';
|
|
3
|
+
export * from './props';
|
|
4
|
+
export * from './requests';
|
|
5
|
+
|
|
6
|
+
import * as schemas from './schemas';
|
|
7
|
+
|
|
8
|
+
export const googleChatCommon = {
|
|
9
|
+
sendMessageSchema: schemas.sendMessageSchema,
|
|
10
|
+
getMessageSchema: schemas.getMessageSchema,
|
|
11
|
+
addSpaceMemberSchema: schemas.addSpaceMemberSchema,
|
|
12
|
+
findMemberSchema: schemas.findMemberSchema,
|
|
13
|
+
searchMessagesSchema: schemas.searchMessagesSchema,
|
|
14
|
+
getDirectMessageDetailsSchema: schemas.getDirectMessageDetailsSchema,
|
|
15
|
+
newMessageTriggerSchema: schemas.newMessageTriggerSchema,
|
|
16
|
+
newMentionTriggerSchema: schemas.newMentionTriggerSchema,
|
|
17
|
+
};
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { Property } from '@guayaba/workflows-framework';
|
|
2
|
+
import { googleChatAPIService } from './requests';
|
|
3
|
+
import { googleChatApiAuth } from './constants';
|
|
4
|
+
|
|
5
|
+
export const projectsDropdown = (refreshers: string[]) =>
|
|
6
|
+
Property.Dropdown({
|
|
7
|
+
displayName: 'Project',
|
|
8
|
+
description: 'Select a Google Cloud Project',
|
|
9
|
+
required: true,
|
|
10
|
+
refreshers,
|
|
11
|
+
auth: googleChatApiAuth,
|
|
12
|
+
async options({ auth }: any) {
|
|
13
|
+
if (!auth) {
|
|
14
|
+
return {
|
|
15
|
+
disabled: true,
|
|
16
|
+
placeholder: 'Connect your Google account first',
|
|
17
|
+
options: [],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const projects = await googleChatAPIService.fetchProjects(
|
|
23
|
+
auth.access_token
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
options: projects.map((project: any) => ({
|
|
28
|
+
label: project.name,
|
|
29
|
+
value: project.projectId,
|
|
30
|
+
})),
|
|
31
|
+
};
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.error('Failed to fetch projects', e);
|
|
34
|
+
return {
|
|
35
|
+
options: [],
|
|
36
|
+
placeholder: 'Unable to load projects',
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export const spacesDropdown = ({
|
|
43
|
+
refreshers,
|
|
44
|
+
required = false,
|
|
45
|
+
}: {
|
|
46
|
+
refreshers: string[];
|
|
47
|
+
required?: boolean;
|
|
48
|
+
}) =>
|
|
49
|
+
Property.Dropdown({
|
|
50
|
+
auth: googleChatApiAuth,
|
|
51
|
+
displayName: 'Space',
|
|
52
|
+
description: `Select a Space${
|
|
53
|
+
required ? '' : ', leave empty for all spaces'
|
|
54
|
+
}`,
|
|
55
|
+
required,
|
|
56
|
+
refreshers,
|
|
57
|
+
async options({ auth }: any) {
|
|
58
|
+
if (!auth) {
|
|
59
|
+
return {
|
|
60
|
+
disabled: true,
|
|
61
|
+
placeholder: 'Connect your Google account first',
|
|
62
|
+
options: [],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const spaces = await googleChatAPIService.fetchSpaces(
|
|
68
|
+
auth.access_token
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
options: spaces.map((space: any) => ({
|
|
73
|
+
label: space.displayName || space.name,
|
|
74
|
+
value: space.name,
|
|
75
|
+
})),
|
|
76
|
+
};
|
|
77
|
+
} catch (e) {
|
|
78
|
+
console.error('Failed to fetch spaces', e);
|
|
79
|
+
return {
|
|
80
|
+
options: [],
|
|
81
|
+
placeholder: 'Unable to load spaces',
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export const allSpacesDropdown = ({
|
|
88
|
+
refreshers,
|
|
89
|
+
required = false,
|
|
90
|
+
}: {
|
|
91
|
+
refreshers: string[];
|
|
92
|
+
required?: boolean;
|
|
93
|
+
}) =>
|
|
94
|
+
Property.Dropdown({
|
|
95
|
+
auth: googleChatApiAuth,
|
|
96
|
+
displayName: 'Space',
|
|
97
|
+
description: `Select a Space${
|
|
98
|
+
required ? '' : ', leave empty for all spaces'
|
|
99
|
+
}`,
|
|
100
|
+
required,
|
|
101
|
+
refreshers,
|
|
102
|
+
async options({ auth }: any) {
|
|
103
|
+
if (!auth) {
|
|
104
|
+
return {
|
|
105
|
+
disabled: true,
|
|
106
|
+
placeholder: 'Connect your Google account first',
|
|
107
|
+
options: [],
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
const spaces = await googleChatAPIService.fetchAllSpaces(
|
|
113
|
+
auth.access_token
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
options: spaces.map((space: any) => ({
|
|
118
|
+
label: space.displayName || space.name,
|
|
119
|
+
value: space.name,
|
|
120
|
+
})),
|
|
121
|
+
};
|
|
122
|
+
} catch (e) {
|
|
123
|
+
console.error('Failed to fetch spaces', e);
|
|
124
|
+
return {
|
|
125
|
+
options: [],
|
|
126
|
+
placeholder: 'Unable to load spaces',
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
export const directMessagesDropdown = ({
|
|
133
|
+
refreshers,
|
|
134
|
+
required = false,
|
|
135
|
+
}: {
|
|
136
|
+
refreshers: string[];
|
|
137
|
+
required?: boolean;
|
|
138
|
+
}) =>
|
|
139
|
+
Property.Dropdown({
|
|
140
|
+
auth: googleChatApiAuth,
|
|
141
|
+
displayName: 'Direct Message',
|
|
142
|
+
description: `Select a Direct Message${
|
|
143
|
+
required ? '' : ', leave empty for all spaces'
|
|
144
|
+
}`,
|
|
145
|
+
required,
|
|
146
|
+
refreshers,
|
|
147
|
+
async options({ auth }: any) {
|
|
148
|
+
if (!auth) {
|
|
149
|
+
return {
|
|
150
|
+
disabled: true,
|
|
151
|
+
placeholder: 'Connect your Google account first',
|
|
152
|
+
options: [],
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
const spaces = await googleChatAPIService.fetchDirectMessages(
|
|
158
|
+
auth.access_token
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
options: spaces.map((space: any) => ({
|
|
163
|
+
label: space.displayName || space.name,
|
|
164
|
+
value: space.name,
|
|
165
|
+
})),
|
|
166
|
+
};
|
|
167
|
+
} catch (e) {
|
|
168
|
+
console.error('Failed to fetch spaces', e);
|
|
169
|
+
return {
|
|
170
|
+
options: [],
|
|
171
|
+
placeholder: 'Unable to load spaces',
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
export const spacesMembersDropdown = (refreshers: string[]) =>
|
|
178
|
+
Property.Dropdown({
|
|
179
|
+
auth: googleChatApiAuth,
|
|
180
|
+
displayName: 'Space Member',
|
|
181
|
+
description: 'Select a space member, leave empty for all members',
|
|
182
|
+
required: false,
|
|
183
|
+
refreshers,
|
|
184
|
+
async options({ auth, spaceId }) {
|
|
185
|
+
if (!auth) {
|
|
186
|
+
return {
|
|
187
|
+
disabled: true,
|
|
188
|
+
placeholder: 'Connect your Google account first',
|
|
189
|
+
options: [],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (!spaceId || typeof spaceId !== 'string') {
|
|
194
|
+
return {
|
|
195
|
+
disabled: true,
|
|
196
|
+
placeholder: 'Please select a space first',
|
|
197
|
+
options: [],
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
try {
|
|
202
|
+
const members = await googleChatAPIService.fetchSpaceMembers(
|
|
203
|
+
auth.access_token,
|
|
204
|
+
spaceId
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
options: members.map((member: any) => ({
|
|
209
|
+
label: member.member.name,
|
|
210
|
+
value: member.member.name,
|
|
211
|
+
})),
|
|
212
|
+
};
|
|
213
|
+
} catch (e) {
|
|
214
|
+
console.error('Failed to fetch space members', e);
|
|
215
|
+
return {
|
|
216
|
+
options: [],
|
|
217
|
+
placeholder: 'Unable to load space members',
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
export const peoplesDropdown = (refreshers: string[]) =>
|
|
224
|
+
Property.Dropdown({
|
|
225
|
+
auth: googleChatApiAuth,
|
|
226
|
+
displayName: 'Select A Person',
|
|
227
|
+
description: 'Select a person',
|
|
228
|
+
required: true,
|
|
229
|
+
refreshers,
|
|
230
|
+
async options({ auth }) {
|
|
231
|
+
if (!auth) {
|
|
232
|
+
return {
|
|
233
|
+
disabled: true,
|
|
234
|
+
placeholder: 'Connect your Google account first',
|
|
235
|
+
options: [],
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
try {
|
|
240
|
+
const members = await googleChatAPIService.fetchPeople(
|
|
241
|
+
auth.access_token
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
options: members
|
|
246
|
+
.map((member: any) => {
|
|
247
|
+
const nameObj =
|
|
248
|
+
member.names?.find((n: any) => n.metadata.primary) ||
|
|
249
|
+
member.names?.[0];
|
|
250
|
+
if (!nameObj) return null;
|
|
251
|
+
|
|
252
|
+
return {
|
|
253
|
+
label: nameObj.displayName,
|
|
254
|
+
value: member.resourceName,
|
|
255
|
+
};
|
|
256
|
+
})
|
|
257
|
+
.filter(Boolean),
|
|
258
|
+
};
|
|
259
|
+
} catch (e) {
|
|
260
|
+
console.error('Failed to fetch people', e);
|
|
261
|
+
return {
|
|
262
|
+
options: [],
|
|
263
|
+
placeholder: 'Unable to load people',
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
export const threadsDropdown = ({
|
|
270
|
+
refreshers,
|
|
271
|
+
required = false,
|
|
272
|
+
}: {
|
|
273
|
+
refreshers: string[];
|
|
274
|
+
required?: boolean;
|
|
275
|
+
}) =>
|
|
276
|
+
Property.Dropdown({
|
|
277
|
+
auth: googleChatApiAuth,
|
|
278
|
+
displayName: 'Thread',
|
|
279
|
+
description: `Select a thread to reply to${required ? '' : ', leave empty for new thread'}`,
|
|
280
|
+
required,
|
|
281
|
+
refreshers,
|
|
282
|
+
async options({ auth, spaceId }) {
|
|
283
|
+
if (!auth) {
|
|
284
|
+
return {
|
|
285
|
+
disabled: true,
|
|
286
|
+
placeholder: 'Connect your Google account first',
|
|
287
|
+
options: [],
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (!spaceId || typeof spaceId !== 'string') {
|
|
292
|
+
return {
|
|
293
|
+
disabled: true,
|
|
294
|
+
placeholder: 'Please select a space first',
|
|
295
|
+
options: [],
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (!spaceId.startsWith('spaces/')) {
|
|
300
|
+
return {
|
|
301
|
+
disabled: true,
|
|
302
|
+
placeholder: 'Invalid space ID format. Please select a valid space.',
|
|
303
|
+
options: [],
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
try {
|
|
308
|
+
const threads = await googleChatAPIService.fetchThreads(
|
|
309
|
+
auth.access_token,
|
|
310
|
+
spaceId
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
const options = threads.map((thread: any) => ({
|
|
314
|
+
label: thread.displayName || thread.name,
|
|
315
|
+
value: thread.name,
|
|
316
|
+
}));
|
|
317
|
+
|
|
318
|
+
options.unshift({
|
|
319
|
+
label: 'Start new thread',
|
|
320
|
+
value: '',
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
return { options };
|
|
324
|
+
} catch (e) {
|
|
325
|
+
console.error('Failed to fetch threads', e);
|
|
326
|
+
return {
|
|
327
|
+
options: [],
|
|
328
|
+
placeholder: 'Unable to load threads',
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
});
|