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 ListChannels from './data/list-channels';
|
||||||
import { IJSONObject } from '@automatisch/types';
|
import SlackClient from './client';
|
||||||
|
|
||||||
export default class Data {
|
export default class Data {
|
||||||
|
client: SlackClient;
|
||||||
listChannels: ListChannels;
|
listChannels: ListChannels;
|
||||||
|
|
||||||
constructor(connectionData: IJSONObject) {
|
constructor(client: SlackClient) {
|
||||||
this.listChannels = new ListChannels(connectionData);
|
this.client = client;
|
||||||
|
this.listChannels = new ListChannels(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,17 +1,27 @@
|
|||||||
import type { IJSONObject } from '@automatisch/types';
|
import { IJSONObject } from '@automatisch/types';
|
||||||
import { WebClient } from '@slack/web-api';
|
import SlackClient from '../client';
|
||||||
|
|
||||||
export default class ListChannels {
|
export default class ListChannels {
|
||||||
client: WebClient;
|
client: SlackClient;
|
||||||
|
|
||||||
constructor(connectionData: IJSONObject) {
|
constructor(client: SlackClient) {
|
||||||
this.client = new WebClient(connectionData.accessToken as string);
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
async run() {
|
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 {
|
return {
|
||||||
value: channel.id,
|
value: channel.id,
|
||||||
name: channel.name,
|
name: channel.name,
|
||||||
|
@@ -26,6 +26,6 @@ export default class Slack implements IService {
|
|||||||
|
|
||||||
// this.triggers = new Triggers(this.client);
|
// this.triggers = new Triggers(this.client);
|
||||||
// this.actions = new Actions(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 getData = async (_parent: unknown, params: Params, context: Context) => {
|
||||||
const step = await context.currentUser
|
const step = await context.currentUser
|
||||||
.$relatedQuery('steps')
|
.$relatedQuery('steps')
|
||||||
.withGraphFetched('connection, flow')
|
.withGraphFetched({
|
||||||
|
connection: true,
|
||||||
|
flow: true,
|
||||||
|
})
|
||||||
.findById(params.stepId);
|
.findById(params.stepId);
|
||||||
|
|
||||||
if (!step) return null;
|
if (!step) return null;
|
||||||
|
Reference in New Issue
Block a user