feat(discord): add list channels data
This commit is contained in:
5
packages/backend/src/apps/discord/data/index.ts
Normal file
5
packages/backend/src/apps/discord/data/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import listChannels from "./list-channels";
|
||||
|
||||
export default [
|
||||
listChannels,
|
||||
];
|
@@ -0,0 +1,32 @@
|
||||
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(`/guilds/${$.auth.data.guildId}/channels`);
|
||||
|
||||
channels.data = response.data
|
||||
.filter((channel: IJSONObject) => {
|
||||
// filter in text channels only
|
||||
return channel.type === 0;
|
||||
})
|
||||
.map((channel: IJSONObject) => {
|
||||
return {
|
||||
value: channel.id,
|
||||
name: channel.name,
|
||||
};
|
||||
});
|
||||
|
||||
return channels;
|
||||
},
|
||||
};
|
@@ -1,6 +1,7 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
import addAuthHeader from './common/add-auth-header';
|
||||
import auth from './auth';
|
||||
import data from './data';
|
||||
import actions from './actions';
|
||||
import triggers from './triggers';
|
||||
|
||||
@@ -15,6 +16,7 @@ export default defineApp({
|
||||
primaryColor: '5865f2',
|
||||
beforeRequest: [addAuthHeader],
|
||||
auth,
|
||||
data,
|
||||
triggers,
|
||||
actions,
|
||||
});
|
||||
|
Reference in New Issue
Block a user