refactor: Introduce IActionOutput and ITriggerOutput types
This commit is contained in:
@@ -24,13 +24,13 @@ export default {
|
||||
options: [
|
||||
{
|
||||
label: 'Yes',
|
||||
value: true
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
label: 'No',
|
||||
value: false
|
||||
}
|
||||
]
|
||||
value: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Time of day',
|
||||
@@ -42,111 +42,111 @@ export default {
|
||||
options: [
|
||||
{
|
||||
label: '00:00',
|
||||
value: 0
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
label: '01:00',
|
||||
value: 1
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
label: '02:00',
|
||||
value: 2
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
label: '03:00',
|
||||
value: 3
|
||||
value: 3,
|
||||
},
|
||||
{
|
||||
label: '04:00',
|
||||
value: 4
|
||||
value: 4,
|
||||
},
|
||||
{
|
||||
label: '05:00',
|
||||
value: 5
|
||||
value: 5,
|
||||
},
|
||||
{
|
||||
label: '06:00',
|
||||
value: 6
|
||||
value: 6,
|
||||
},
|
||||
{
|
||||
label: '07:00',
|
||||
value: 7
|
||||
value: 7,
|
||||
},
|
||||
{
|
||||
label: '08:00',
|
||||
value: 8
|
||||
value: 8,
|
||||
},
|
||||
{
|
||||
label: '09:00',
|
||||
value: 9
|
||||
value: 9,
|
||||
},
|
||||
{
|
||||
label: '10:00',
|
||||
value: 10
|
||||
value: 10,
|
||||
},
|
||||
{
|
||||
label: '11:00',
|
||||
value: 11
|
||||
value: 11,
|
||||
},
|
||||
{
|
||||
label: '12:00',
|
||||
value: 12
|
||||
value: 12,
|
||||
},
|
||||
{
|
||||
label: '13:00',
|
||||
value: 13
|
||||
value: 13,
|
||||
},
|
||||
{
|
||||
label: '14:00',
|
||||
value: 14
|
||||
value: 14,
|
||||
},
|
||||
{
|
||||
label: '15:00',
|
||||
value: 15
|
||||
value: 15,
|
||||
},
|
||||
{
|
||||
label: '16:00',
|
||||
value: 16
|
||||
value: 16,
|
||||
},
|
||||
{
|
||||
label: '17:00',
|
||||
value: 17
|
||||
value: 17,
|
||||
},
|
||||
{
|
||||
label: '18:00',
|
||||
value: 18
|
||||
value: 18,
|
||||
},
|
||||
{
|
||||
label: '19:00',
|
||||
value: 19
|
||||
value: 19,
|
||||
},
|
||||
{
|
||||
label: '20:00',
|
||||
value: 20
|
||||
value: 20,
|
||||
},
|
||||
{
|
||||
label: '21:00',
|
||||
value: 21
|
||||
value: 21,
|
||||
},
|
||||
{
|
||||
label: '22:00',
|
||||
value: 22
|
||||
value: 22,
|
||||
},
|
||||
{
|
||||
label: '23:00',
|
||||
value: 23
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
value: 23,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'testStep',
|
||||
name: 'Test trigger'
|
||||
}
|
||||
name: 'Test trigger',
|
||||
},
|
||||
],
|
||||
|
||||
getInterval(parameters: IGlobalVariable["db"]["step"]["parameters"]) {
|
||||
getInterval(parameters: IGlobalVariable['step']['parameters']) {
|
||||
if (parameters.triggersOnWeekend as boolean) {
|
||||
return cronTimes.everyDayAt(parameters.hour as number);
|
||||
}
|
||||
@@ -156,14 +156,20 @@ export default {
|
||||
|
||||
async run($: IGlobalVariable, startDateTime: Date) {
|
||||
const dateTime = DateTime.fromJSDate(startDateTime);
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(dateTime) as IJSONValue;
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
|
||||
dateTime
|
||||
) as IJSONValue;
|
||||
|
||||
return { data: [dateTimeObjectRepresentation] };
|
||||
},
|
||||
|
||||
async testRun($: IGlobalVariable) {
|
||||
const nextCronDateTime = getNextCronDateTime(this.getInterval($.db.step.parameters));
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(nextCronDateTime) as IJSONValue;
|
||||
const nextCronDateTime = getNextCronDateTime(
|
||||
this.getInterval($.step.parameters)
|
||||
);
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
|
||||
nextCronDateTime
|
||||
) as IJSONValue;
|
||||
|
||||
return { data: [dateTimeObjectRepresentation] };
|
||||
},
|
||||
|
@@ -24,25 +24,25 @@ export default {
|
||||
options: [
|
||||
{
|
||||
label: 'Yes',
|
||||
value: true
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
label: 'No',
|
||||
value: false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
value: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'testStep',
|
||||
name: 'Test trigger'
|
||||
}
|
||||
name: 'Test trigger',
|
||||
},
|
||||
],
|
||||
|
||||
getInterval(parameters: IGlobalVariable["db"]["step"]["parameters"]) {
|
||||
getInterval(parameters: IGlobalVariable['step']['parameters']) {
|
||||
if (parameters.triggersOnWeekend) {
|
||||
return cronTimes.everyHour
|
||||
return cronTimes.everyHour;
|
||||
}
|
||||
|
||||
return cronTimes.everyHourExcludingWeekends;
|
||||
@@ -50,14 +50,20 @@ export default {
|
||||
|
||||
async run($: IGlobalVariable, startDateTime: Date) {
|
||||
const dateTime = DateTime.fromJSDate(startDateTime);
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(dateTime) as IJSONValue;
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
|
||||
dateTime
|
||||
) as IJSONValue;
|
||||
|
||||
return { data: [dateTimeObjectRepresentation] };
|
||||
},
|
||||
|
||||
async testRun($: IGlobalVariable) {
|
||||
const nextCronDateTime = getNextCronDateTime(this.getInterval($.db.step.parameters));
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(nextCronDateTime) as IJSONValue;
|
||||
const nextCronDateTime = getNextCronDateTime(
|
||||
this.getInterval($.step.parameters)
|
||||
);
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
|
||||
nextCronDateTime
|
||||
) as IJSONValue;
|
||||
|
||||
return { data: [dateTimeObjectRepresentation] };
|
||||
},
|
||||
|
@@ -23,129 +23,129 @@ export default {
|
||||
options: [
|
||||
{
|
||||
label: 1,
|
||||
value: 1
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
label: 2,
|
||||
value: 2
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
label: 3,
|
||||
value: 3
|
||||
value: 3,
|
||||
},
|
||||
{
|
||||
label: 4,
|
||||
value: 4
|
||||
value: 4,
|
||||
},
|
||||
{
|
||||
label: 5,
|
||||
value: 5
|
||||
value: 5,
|
||||
},
|
||||
{
|
||||
label: 6,
|
||||
value: 6
|
||||
value: 6,
|
||||
},
|
||||
{
|
||||
label: 7,
|
||||
value: 7
|
||||
value: 7,
|
||||
},
|
||||
{
|
||||
label: 8,
|
||||
value: 8
|
||||
value: 8,
|
||||
},
|
||||
{
|
||||
label: 9,
|
||||
value: 9
|
||||
value: 9,
|
||||
},
|
||||
{
|
||||
label: 10,
|
||||
value: 10
|
||||
value: 10,
|
||||
},
|
||||
{
|
||||
label: 11,
|
||||
value: 11
|
||||
value: 11,
|
||||
},
|
||||
{
|
||||
label: 12,
|
||||
value: 12
|
||||
value: 12,
|
||||
},
|
||||
{
|
||||
label: 13,
|
||||
value: 13
|
||||
value: 13,
|
||||
},
|
||||
{
|
||||
label: 14,
|
||||
value: 14
|
||||
value: 14,
|
||||
},
|
||||
{
|
||||
label: 15,
|
||||
value: 15
|
||||
value: 15,
|
||||
},
|
||||
{
|
||||
label: 16,
|
||||
value: 16
|
||||
value: 16,
|
||||
},
|
||||
{
|
||||
label: 17,
|
||||
value: 17
|
||||
value: 17,
|
||||
},
|
||||
{
|
||||
label: 18,
|
||||
value: 18
|
||||
value: 18,
|
||||
},
|
||||
{
|
||||
label: 19,
|
||||
value: 19
|
||||
value: 19,
|
||||
},
|
||||
{
|
||||
label: 20,
|
||||
value: 20
|
||||
value: 20,
|
||||
},
|
||||
{
|
||||
label: 21,
|
||||
value: 21
|
||||
value: 21,
|
||||
},
|
||||
{
|
||||
label: 22,
|
||||
value: 22
|
||||
value: 22,
|
||||
},
|
||||
{
|
||||
label: 23,
|
||||
value: 23
|
||||
value: 23,
|
||||
},
|
||||
{
|
||||
label: 24,
|
||||
value: 24
|
||||
value: 24,
|
||||
},
|
||||
{
|
||||
label: 25,
|
||||
value: 25
|
||||
value: 25,
|
||||
},
|
||||
{
|
||||
label: 26,
|
||||
value: 26
|
||||
value: 26,
|
||||
},
|
||||
{
|
||||
label: 27,
|
||||
value: 27
|
||||
value: 27,
|
||||
},
|
||||
{
|
||||
label: 28,
|
||||
value: 28
|
||||
value: 28,
|
||||
},
|
||||
{
|
||||
label: 29,
|
||||
value: 29
|
||||
value: 29,
|
||||
},
|
||||
{
|
||||
label: 30,
|
||||
value: 30
|
||||
value: 30,
|
||||
},
|
||||
{
|
||||
label: 31,
|
||||
value: 31
|
||||
}
|
||||
]
|
||||
value: 31,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Time of day',
|
||||
@@ -157,126 +157,135 @@ export default {
|
||||
options: [
|
||||
{
|
||||
label: '00:00',
|
||||
value: 0
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
label: '01:00',
|
||||
value: 1
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
label: '02:00',
|
||||
value: 2
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
label: '03:00',
|
||||
value: 3
|
||||
value: 3,
|
||||
},
|
||||
{
|
||||
label: '04:00',
|
||||
value: 4
|
||||
value: 4,
|
||||
},
|
||||
{
|
||||
label: '05:00',
|
||||
value: 5
|
||||
value: 5,
|
||||
},
|
||||
{
|
||||
label: '06:00',
|
||||
value: 6
|
||||
value: 6,
|
||||
},
|
||||
{
|
||||
label: '07:00',
|
||||
value: 7
|
||||
value: 7,
|
||||
},
|
||||
{
|
||||
label: '08:00',
|
||||
value: 8
|
||||
value: 8,
|
||||
},
|
||||
{
|
||||
label: '09:00',
|
||||
value: 9
|
||||
value: 9,
|
||||
},
|
||||
{
|
||||
label: '10:00',
|
||||
value: 10
|
||||
value: 10,
|
||||
},
|
||||
{
|
||||
label: '11:00',
|
||||
value: 11
|
||||
value: 11,
|
||||
},
|
||||
{
|
||||
label: '12:00',
|
||||
value: 12
|
||||
value: 12,
|
||||
},
|
||||
{
|
||||
label: '13:00',
|
||||
value: 13
|
||||
value: 13,
|
||||
},
|
||||
{
|
||||
label: '14:00',
|
||||
value: 14
|
||||
value: 14,
|
||||
},
|
||||
{
|
||||
label: '15:00',
|
||||
value: 15
|
||||
value: 15,
|
||||
},
|
||||
{
|
||||
label: '16:00',
|
||||
value: 16
|
||||
value: 16,
|
||||
},
|
||||
{
|
||||
label: '17:00',
|
||||
value: 17
|
||||
value: 17,
|
||||
},
|
||||
{
|
||||
label: '18:00',
|
||||
value: 18
|
||||
value: 18,
|
||||
},
|
||||
{
|
||||
label: '19:00',
|
||||
value: 19
|
||||
value: 19,
|
||||
},
|
||||
{
|
||||
label: '20:00',
|
||||
value: 20
|
||||
value: 20,
|
||||
},
|
||||
{
|
||||
label: '21:00',
|
||||
value: 21
|
||||
value: 21,
|
||||
},
|
||||
{
|
||||
label: '22:00',
|
||||
value: 22
|
||||
value: 22,
|
||||
},
|
||||
{
|
||||
label: '23:00',
|
||||
value: 23
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
value: 23,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'testStep',
|
||||
name: 'Test trigger'
|
||||
}
|
||||
name: 'Test trigger',
|
||||
},
|
||||
],
|
||||
|
||||
getInterval(parameters: IGlobalVariable["db"]["step"]["parameters"]) {
|
||||
const interval = cronTimes.everyMonthOnAndAt(parameters.day as number, parameters.hour as number);
|
||||
getInterval(parameters: IGlobalVariable['step']['parameters']) {
|
||||
const interval = cronTimes.everyMonthOnAndAt(
|
||||
parameters.day as number,
|
||||
parameters.hour as number
|
||||
);
|
||||
|
||||
return interval;
|
||||
},
|
||||
|
||||
async run($: IGlobalVariable, startDateTime: Date) {
|
||||
const dateTime = DateTime.fromJSDate(startDateTime);
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(dateTime) as IJSONValue;
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
|
||||
dateTime
|
||||
) as IJSONValue;
|
||||
|
||||
return { data: [dateTimeObjectRepresentation] };
|
||||
},
|
||||
|
||||
async testRun($: IGlobalVariable) {
|
||||
const nextCronDateTime = getNextCronDateTime(this.getInterval($.db.step.parameters));
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(nextCronDateTime) as IJSONValue;
|
||||
const nextCronDateTime = getNextCronDateTime(
|
||||
this.getInterval($.step.parameters)
|
||||
);
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
|
||||
nextCronDateTime
|
||||
) as IJSONValue;
|
||||
|
||||
return { data: [dateTimeObjectRepresentation] };
|
||||
},
|
||||
|
@@ -23,33 +23,33 @@ export default {
|
||||
options: [
|
||||
{
|
||||
label: 'Monday',
|
||||
value: 1
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
label: 'Tuesday',
|
||||
value: 2
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
label: 'Wednesday',
|
||||
value: 3
|
||||
value: 3,
|
||||
},
|
||||
{
|
||||
label: 'Thursday',
|
||||
value: 4
|
||||
value: 4,
|
||||
},
|
||||
{
|
||||
label: 'Friday',
|
||||
value: 5
|
||||
value: 5,
|
||||
},
|
||||
{
|
||||
label: 'Saturday',
|
||||
value: 6
|
||||
value: 6,
|
||||
},
|
||||
{
|
||||
label: 'Sunday',
|
||||
value: 0
|
||||
}
|
||||
]
|
||||
value: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Time of day',
|
||||
@@ -61,126 +61,135 @@ export default {
|
||||
options: [
|
||||
{
|
||||
label: '00:00',
|
||||
value: 0
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
label: '01:00',
|
||||
value: 1
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
label: '02:00',
|
||||
value: 2
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
label: '03:00',
|
||||
value: 3
|
||||
value: 3,
|
||||
},
|
||||
{
|
||||
label: '04:00',
|
||||
value: 4
|
||||
value: 4,
|
||||
},
|
||||
{
|
||||
label: '05:00',
|
||||
value: 5
|
||||
value: 5,
|
||||
},
|
||||
{
|
||||
label: '06:00',
|
||||
value: 6
|
||||
value: 6,
|
||||
},
|
||||
{
|
||||
label: '07:00',
|
||||
value: 7
|
||||
value: 7,
|
||||
},
|
||||
{
|
||||
label: '08:00',
|
||||
value: 8
|
||||
value: 8,
|
||||
},
|
||||
{
|
||||
label: '09:00',
|
||||
value: 9
|
||||
value: 9,
|
||||
},
|
||||
{
|
||||
label: '10:00',
|
||||
value: 10
|
||||
value: 10,
|
||||
},
|
||||
{
|
||||
label: '11:00',
|
||||
value: 11
|
||||
value: 11,
|
||||
},
|
||||
{
|
||||
label: '12:00',
|
||||
value: 12
|
||||
value: 12,
|
||||
},
|
||||
{
|
||||
label: '13:00',
|
||||
value: 13
|
||||
value: 13,
|
||||
},
|
||||
{
|
||||
label: '14:00',
|
||||
value: 14
|
||||
value: 14,
|
||||
},
|
||||
{
|
||||
label: '15:00',
|
||||
value: 15
|
||||
value: 15,
|
||||
},
|
||||
{
|
||||
label: '16:00',
|
||||
value: 16
|
||||
value: 16,
|
||||
},
|
||||
{
|
||||
label: '17:00',
|
||||
value: 17
|
||||
value: 17,
|
||||
},
|
||||
{
|
||||
label: '18:00',
|
||||
value: 18
|
||||
value: 18,
|
||||
},
|
||||
{
|
||||
label: '19:00',
|
||||
value: 19
|
||||
value: 19,
|
||||
},
|
||||
{
|
||||
label: '20:00',
|
||||
value: 20
|
||||
value: 20,
|
||||
},
|
||||
{
|
||||
label: '21:00',
|
||||
value: 21
|
||||
value: 21,
|
||||
},
|
||||
{
|
||||
label: '22:00',
|
||||
value: 22
|
||||
value: 22,
|
||||
},
|
||||
{
|
||||
label: '23:00',
|
||||
value: 23
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
value: 23,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'testStep',
|
||||
name: 'Test trigger'
|
||||
}
|
||||
name: 'Test trigger',
|
||||
},
|
||||
],
|
||||
|
||||
getInterval(parameters: IGlobalVariable["db"]["step"]["parameters"]) {
|
||||
const interval = cronTimes.everyWeekOnAndAt(parameters.weekday as number, parameters.hour as number);
|
||||
getInterval(parameters: IGlobalVariable['step']['parameters']) {
|
||||
const interval = cronTimes.everyWeekOnAndAt(
|
||||
parameters.weekday as number,
|
||||
parameters.hour as number
|
||||
);
|
||||
|
||||
return interval;
|
||||
},
|
||||
|
||||
async run($: IGlobalVariable, startDateTime: Date) {
|
||||
const dateTime = DateTime.fromJSDate(startDateTime);
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(dateTime) as IJSONValue;
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
|
||||
dateTime
|
||||
) as IJSONValue;
|
||||
|
||||
return { data: [dateTimeObjectRepresentation] };
|
||||
},
|
||||
|
||||
async testRun($: IGlobalVariable) {
|
||||
const nextCronDateTime = getNextCronDateTime(this.getInterval($.db.step.parameters));
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(nextCronDateTime) as IJSONValue;
|
||||
const nextCronDateTime = getNextCronDateTime(
|
||||
this.getInterval($.step.parameters)
|
||||
);
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
|
||||
nextCronDateTime
|
||||
) as IJSONValue;
|
||||
|
||||
return { data: [dateTimeObjectRepresentation] };
|
||||
},
|
||||
|
@@ -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;
|
||||
|
@@ -1,4 +1,8 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
import {
|
||||
IGlobalVariable,
|
||||
IJSONObject,
|
||||
ITriggerOutput,
|
||||
} from '@automatisch/types';
|
||||
import { URLSearchParams } from 'url';
|
||||
import { omitBy, isEmpty } from 'lodash';
|
||||
import generateRequest from './generate-request';
|
||||
@@ -14,12 +18,8 @@ const getUserFollowers = async (
|
||||
) => {
|
||||
let response;
|
||||
|
||||
const followers: {
|
||||
data: IJSONObject[];
|
||||
error: IJSONObject | null;
|
||||
} = {
|
||||
const followers: ITriggerOutput = {
|
||||
data: [],
|
||||
error: null,
|
||||
};
|
||||
|
||||
do {
|
||||
@@ -54,7 +54,10 @@ const getUserFollowers = async (
|
||||
!options.lastInternalId ||
|
||||
Number(tweet.id) > Number(options.lastInternalId)
|
||||
) {
|
||||
followers.data.push(tweet);
|
||||
followers.data.push({
|
||||
raw: tweet,
|
||||
meta: { internalId: tweet.id as string },
|
||||
});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@@ -1,4 +1,8 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
import {
|
||||
IGlobalVariable,
|
||||
IJSONObject,
|
||||
ITriggerOutput,
|
||||
} from '@automatisch/types';
|
||||
import { URLSearchParams } from 'url';
|
||||
import omitBy from 'lodash/omitBy';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
@@ -22,19 +26,15 @@ const getUserTweets = async (
|
||||
const currentUser = await getCurrentUser($);
|
||||
username = currentUser.username as string;
|
||||
} else {
|
||||
username = $.db.step.parameters.username as string;
|
||||
username = $.step.parameters.username as string;
|
||||
}
|
||||
|
||||
const user = await getUserByUsername($, username);
|
||||
|
||||
let response;
|
||||
|
||||
const tweets: {
|
||||
data: IJSONObject[];
|
||||
error: IJSONObject | null;
|
||||
} = {
|
||||
const tweets: ITriggerOutput = {
|
||||
data: [],
|
||||
error: null,
|
||||
};
|
||||
|
||||
do {
|
||||
@@ -65,7 +65,10 @@ const getUserTweets = async (
|
||||
!options.lastInternalId ||
|
||||
Number(tweet.id) > Number(options.lastInternalId)
|
||||
) {
|
||||
tweets.data.push(tweet);
|
||||
tweets.data.push({
|
||||
raw: tweet,
|
||||
meta: { internalId: tweet.id as string },
|
||||
});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ export default {
|
||||
async run($: IGlobalVariable) {
|
||||
return await getUserTweets($, {
|
||||
currentUser: true,
|
||||
lastInternalId: $.db.flow.lastInternalId,
|
||||
lastInternalId: $.flow.lastInternalId,
|
||||
});
|
||||
},
|
||||
|
||||
|
@@ -18,7 +18,7 @@ export default {
|
||||
],
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
return await myFollowers($, $.db.flow.lastInternalId);
|
||||
return await myFollowers($, $.flow.lastInternalId);
|
||||
},
|
||||
|
||||
async testRun($: IGlobalVariable) {
|
||||
|
@@ -32,14 +32,14 @@ export default {
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
return await searchTweets($, {
|
||||
searchTerm: $.db.step.parameters.searchTerm as string,
|
||||
lastInternalId: $.db.flow.lastInternalId,
|
||||
searchTerm: $.step.parameters.searchTerm as string,
|
||||
lastInternalId: $.flow.lastInternalId,
|
||||
});
|
||||
},
|
||||
|
||||
async testRun($: IGlobalVariable) {
|
||||
return await searchTweets($, {
|
||||
searchTerm: $.db.step.parameters.searchTerm as string,
|
||||
searchTerm: $.step.parameters.searchTerm as string,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
@@ -1,4 +1,8 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
import {
|
||||
IGlobalVariable,
|
||||
IJSONObject,
|
||||
ITriggerOutput,
|
||||
} from '@automatisch/types';
|
||||
import qs from 'qs';
|
||||
import generateRequest from '../../common/generate-request';
|
||||
import { omitBy, isEmpty } from 'lodash';
|
||||
@@ -14,12 +18,8 @@ const searchTweets = async (
|
||||
) => {
|
||||
let response;
|
||||
|
||||
const tweets: {
|
||||
data: IJSONObject[];
|
||||
error: IJSONObject | null;
|
||||
} = {
|
||||
const tweets: ITriggerOutput = {
|
||||
data: [],
|
||||
error: null,
|
||||
};
|
||||
|
||||
do {
|
||||
@@ -56,7 +56,14 @@ const searchTweets = async (
|
||||
!options.lastInternalId ||
|
||||
Number(tweet.id) > Number(options.lastInternalId)
|
||||
) {
|
||||
tweets.data.push(tweet);
|
||||
const dataItem = {
|
||||
raw: tweet,
|
||||
meta: {
|
||||
internalId: tweet.id as string,
|
||||
},
|
||||
};
|
||||
|
||||
tweets.data.push(dataItem);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@@ -32,15 +32,15 @@ export default {
|
||||
async run($: IGlobalVariable) {
|
||||
return await getUserTweets($, {
|
||||
currentUser: false,
|
||||
userId: $.db.step.parameters.username as string,
|
||||
lastInternalId: $.db.flow.lastInternalId,
|
||||
userId: $.step.parameters.username as string,
|
||||
lastInternalId: $.flow.lastInternalId,
|
||||
});
|
||||
},
|
||||
|
||||
async testRun($: IGlobalVariable) {
|
||||
return await getUserTweets($, {
|
||||
currentUser: false,
|
||||
userId: $.db.step.parameters.username as string,
|
||||
userId: $.step.parameters.username as string,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
Reference in New Issue
Block a user