Skip to content

Commit a97dfc2

Browse files
authored
Get Users for a Queue (#2)
1 parent e74a46b commit a97dfc2

File tree

7 files changed

+159
-6
lines changed

7 files changed

+159
-6
lines changed

nodes/GenesysCloud/GenericFunctions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function genesysCloudApiRequest(
1313
this: IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions,
1414
method: IHttpRequestMethods,
1515
resource: string,
16-
body: IDataObject = {},
16+
body: IDataObject | IDataObject[] = {},
1717
query: IDataObject = {},
1818
) {
1919
const credentials = await this.getCredentials('genesysCloudPlatformApiOAuth2Api');

nodes/GenesysCloud/QueueDescription.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export const queueOperations: INodeProperties[] = [
1212
},
1313
},
1414
options: [
15+
{
16+
name: 'Add Members',
17+
value: 'addMembers',
18+
description: 'Add members to a queue',
19+
action: 'Add members to a queue',
20+
},
1521
{
1622
name: 'Create',
1723
value: 'create',
@@ -290,7 +296,7 @@ export const queueFields: INodeProperties[] = [
290296
displayOptions: {
291297
show: {
292298
resource: ['queue'],
293-
operation: ['get', 'getMembers'],
299+
operation: ['get', 'getMembers', 'addMembers'],
294300
},
295301
},
296302
description: 'ID of queue that needs to be fetched',
@@ -546,4 +552,21 @@ export const queueFields: INodeProperties[] = [
546552
},
547553
],
548554
},
555+
/* -------------------------------------------------------------------------- */
556+
/* queue:addMembers */
557+
/* -------------------------------------------------------------------------- */
558+
{
559+
displayName: 'User IDs',
560+
name: 'userIds',
561+
type: 'string',
562+
required: true,
563+
default: '',
564+
displayOptions: {
565+
show: {
566+
resource: ['queue'],
567+
operation: ['addMembers'],
568+
},
569+
},
570+
description: 'Comma-separated list or Array of user IDs to add to the queue',
571+
},
549572
];

nodes/GenesysCloud/QueueOperation.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export async function queueOperation(
1515
return getAll.call(this, index);
1616
} else if (operation === 'getMembers') {
1717
return getMembers.call(this, index);
18+
} else if (operation === 'addMembers') {
19+
return addMembers.call(this, index);
1820
}
1921

2022
return [];
@@ -121,3 +123,30 @@ export async function getMembers(
121123
{ itemData: { item: index } },
122124
);
123125
}
126+
127+
export async function addMembers(
128+
this: IExecuteFunctions,
129+
index: number,
130+
): Promise<INodeExecutionData[]> {
131+
const queueId = this.getNodeParameter('queueId', index) as string;
132+
const userIds = this.getNodeParameter('userIds', index) as string | string[];
133+
134+
let members: IDataObject[] = [];
135+
if (Array.isArray(userIds)) {
136+
members = userIds.map((id) => ({ id: id.trim() }));
137+
} else {
138+
members = userIds.split(',').map((id) => ({ id: id.trim() }));
139+
}
140+
141+
const responseData = await genesysCloudApiRequest.call(
142+
this,
143+
'POST',
144+
`/api/v2/routing/queues/${queueId}/members`,
145+
members,
146+
);
147+
148+
return this.helpers.constructExecutionMetaData(
149+
this.helpers.returnJsonArray(responseData as IDataObject[]),
150+
{ itemData: { item: index } },
151+
);
152+
}

