first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
import type { IDataObject, ILoadOptionsFunctions, INodePropertyOptions } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { apiRequestAllItems } from '../transport';
|
||||
|
||||
// Get all the available channels
|
||||
export async function getChannels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const endpoint = 'channels';
|
||||
const responseData = await apiRequestAllItems.call(this, 'GET', endpoint, {});
|
||||
|
||||
if (responseData === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'No data got returned');
|
||||
}
|
||||
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
let name: string;
|
||||
for (const data of responseData) {
|
||||
if (data.delete_at !== 0 || !data.display_name || !data.name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
name = `${data.team_display_name} - ${data.display_name || data.name} (${
|
||||
data.type === 'O' ? 'public' : 'private'
|
||||
})`;
|
||||
|
||||
returnData.push({
|
||||
name,
|
||||
value: data.id as string,
|
||||
});
|
||||
}
|
||||
|
||||
returnData.sort((a, b) => {
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
// Get all the channels in a team
|
||||
export async function getChannelsInTeam(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
const teamId = this.getCurrentNodeParameter('teamId');
|
||||
const endpoint = `users/me/teams/${teamId}/channels`;
|
||||
const responseData = await apiRequestAllItems.call(this, 'GET', endpoint, {});
|
||||
|
||||
if (responseData === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'No data got returned');
|
||||
}
|
||||
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
let name: string;
|
||||
for (const data of responseData) {
|
||||
if (data.delete_at !== 0 || !data.display_name || !data.name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const channelTypes: IDataObject = {
|
||||
D: 'direct',
|
||||
G: 'group',
|
||||
O: 'public',
|
||||
P: 'private',
|
||||
};
|
||||
|
||||
name = `${data.display_name} (${channelTypes[data.type as string]})`;
|
||||
|
||||
returnData.push({
|
||||
name,
|
||||
value: data.id as string,
|
||||
});
|
||||
}
|
||||
|
||||
returnData.sort((a, b) => {
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
export async function getTeams(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const endpoint = 'users/me/teams';
|
||||
const responseData = await apiRequestAllItems.call(this, 'GET', endpoint, {});
|
||||
|
||||
if (responseData === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'No data got returned');
|
||||
}
|
||||
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
let name: string;
|
||||
for (const data of responseData) {
|
||||
if (data.delete_at !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
name = `${data.display_name} (${data.type === 'O' ? 'public' : 'private'})`;
|
||||
|
||||
returnData.push({
|
||||
name,
|
||||
value: data.id as string,
|
||||
});
|
||||
}
|
||||
|
||||
returnData.sort((a, b) => {
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
export async function getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const endpoint = 'users';
|
||||
const responseData = await apiRequestAllItems.call(this, 'GET', endpoint, {});
|
||||
|
||||
if (responseData === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'No data got returned');
|
||||
}
|
||||
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
for (const data of responseData) {
|
||||
if (data.delete_at !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
returnData.push({
|
||||
name: data.username as string,
|
||||
value: data.id as string,
|
||||
});
|
||||
}
|
||||
|
||||
returnData.sort((a, b) => {
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
return returnData;
|
||||
}
|
||||
Reference in New Issue
Block a user