refactor: Adjust slack list channels to use slack client
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import ListChannels from './data/list-channels';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
import SlackClient from './client';
|
||||
|
||||
export default class Data {
|
||||
client: SlackClient;
|
||||
listChannels: ListChannels;
|
||||
|
||||
constructor(connectionData: IJSONObject) {
|
||||
this.listChannels = new ListChannels(connectionData);
|
||||
constructor(client: SlackClient) {
|
||||
this.client = client;
|
||||
this.listChannels = new ListChannels(client);
|
||||
}
|
||||
}
|
||||
|
@@ -1,17 +1,27 @@
|
||||
import type { IJSONObject } from '@automatisch/types';
|
||||
import { WebClient } from '@slack/web-api';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
import SlackClient from '../client';
|
||||
|
||||
export default class ListChannels {
|
||||
client: WebClient;
|
||||
client: SlackClient;
|
||||
|
||||
constructor(connectionData: IJSONObject) {
|
||||
this.client = new WebClient(connectionData.accessToken as string);
|
||||
constructor(client: SlackClient) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
async run() {
|
||||
const { channels } = await this.client.conversations.list();
|
||||
const response = await this.client.httpClient.get('/conversations.list', {
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.client.connection.formattedData.accessToken}`,
|
||||
},
|
||||
});
|
||||
|
||||
return channels.map((channel) => {
|
||||
if (response.data.ok === 'false') {
|
||||
throw new Error(
|
||||
`Error occured while fetching slack channels: ${response.data.error}`
|
||||
);
|
||||
}
|
||||
|
||||
return response.data.channels.map((channel: IJSONObject) => {
|
||||
return {
|
||||
value: channel.id,
|
||||
name: channel.name,
|
||||
|
@@ -26,6 +26,6 @@ export default class Slack implements IService {
|
||||
|
||||
// this.triggers = new Triggers(this.client);
|
||||
// this.actions = new Actions(this.client);
|
||||
// this.data = new Data(this.client);
|
||||
this.data = new Data(this.client);
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,10 @@ type Params = {
|
||||
const getData = async (_parent: unknown, params: Params, context: Context) => {
|
||||
const step = await context.currentUser
|
||||
.$relatedQuery('steps')
|
||||
.withGraphFetched('connection, flow')
|
||||
.withGraphFetched({
|
||||
connection: true,
|
||||
flow: true,
|
||||
})
|
||||
.findById(params.stepId);
|
||||
|
||||
if (!step) return null;
|
||||
|
Reference in New Issue
Block a user