nodes/GenesysCloud/UserDescription.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ export const userOperations: INodeProperties[] = [
2424
description: 'Get many users',
2525
action: 'Get many users',
2626
},
27+
{
28+
name: 'Get Queues',
29+
value: 'getQueues',
30+
description: 'Get queues for a user',
31+
action: 'Get queues for a user',
32+
},
2733
],
2834
default: 'get',
2935
},
@@ -42,7 +48,7 @@ export const userFields: INodeProperties[] = [
4248
displayOptions: {
4349
show: {
4450
resource: ['user'],
45-
operation: ['get'],
51+
operation: ['get', 'getQueues'],
4652
},
4753
},
4854
description: 'The ID of the user',
@@ -58,7 +64,7 @@ export const userFields: INodeProperties[] = [
5864
displayOptions: {
5965
show: {
6066
resource: ['user'],
61-
operation: ['getAll'],
67+
operation: ['getAll', 'getQueues'],
6268
},
6369
},
6470
default: false,
@@ -71,7 +77,7 @@ export const userFields: INodeProperties[] = [
7177
displayOptions: {
7278
show: {
7379
resource: ['user'],
74-
operation: ['getAll'],
80+
operation: ['getAll', 'getQueues'],
7581
returnAll: [false],
7682
},
7783
},
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import type { IExecuteFunctions } from 'n8n-workflow';
2+
import { userOperation } from './UserOperation';
3+
import * as GenericFunctions from './GenericFunctions';
4+
5+
describe('UserOperation', () => {
6+
const mockExecuteFunctions = {
7+
getNodeParameter: jest.fn(),
8+
helpers: {
9+
constructExecutionMetaData: jest.fn().mockImplementation((data) => data),
10+
returnJsonArray: jest.fn().mockImplementation((data) => data),
11+
},
12+
} as unknown as IExecuteFunctions & {
13+
getNodeParameter: jest.Mock;
14+
helpers: {
15+
constructExecutionMetaData: jest.Mock;
16+
returnJsonArray: jest.Mock;
17+
};
18+
};
19+
20+
beforeEach(() => {
21+
jest.clearAllMocks();
22+
});
23+
24+
describe('getQueues', () => {
25+
it('should retrieve queues for a user', async () => {
26+
const index = 0;
27+
const userId = 'test-user-id';
28+
const returnAll = true;
29+
const response = [{ id: 'queue-1', name: 'Queue 1' }];
30+
31+
mockExecuteFunctions.getNodeParameter.mockImplementation((paramName: string) => {
32+
if (paramName === 'operation') return 'getQueues';
33+
if (paramName === 'userId') return userId;
34+
if (paramName === 'returnAll') return returnAll;
35+
return undefined;
36+
});
37+
38+
jest.spyOn(GenericFunctions, 'genesysCloudApiRequestAllItems').mockResolvedValue(response);
39+
40+
await userOperation.call(mockExecuteFunctions, index);
41+
42+
expect(GenericFunctions.genesysCloudApiRequestAllItems).toHaveBeenCalledWith(
43+
'entities',
44+
'GET',
45+
`/api/v2/users/${userId}/queues`,
46+
{},
47+
{},
48+
0,
49+
);
50+
});
51+
52+
it('should retrieve queues for a user with limit', async () => {
53+
const index = 0;
54+
const userId = 'test-user-id';
55+
const returnAll = false;
56+
const limit = 5;
57+
const response = [{ id: 'queue-1', name: 'Queue 1' }];
58+
59+
mockExecuteFunctions.getNodeParameter.mockImplementation((paramName: string) => {
60+
if (paramName === 'operation') return 'getQueues';
61+
if (paramName === 'userId') return userId;
62+
if (paramName === 'returnAll') return returnAll;
63+
if (paramName === 'limit') return limit;
64+
return undefined;
65+
});
66+
67+
jest.spyOn(GenericFunctions, 'genesysCloudApiRequestAllItems').mockResolvedValue(response);
68+
69+
await userOperation.call(mockExecuteFunctions, index);
70+
71+
expect(GenericFunctions.genesysCloudApiRequestAllItems).toHaveBeenCalledWith(
72+
'entities',
73+
'GET',
74+
`/api/v2/users/${userId}/queues`,
75+
{},
76+
{},
77+
limit,
78+
);
79+
});
80+
});
81+
});

nodes/GenesysCloud/UserOperation.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ export async function userOperation(
3434
qs,
3535
limit,
3636
);
37+
} else if (operation === 'getQueues') {
38+
const userId = this.getNodeParameter('userId', index) as string;
39+
const returnAll = this.getNodeParameter('returnAll', index) as boolean;
40+
const limit = returnAll ? 0 : (this.getNodeParameter('limit', index) as number);
41+
42+
responseData = await genesysCloudApiRequestAllItems.call(
43+
this,
44+
'entities',
45+
'GET',
46+
`/api/v2/users/${userId}/queues`,
47+
{},
48+
qs,
49+
limit,
50+
);
3751
}
3852

3953
return this.helpers.constructExecutionMetaData(

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@makingchatbots/n8n-nodes-genesys-cloud",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "n8n node for interacting with Genesys Cloud's Platform API",
55
"license": "MIT",
66
"homepage": "https://makingchatbots.com",

0 commit comments

Comments
 (0)