feat: Create send slack message action
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
fb7e679230
commit
5e1fc510ff
13
packages/backend/src/apps/slack/actions.ts
Normal file
13
packages/backend/src/apps/slack/actions.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import SendMessageToChannel from './actions/send-message-to-channel';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default class Actions {
|
||||
sendMessageToChannel: SendMessageToChannel;
|
||||
|
||||
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
||||
this.sendMessageToChannel = new SendMessageToChannel(
|
||||
connectionData,
|
||||
parameters
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
import { WebClient } from '@slack/web-api';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default class SendMessageToChannel {
|
||||
client: WebClient;
|
||||
parameters: IJSONObject;
|
||||
|
||||
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
||||
this.client = new WebClient(connectionData.accessToken as string);
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
async run() {
|
||||
const result = await this.client.chat.postMessage({
|
||||
channel: this.parameters.channel as string,
|
||||
text: this.parameters.message as string,
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -1,18 +1,25 @@
|
||||
import Authentication from './authentication';
|
||||
import Data from './data';
|
||||
import {
|
||||
IService,
|
||||
IAuthentication,
|
||||
IApp,
|
||||
IJSONObject,
|
||||
} from '@automatisch/types';
|
||||
import Authentication from './authentication';
|
||||
import Actions from './actions';
|
||||
import Data from './data';
|
||||
|
||||
export default class Slack implements IService {
|
||||
authenticationClient: IAuthentication;
|
||||
actions: Actions;
|
||||
data: Data;
|
||||
|
||||
constructor(appData: IApp, connectionData: IJSONObject) {
|
||||
constructor(
|
||||
appData: IApp,
|
||||
connectionData: IJSONObject,
|
||||
parameters: IJSONObject
|
||||
) {
|
||||
this.authenticationClient = new Authentication(appData, connectionData);
|
||||
this.data = new Data(connectionData);
|
||||
this.actions = new Actions(connectionData, parameters);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user