feat: Implement getData query and send a message action for slack

This commit is contained in:
Faruk AYDIN
2022-03-15 02:57:37 +03:00
committed by Ömer Faruk Aydın
parent f8c7b85682
commit 8512528fcf
14 changed files with 305 additions and 92 deletions

View File

@@ -0,0 +1,10 @@
import ListChannels from './data/list-channels';
import { IJSONObject } from '@automatisch/types';
export default class Data {
listChannels: ListChannels;
constructor(connectionData: IJSONObject) {
this.listChannels = new ListChannels(connectionData);
}
}

View File

@@ -0,0 +1,21 @@
import type { IJSONObject } from '@automatisch/types';
import { WebClient } from '@slack/web-api';
export default class ListChannels {
client: WebClient;
constructor(connectionData: IJSONObject) {
this.client = new WebClient(connectionData.accessToken as string);
}
async run() {
const { channels } = await this.client.conversations.list();
return channels.map((channel) => {
return {
value: channel.id,
name: channel.name,
};
});
}
}

View File

@@ -1,4 +1,5 @@
import Authentication from './authentication';
import Data from './data';
import {
IService,
IAuthentication,
@@ -8,8 +9,10 @@ import {
export default class Slack implements IService {
authenticationClient: IAuthentication;
data: Data;
constructor(appData: IApp, connectionData: IJSONObject) {
this.authenticationClient = new Authentication(appData, connectionData);
this.data = new Data(connectionData);
}
}

View File

@@ -96,5 +96,58 @@
}
]
}
],
"actions": [
{
"name": "Send a message to channel",
"key": "sendMessageToChannel",
"description": "Send a message to a specific channel you specify.",
"substeps": [
{
"key": "chooseAccount",
"name": "Choose account"
},
{
"key": "setupAction",
"name": "Set up action",
"arguments": [
{
"label": "Channel",
"key": "channel",
"type": "dropdown",
"required": true,
"description": "Pick a channel to send the message to.",
"variables": false,
"source": {
"type": "query",
"name": "getData",
"arguments": [
{
"name": "stepId",
"value": "{step.id}"
},
{
"name": "key",
"value": "listChannels"
}
]
}
},
{
"label": "Message text",
"key": "message",
"type": "string",
"required": true,
"description": "The content of your new message.",
"variables": true
}
]
},
{
"key": "testStep",
"name": "Test action"
}
]
}
]
}

View File

@@ -221,7 +221,7 @@
"key": "myTweet",
"interval": "15m",
"description": "Will be triggered when you tweet something new.",
"subSteps": [
"substeps": [
{
"key": "chooseAccount",
"name": "Choose account"
@@ -236,7 +236,7 @@
"name": "User Tweet",
"key": "userTweet",
"description": "Will be triggered when a specific user tweet something new.",
"subSteps": [
"substeps": [
{
"key": "chooseAccount",
"name": "Choose account"
@@ -263,7 +263,7 @@
"name": "Search Tweet",
"key": "searchTweet",
"description": "Will be triggered when any user tweet something containing a specific keyword, phrase, username or hashtag.",
"subSteps": [
"substeps": [
{
"key": "chooseAccount",
"name": "Choose account"
@@ -292,7 +292,7 @@
"name": "Create Tweet",
"key": "createTweet",
"description": "Will create a tweet.",
"subSteps": [
"substeps": [
{
"key": "chooseAccount",
"name": "Choose account"

View File

@@ -0,0 +1,31 @@
import App from '../../models/app';
import Connection from '../../models/connection';
import Step from '../../models/step';
import { IApp } from '@automatisch/types';
import Context from '../../types/express/context';
import ListData from '../../apps/slack/data/list-channels';
type Params = {
stepId: string;
key: string;
};
const getData = async (_parent: unknown, params: Params, context: Context) => {
const step = await context.currentUser
.$relatedQuery('steps')
.withGraphFetched('connection')
.findById(params.stepId);
const connection = step.connection;
const appData = App.findOneByKey(step.appKey);
const AppClass = (await import(`../../apps/${step.appKey}`)).default;
const appInstance = new AppClass(appData, connection.formattedData);
const command = appInstance.data[params.key];
const fetchedData = await command.run();
return fetchedData;
};
export default getData;

View File

@@ -8,6 +8,7 @@ import getFlows from './queries/get-flows';
import getStepWithTestExecutions from './queries/get-step-with-test-executions';
import getExecutions from './queries/get-executions';
import getExecutionSteps from './queries/get-execution-steps';
import getData from './queries/get-data';
const queryResolvers = {
getApps,
@@ -20,6 +21,7 @@ const queryResolvers = {
getStepWithTestExecutions,
getExecutions,
getExecutionSteps,
getData,
};
export default queryResolvers;

View File

@@ -13,6 +13,7 @@ type Query {
limit: Int!
offset: Int!
): ExecutionStepConnection
getData(stepId: String!, key: String!): JSONObject
}
type Mutation {
@@ -48,22 +49,34 @@ type Action {
name: String
key: String
description: String
subSteps: [ActionSubStep]
substeps: [ActionSubstep]
}
type ActionSubStep {
type ActionSubstep {
key: String
name: String
arguments: [ActionSubStepArgument]
arguments: [ActionSubstepArgument]
}
type ActionSubStepArgument {
type ActionSubstepArgument {
label: String
key: String
type: String
description: String
required: Boolean
variables: Boolean
source: ActionSubstepArgumentSource
}
type ActionSubstepArgumentSource {
type: String
name: String
arguments: [ActionSubstepArgumentSourceArgument]
}
type ActionSubstepArgumentSourceArgument {
name: String
value: String
}
type App {
@@ -337,16 +350,16 @@ type Trigger {
name: String
key: String
description: String
subSteps: [TriggerSubStep]
substeps: [TriggerSubstep]
}
type TriggerSubStep {
type TriggerSubstep {
key: String
name: String
arguments: [TriggerSubStepArgument]
arguments: [TriggerSubstepArgument]
}
type TriggerSubStepArgument {
type TriggerSubstepArgument {
label: String
key: String
type: String

View File

@@ -9,6 +9,7 @@ class ExecutionStep extends Base {
dataIn!: Record<string, unknown>;
dataOut!: Record<string, unknown>;
status: string;
step: Step;
static tableName = 'execution_steps';

View File

@@ -78,6 +78,16 @@ class Processor {
fetchedActionData = await command.run();
}
console.log(
'previous execution step dataOut :',
previousExecutionStep?.dataOut
);
console.log(
'previous execution step parameters :',
previousExecutionStep?.step.parameters
);
previousExecutionStep = await execution
.$relatedQuery('executionSteps')
.insertAndFetch({