refactor: Adjust send a message to channel to use slack client

This commit is contained in:
Faruk AYDIN
2022-09-01 23:19:53 +03:00
parent 26eee1bb63
commit e0f055a375
5 changed files with 52 additions and 20 deletions

View File

@@ -0,0 +1,34 @@
import SlackClient from '../index';
export default class PostMessageToChannel {
client: SlackClient;
constructor(client: SlackClient) {
this.client = client;
}
async run(channelId: string, text: string) {
const headers = {
Authorization: `Bearer ${this.client.connection.formattedData.accessToken}`,
};
const params = {
channel: channelId,
text,
};
const response = await this.client.httpClient.post(
'/chat.postMessage',
params,
{ headers }
);
if (response.data.ok === 'false') {
throw new Error(
`Error occured while posting a message to channel: ${response.data.error}`
);
}
return response.data.message;
}
}