refactor: Redesign list channels for the slack actions

This commit is contained in:
Faruk AYDIN
2022-10-07 14:00:58 +03:00
parent c958abdfcf
commit 2862953136
4 changed files with 72 additions and 14 deletions

View File

@@ -0,0 +1,36 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
export default {
name: 'List channels',
key: 'listChannels',
async run($: IGlobalVariable) {
const channels: {
data: IJSONObject[];
error: IJSONObject | null;
} = {
data: [],
error: null,
};
const response = await $.http.get('/conversations.list', {
headers: {
Authorization: `Bearer ${$.auth.data.accessToken}`,
},
});
if (response.integrationError || response.data.ok === 'false') {
channels.error = response.integrationError;
return channels;
}
channels.data = response.data.channels.map((channel: IJSONObject) => {
return {
value: channel.id,
name: channel.name,
};
});
return channels;
},
};