refactor: Introduce IActionOutput and ITriggerOutput types
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
import { IGlobalVariable, IActionOutput } from '@automatisch/types';
|
||||
|
||||
type FindMessageOptions = {
|
||||
query: string;
|
||||
@@ -8,11 +8,6 @@ type FindMessageOptions = {
|
||||
};
|
||||
|
||||
const findMessage = async ($: IGlobalVariable, options: FindMessageOptions) => {
|
||||
const message: {
|
||||
data?: IJSONObject;
|
||||
error?: IJSONObject;
|
||||
} = {};
|
||||
|
||||
const headers = {
|
||||
Authorization: `Bearer ${$.auth.data.accessToken}`,
|
||||
};
|
||||
@@ -29,20 +24,14 @@ const findMessage = async ($: IGlobalVariable, options: FindMessageOptions) => {
|
||||
params,
|
||||
});
|
||||
|
||||
if (response.integrationError) {
|
||||
message.error = response.integrationError;
|
||||
return message;
|
||||
}
|
||||
|
||||
const data = response.data;
|
||||
|
||||
if (!data.ok) {
|
||||
message.error = data;
|
||||
return message;
|
||||
}
|
||||
|
||||
const messages = data.messages.matches;
|
||||
message.data = messages?.[0];
|
||||
const message: IActionOutput = {
|
||||
data: {
|
||||
raw: data?.data?.messages.matches[0],
|
||||
},
|
||||
error: response?.integrationError || (!data.ok && data),
|
||||
};
|
||||
|
||||
return message;
|
||||
};
|
||||
|
@@ -72,7 +72,7 @@ export default {
|
||||
],
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const parameters = $.db.step.parameters;
|
||||
const parameters = $.step.parameters;
|
||||
const query = parameters.query as string;
|
||||
const sortBy = parameters.sortBy as string;
|
||||
const sortDirection = parameters.sortDirection as string;
|
||||
|
@@ -49,8 +49,8 @@ export default {
|
||||
],
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const channelId = $.db.step.parameters.channel as string;
|
||||
const text = $.db.step.parameters.message as string;
|
||||
const channelId = $.step.parameters.channel as string;
|
||||
const text = $.step.parameters.message as string;
|
||||
|
||||
const message = await postMessage($, channelId, text);
|
||||
|
||||
|
@@ -1,18 +1,10 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
import { IGlobalVariable, IActionOutput } from '@automatisch/types';
|
||||
|
||||
const postMessage = async (
|
||||
$: IGlobalVariable,
|
||||
channelId: string,
|
||||
text: string
|
||||
) => {
|
||||
const message: {
|
||||
data: IJSONObject | null | undefined;
|
||||
error: IJSONObject | null | undefined;
|
||||
} = {
|
||||
data: null,
|
||||
error: null,
|
||||
};
|
||||
|
||||
const headers = {
|
||||
Authorization: `Bearer ${$.auth.data.accessToken}`,
|
||||
};
|
||||
@@ -24,8 +16,12 @@ const postMessage = async (
|
||||
|
||||
const response = await $.http.post('/chat.postMessage', params, { headers });
|
||||
|
||||
message.error = response?.integrationError;
|
||||
message.data = response?.data?.message;
|
||||
const message: IActionOutput = {
|
||||
data: {
|
||||
raw: response?.data?.message,
|
||||
},
|
||||
error: response?.integrationError,
|
||||
};
|
||||
|
||||
if (response.data.ok === false) {
|
||||
message.error = response.data;
|
||||
|
Reference in New Issue
Block a user