feat(slack/list-channels): add im channels and increase limit

This commit is contained in:
Ali BARIN
2023-02-08 20:18:11 +00:00
parent 113a91a73f
commit 3d98e6cdc0
2 changed files with 44 additions and 15 deletions

View File

@@ -29,6 +29,7 @@ const userScopes = [
'groups:history',
'groups:read',
'groups:write',
'im:read',
'im:write',
'mpim:write',
'reactions:read',

View File

@@ -1,5 +1,24 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
type TChannel = {
id: string;
name: string;
}
type TConversationListResponseData = {
channels: TChannel[],
response_metadata?: {
next_cursor: string
};
needed?: string;
error?: string;
ok: boolean;
}
type TResponse = {
data: TConversationListResponseData;
}
export default {
name: 'List channels',
key: 'listChannels',
@@ -13,24 +32,33 @@ export default {
error: null,
};
const response = await $.http.get('/conversations.list', {
params: {
types: 'public_channel,private_channel',
limit: 1000,
exclude_archived: true,
let nextCursor;
do {
const response: TResponse = await $.http.get('/conversations.list', {
params: {
types: 'public_channel,private_channel,im',
cursor: nextCursor,
limit: 1000,
}
});
nextCursor = response.data.response_metadata?.next_cursor;
if (response.data.error === 'missing_scope') {
throw new Error(`Missing "${response.data.needed}" scope while authorizing. Please, reconnect your connection!`);
}
});
if (response.data.ok === false) {
throw new Error(response.data);
}
if (response.data.ok === false) {
throw new Error(JSON.stringify(response.data, null, 2));
}
channels.data = response.data.channels.map((channel: IJSONObject) => {
return {
value: channel.id,
name: channel.name,
};
});
for (const channel of response.data.channels) {
channels.data.push({
value: channel.id as string,
name: channel.name as string,
});
}
} while (nextCursor);
return channels;
},