feat(slack/list-channels): add im channels and increase limit
This commit is contained in:
@@ -29,6 +29,7 @@ const userScopes = [
|
|||||||
'groups:history',
|
'groups:history',
|
||||||
'groups:read',
|
'groups:read',
|
||||||
'groups:write',
|
'groups:write',
|
||||||
|
'im:read',
|
||||||
'im:write',
|
'im:write',
|
||||||
'mpim:write',
|
'mpim:write',
|
||||||
'reactions:read',
|
'reactions:read',
|
||||||
|
@@ -1,5 +1,24 @@
|
|||||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
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 {
|
export default {
|
||||||
name: 'List channels',
|
name: 'List channels',
|
||||||
key: 'listChannels',
|
key: 'listChannels',
|
||||||
@@ -13,24 +32,33 @@ export default {
|
|||||||
error: null,
|
error: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await $.http.get('/conversations.list', {
|
let nextCursor;
|
||||||
params: {
|
do {
|
||||||
types: 'public_channel,private_channel',
|
const response: TResponse = await $.http.get('/conversations.list', {
|
||||||
limit: 1000,
|
params: {
|
||||||
exclude_archived: true,
|
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) {
|
if (response.data.ok === false) {
|
||||||
throw new Error(response.data);
|
throw new Error(JSON.stringify(response.data, null, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
channels.data = response.data.channels.map((channel: IJSONObject) => {
|
for (const channel of response.data.channels) {
|
||||||
return {
|
channels.data.push({
|
||||||
value: channel.id,
|
value: channel.id as string,
|
||||||
name: channel.name,
|
name: channel.name as string,
|
||||||
};
|
});
|
||||||
});
|
}
|
||||||
|
} while (nextCursor);
|
||||||
|
|
||||||
return channels;
|
return channels;
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user