Merge pull request #667 from automatisch/refactor/user-args-for-actions

refactor: Specify only the arguments for trigger definitions
This commit is contained in:
Ömer Faruk Aydın
2022-10-31 22:04:31 +01:00
committed by GitHub
21 changed files with 691 additions and 861 deletions

View File

@@ -6,16 +6,6 @@ export default defineTrigger({
pollInterval: 15, pollInterval: 15,
key: 'new-albums', key: 'new-albums',
description: 'Triggers when you create a new album.', description: 'Triggers when you create a new album.',
substeps: [
{
key: 'chooseConnection',
name: 'Choose connection',
},
{
key: 'testStep',
name: 'Test trigger',
},
],
async run($) { async run($) {
await newAlbums($); await newAlbums($);

View File

@@ -6,16 +6,6 @@ export default defineTrigger({
pollInterval: 15, pollInterval: 15,
key: 'newFavoritePhotos', key: 'newFavoritePhotos',
description: 'Triggers when you favorite a photo.', description: 'Triggers when you favorite a photo.',
substeps: [
{
key: 'chooseConnection',
name: 'Choose connection',
},
{
key: 'testStep',
name: 'Test trigger',
},
],
async run($) { async run($) {
await newFavoritePhotos($); await newFavoritePhotos($);

View File

@@ -6,37 +6,23 @@ export default defineTrigger({
pollInterval: 15, pollInterval: 15,
key: 'newPhotosInAlbum', key: 'newPhotosInAlbum',
description: 'Triggers when you add a new photo in an album.', description: 'Triggers when you add a new photo in an album.',
substeps: [ arguments: [
{ {
key: 'chooseConnection', label: 'Album',
name: 'Choose connection', key: 'album',
}, type: 'dropdown' as const,
{ required: true,
key: 'chooseTrigger', variables: false,
name: 'Set up a trigger', source: {
arguments: [ type: 'query',
{ name: 'getData',
label: 'Album', arguments: [
key: 'album', {
type: 'dropdown' as const, name: 'key',
required: true, value: 'listAlbums',
variables: false,
source: {
type: 'query',
name: 'getData',
arguments: [
{
name: 'key',
value: 'listAlbums',
},
],
}, },
}, ],
], },
},
{
key: 'testStep',
name: 'Test trigger',
}, },
], ],

View File

@@ -6,16 +6,6 @@ export default defineTrigger({
pollInterval: 15, pollInterval: 15,
key: 'newPhotos', key: 'newPhotos',
description: 'Triggers when you add a new photo.', description: 'Triggers when you add a new photo.',
substeps: [
{
key: 'chooseConnection',
name: 'Choose connection',
},
{
key: 'testStep',
name: 'Test trigger',
},
],
async run($) { async run($) {
await newPhotos($); await newPhotos($);

View File

@@ -6,91 +6,77 @@ export default defineTrigger({
key: 'newIssues', key: 'newIssues',
pollInterval: 15, pollInterval: 15,
description: 'Triggers when a new issue is created', description: 'Triggers when a new issue is created',
substeps: [ arguments: [
{ {
key: 'chooseConnection', label: 'Repo',
name: 'Choose connection', key: 'repo',
type: 'dropdown' as const,
required: false,
variables: false,
source: {
type: 'query',
name: 'getData',
arguments: [
{
name: 'key',
value: 'listRepos',
},
],
},
}, },
{ {
key: 'chooseTrigger', label: 'Which types of issues should this trigger on?',
name: 'Set up a trigger', key: 'issueType',
arguments: [ type: 'dropdown' as const,
description: 'Defaults to any issue you can see.',
required: true,
variables: false,
value: 'all',
options: [
{ {
label: 'Repo', label: 'Any issue you can see',
key: 'repo',
type: 'dropdown' as const,
required: false,
variables: false,
source: {
type: 'query',
name: 'getData',
arguments: [
{
name: 'key',
value: 'listRepos',
},
],
},
},
{
label: 'Which types of issues should this trigger on?',
key: 'issueType',
type: 'dropdown' as const,
description: 'Defaults to any issue you can see.',
required: true,
variables: false,
value: 'all', value: 'all',
options: [
{
label: 'Any issue you can see',
value: 'all',
},
{
label: 'Only issues assigned to you',
value: 'assigned',
},
{
label: 'Only issues created by you',
value: 'created',
},
{
label: `Only issues you're mentioned in`,
value: 'mentioned',
},
{
label: `Only issues you're subscribed to`,
value: 'subscribed',
},
],
}, },
{ {
label: 'Label', label: 'Only issues assigned to you',
key: 'label', value: 'assigned',
type: 'dropdown' as const, },
description: 'Only trigger on issues when this label is added.', {
required: false, label: 'Only issues created by you',
variables: false, value: 'created',
dependsOn: ['parameters.repo'], },
source: { {
type: 'query', label: `Only issues you're mentioned in`,
name: 'getData', value: 'mentioned',
arguments: [ },
{ {
name: 'key', label: `Only issues you're subscribed to`,
value: 'listLabels', value: 'subscribed',
},
{
name: 'parameters.repo',
value: '{parameters.repo}',
},
],
},
}, },
], ],
}, },
{ {
key: 'testStep', label: 'Label',
name: 'Test trigger', key: 'label',
type: 'dropdown' as const,
description: 'Only trigger on issues when this label is added.',
required: false,
variables: false,
dependsOn: ['parameters.repo'],
source: {
type: 'query',
name: 'getData',
arguments: [
{
name: 'key',
value: 'listLabels',
},
{
name: 'parameters.repo',
value: '{parameters.repo}',
},
],
},
}, },
], ],

View File

@@ -6,37 +6,23 @@ export default defineTrigger({
key: 'newPullRequests', key: 'newPullRequests',
pollInterval: 15, pollInterval: 15,
description: 'Triggers when a new pull request is created', description: 'Triggers when a new pull request is created',
substeps: [ arguments: [
{ {
key: 'chooseConnection', label: 'Repo',
name: 'Choose connection', key: 'repo',
}, type: 'dropdown' as const,
{ required: true,
key: 'chooseTrigger', variables: false,
name: 'Set up a trigger', source: {
arguments: [ type: 'query',
{ name: 'getData',
label: 'Repo', arguments: [
key: 'repo', {
type: 'dropdown' as const, name: 'key',
required: true, value: 'listRepos',
variables: false,
source: {
type: 'query',
name: 'getData',
arguments: [
{
name: 'key',
value: 'listRepos',
},
],
}, },
}, ],
], },
},
{
key: 'testStep',
name: 'Test trigger',
}, },
], ],

View File

@@ -6,37 +6,23 @@ export default defineTrigger({
key: 'newStargazers', key: 'newStargazers',
pollInterval: 15, pollInterval: 15,
description: 'Triggers when a user stars a repository', description: 'Triggers when a user stars a repository',
substeps: [ arguments: [
{ {
key: 'chooseConnection', label: 'Repo',
name: 'Choose connection', key: 'repo',
}, type: 'dropdown' as const,
{ required: true,
key: 'chooseTrigger', variables: false,
name: 'Set up a trigger', source: {
arguments: [ type: 'query',
{ name: 'getData',
label: 'Repo', arguments: [
key: 'repo', {
type: 'dropdown' as const, name: 'key',
required: true, value: 'listRepos',
variables: false,
source: {
type: 'query',
name: 'getData',
arguments: [
{
name: 'key',
value: 'listRepos',
},
],
}, },
}, ],
], },
},
{
key: 'testStep',
name: 'Test trigger',
}, },
], ],

View File

@@ -6,37 +6,23 @@ export default defineTrigger({
key: 'newWatchers', key: 'newWatchers',
pollInterval: 15, pollInterval: 15,
description: 'Triggers when a user watches a repository', description: 'Triggers when a user watches a repository',
substeps: [ arguments: [
{ {
key: 'chooseConnection', label: 'Repo',
name: 'Choose connection', key: 'repo',
}, type: 'dropdown' as const,
{ required: true,
key: 'chooseTrigger', variables: false,
name: 'Set up a trigger', source: {
arguments: [ type: 'query',
{ name: 'getData',
label: 'Repo', arguments: [
key: 'repo', {
type: 'dropdown' as const, name: 'key',
required: true, value: 'listRepos',
variables: false,
source: {
type: 'query',
name: 'getData',
arguments: [
{
name: 'key',
value: 'listRepos',
},
],
}, },
}, ],
], },
},
{
key: 'testStep',
name: 'Test trigger',
}, },
], ],

View File

@@ -6,24 +6,14 @@ export default defineTrigger({
key: 'newItemsInFeed', key: 'newItemsInFeed',
description: 'Triggers on new RSS feed items.', description: 'Triggers on new RSS feed items.',
pollInterval: 15, pollInterval: 15,
substeps: [ arguments: [
{ {
key: 'chooseTrigger', label: 'Feed URL',
name: 'Set up trigger', key: 'feedUrl',
arguments: [ type: 'string' as const,
{ required: true,
label: 'Feed URL', description: 'Paste your publicly accessible RSS URL here.',
key: 'feedUrl', variables: false,
type: 'string' as const,
required: true,
description: 'Paste your publicly accessible RSS URL here.',
variables: false,
},
],
},
{
key: 'testStep',
name: 'Test trigger',
}, },
], ],

View File

@@ -9,141 +9,131 @@ export default defineTrigger({
name: 'Every day', name: 'Every day',
key: 'everyDay', key: 'everyDay',
description: 'Triggers every day.', description: 'Triggers every day.',
substeps: [ arguments: [
{ {
key: 'chooseTrigger', label: 'Trigger on weekends?',
name: 'Set up a trigger', key: 'triggersOnWeekend',
arguments: [ type: 'dropdown' as const,
description: 'Should this flow trigger on Saturday and Sunday?',
required: true,
value: true,
variables: false,
options: [
{ {
label: 'Trigger on weekends?', label: 'Yes',
key: 'triggersOnWeekend',
type: 'dropdown' as const,
description: 'Should this flow trigger on Saturday and Sunday?',
required: true,
value: true, value: true,
variables: false,
options: [
{
label: 'Yes',
value: true,
},
{
label: 'No',
value: false,
},
],
}, },
{ {
label: 'Time of day', label: 'No',
key: 'hour', value: false,
type: 'dropdown' as const,
required: true,
value: null,
variables: false,
options: [
{
label: '00:00',
value: 0,
},
{
label: '01:00',
value: 1,
},
{
label: '02:00',
value: 2,
},
{
label: '03:00',
value: 3,
},
{
label: '04:00',
value: 4,
},
{
label: '05:00',
value: 5,
},
{
label: '06:00',
value: 6,
},
{
label: '07:00',
value: 7,
},
{
label: '08:00',
value: 8,
},
{
label: '09:00',
value: 9,
},
{
label: '10:00',
value: 10,
},
{
label: '11:00',
value: 11,
},
{
label: '12:00',
value: 12,
},
{
label: '13:00',
value: 13,
},
{
label: '14:00',
value: 14,
},
{
label: '15:00',
value: 15,
},
{
label: '16:00',
value: 16,
},
{
label: '17:00',
value: 17,
},
{
label: '18:00',
value: 18,
},
{
label: '19:00',
value: 19,
},
{
label: '20:00',
value: 20,
},
{
label: '21:00',
value: 21,
},
{
label: '22:00',
value: 22,
},
{
label: '23:00',
value: 23,
},
],
}, },
], ],
}, },
{ {
key: 'testStep', label: 'Time of day',
name: 'Test trigger', key: 'hour',
type: 'dropdown' as const,
required: true,
value: null,
variables: false,
options: [
{
label: '00:00',
value: 0,
},
{
label: '01:00',
value: 1,
},
{
label: '02:00',
value: 2,
},
{
label: '03:00',
value: 3,
},
{
label: '04:00',
value: 4,
},
{
label: '05:00',
value: 5,
},
{
label: '06:00',
value: 6,
},
{
label: '07:00',
value: 7,
},
{
label: '08:00',
value: 8,
},
{
label: '09:00',
value: 9,
},
{
label: '10:00',
value: 10,
},
{
label: '11:00',
value: 11,
},
{
label: '12:00',
value: 12,
},
{
label: '13:00',
value: 13,
},
{
label: '14:00',
value: 14,
},
{
label: '15:00',
value: 15,
},
{
label: '16:00',
value: 16,
},
{
label: '17:00',
value: 17,
},
{
label: '18:00',
value: 18,
},
{
label: '19:00',
value: 19,
},
{
label: '20:00',
value: 20,
},
{
label: '21:00',
value: 21,
},
{
label: '22:00',
value: 22,
},
{
label: '23:00',
value: 23,
},
],
}, },
], ],

View File

@@ -9,36 +9,26 @@ export default defineTrigger({
name: 'Every hour', name: 'Every hour',
key: 'everyHour', key: 'everyHour',
description: 'Triggers every hour.', description: 'Triggers every hour.',
substeps: [ arguments: [
{ {
key: 'chooseTrigger', label: 'Trigger on weekends?',
name: 'Set up a trigger', key: 'triggersOnWeekend',
arguments: [ type: 'dropdown' as const,
description: 'Should this flow trigger on Saturday and Sunday?',
required: true,
value: true,
variables: false,
options: [
{ {
label: 'Trigger on weekends?', label: 'Yes',
key: 'triggersOnWeekend',
type: 'dropdown' as const,
description: 'Should this flow trigger on Saturday and Sunday?',
required: true,
value: true, value: true,
variables: false, },
options: [ {
{ label: 'No',
label: 'Yes', value: false,
value: true,
},
{
label: 'No',
value: false,
},
],
}, },
], ],
}, },
{
key: 'testStep',
name: 'Test trigger',
},
], ],
getInterval(parameters: IGlobalVariable['step']['parameters']) { getInterval(parameters: IGlobalVariable['step']['parameters']) {

View File

@@ -9,256 +9,246 @@ export default defineTrigger({
name: 'Every month', name: 'Every month',
key: 'everyMonth', key: 'everyMonth',
description: 'Triggers every month.', description: 'Triggers every month.',
substeps: [ arguments: [
{ {
key: 'chooseTrigger', label: 'Day of the month',
name: 'Set up a trigger', key: 'day',
arguments: [ type: 'dropdown' as const,
required: true,
value: null,
variables: false,
options: [
{ {
label: 'Day of the month', label: '1',
key: 'day', value: 1,
type: 'dropdown' as const,
required: true,
value: null,
variables: false,
options: [
{
label: '1',
value: 1,
},
{
label: '2',
value: 2,
},
{
label: '3',
value: 3,
},
{
label: '4',
value: 4,
},
{
label: '5',
value: 5,
},
{
label: '6',
value: 6,
},
{
label: '7',
value: 7,
},
{
label: '8',
value: 8,
},
{
label: '9',
value: 9,
},
{
label: '10',
value: 10,
},
{
label: '11',
value: 11,
},
{
label: '12',
value: 12,
},
{
label: '13',
value: 13,
},
{
label: '14',
value: 14,
},
{
label: '15',
value: 15,
},
{
label: '16',
value: 16,
},
{
label: '17',
value: 17,
},
{
label: '18',
value: 18,
},
{
label: '19',
value: 19,
},
{
label: '20',
value: 20,
},
{
label: '21',
value: 21,
},
{
label: '22',
value: 22,
},
{
label: '23',
value: 23,
},
{
label: '24',
value: 24,
},
{
label: '25',
value: 25,
},
{
label: '26',
value: 26,
},
{
label: '27',
value: 27,
},
{
label: '28',
value: 28,
},
{
label: '29',
value: 29,
},
{
label: '30',
value: 30,
},
{
label: '31',
value: 31,
},
],
}, },
{ {
label: 'Time of day', label: '2',
key: 'hour', value: 2,
type: 'dropdown' as const, },
required: true, {
value: null, label: '3',
variables: false, value: 3,
options: [ },
{ {
label: '00:00', label: '4',
value: 0, value: 4,
}, },
{ {
label: '01:00', label: '5',
value: 1, value: 5,
}, },
{ {
label: '02:00', label: '6',
value: 2, value: 6,
}, },
{ {
label: '03:00', label: '7',
value: 3, value: 7,
}, },
{ {
label: '04:00', label: '8',
value: 4, value: 8,
}, },
{ {
label: '05:00', label: '9',
value: 5, value: 9,
}, },
{ {
label: '06:00', label: '10',
value: 6, value: 10,
}, },
{ {
label: '07:00', label: '11',
value: 7, value: 11,
}, },
{ {
label: '08:00', label: '12',
value: 8, value: 12,
}, },
{ {
label: '09:00', label: '13',
value: 9, value: 13,
}, },
{ {
label: '10:00', label: '14',
value: 10, value: 14,
}, },
{ {
label: '11:00', label: '15',
value: 11, value: 15,
}, },
{ {
label: '12:00', label: '16',
value: 12, value: 16,
}, },
{ {
label: '13:00', label: '17',
value: 13, value: 17,
}, },
{ {
label: '14:00', label: '18',
value: 14, value: 18,
}, },
{ {
label: '15:00', label: '19',
value: 15, value: 19,
}, },
{ {
label: '16:00', label: '20',
value: 16, value: 20,
}, },
{ {
label: '17:00', label: '21',
value: 17, value: 21,
}, },
{ {
label: '18:00', label: '22',
value: 18, value: 22,
}, },
{ {
label: '19:00', label: '23',
value: 19, value: 23,
}, },
{ {
label: '20:00', label: '24',
value: 20, value: 24,
}, },
{ {
label: '21:00', label: '25',
value: 21, value: 25,
}, },
{ {
label: '22:00', label: '26',
value: 22, value: 26,
}, },
{ {
label: '23:00', label: '27',
value: 23, value: 27,
}, },
], {
label: '28',
value: 28,
},
{
label: '29',
value: 29,
},
{
label: '30',
value: 30,
},
{
label: '31',
value: 31,
}, },
], ],
}, },
{ {
key: 'testStep', label: 'Time of day',
name: 'Test trigger', key: 'hour',
type: 'dropdown' as const,
required: true,
value: null,
variables: false,
options: [
{
label: '00:00',
value: 0,
},
{
label: '01:00',
value: 1,
},
{
label: '02:00',
value: 2,
},
{
label: '03:00',
value: 3,
},
{
label: '04:00',
value: 4,
},
{
label: '05:00',
value: 5,
},
{
label: '06:00',
value: 6,
},
{
label: '07:00',
value: 7,
},
{
label: '08:00',
value: 8,
},
{
label: '09:00',
value: 9,
},
{
label: '10:00',
value: 10,
},
{
label: '11:00',
value: 11,
},
{
label: '12:00',
value: 12,
},
{
label: '13:00',
value: 13,
},
{
label: '14:00',
value: 14,
},
{
label: '15:00',
value: 15,
},
{
label: '16:00',
value: 16,
},
{
label: '17:00',
value: 17,
},
{
label: '18:00',
value: 18,
},
{
label: '19:00',
value: 19,
},
{
label: '20:00',
value: 20,
},
{
label: '21:00',
value: 21,
},
{
label: '22:00',
value: 22,
},
{
label: '23:00',
value: 23,
},
],
}, },
], ],

View File

@@ -1,5 +1,5 @@
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
import { IGlobalVariable, IJSONValue } from '@automatisch/types'; import { IGlobalVariable } from '@automatisch/types';
import defineTrigger from '../../../../helpers/define-trigger'; import defineTrigger from '../../../../helpers/define-trigger';
import cronTimes from '../../common/cron-times'; import cronTimes from '../../common/cron-times';
import getNextCronDateTime from '../../common/get-next-cron-date-time'; import getNextCronDateTime from '../../common/get-next-cron-date-time';
@@ -9,160 +9,150 @@ export default defineTrigger({
name: 'Every week', name: 'Every week',
key: 'everyWeek', key: 'everyWeek',
description: 'Triggers every week.', description: 'Triggers every week.',
substeps: [ arguments: [
{ {
key: 'chooseTrigger', label: 'Day of the week',
name: 'Set up a trigger', key: 'weekday',
arguments: [ type: 'dropdown' as const,
required: true,
value: null,
variables: false,
options: [
{ {
label: 'Day of the week', label: 'Monday',
key: 'weekday', value: 1,
type: 'dropdown' as const,
required: true,
value: null,
variables: false,
options: [
{
label: 'Monday',
value: 1,
},
{
label: 'Tuesday',
value: 2,
},
{
label: 'Wednesday',
value: 3,
},
{
label: 'Thursday',
value: 4,
},
{
label: 'Friday',
value: 5,
},
{
label: 'Saturday',
value: 6,
},
{
label: 'Sunday',
value: 0,
},
],
}, },
{ {
label: 'Time of day', label: 'Tuesday',
key: 'hour', value: 2,
type: 'dropdown' as const, },
required: true, {
value: null, label: 'Wednesday',
variables: false, value: 3,
options: [ },
{ {
label: '00:00', label: 'Thursday',
value: 0, value: 4,
}, },
{ {
label: '01:00', label: 'Friday',
value: 1, value: 5,
}, },
{ {
label: '02:00', label: 'Saturday',
value: 2, value: 6,
}, },
{ {
label: '03:00', label: 'Sunday',
value: 3, value: 0,
},
{
label: '04:00',
value: 4,
},
{
label: '05:00',
value: 5,
},
{
label: '06:00',
value: 6,
},
{
label: '07:00',
value: 7,
},
{
label: '08:00',
value: 8,
},
{
label: '09:00',
value: 9,
},
{
label: '10:00',
value: 10,
},
{
label: '11:00',
value: 11,
},
{
label: '12:00',
value: 12,
},
{
label: '13:00',
value: 13,
},
{
label: '14:00',
value: 14,
},
{
label: '15:00',
value: 15,
},
{
label: '16:00',
value: 16,
},
{
label: '17:00',
value: 17,
},
{
label: '18:00',
value: 18,
},
{
label: '19:00',
value: 19,
},
{
label: '20:00',
value: 20,
},
{
label: '21:00',
value: 21,
},
{
label: '22:00',
value: 22,
},
{
label: '23:00',
value: 23,
},
],
}, },
], ],
}, },
{ {
key: 'testStep', label: 'Time of day',
name: 'Test trigger', key: 'hour',
type: 'dropdown' as const,
required: true,
value: null,
variables: false,
options: [
{
label: '00:00',
value: 0,
},
{
label: '01:00',
value: 1,
},
{
label: '02:00',
value: 2,
},
{
label: '03:00',
value: 3,
},
{
label: '04:00',
value: 4,
},
{
label: '05:00',
value: 5,
},
{
label: '06:00',
value: 6,
},
{
label: '07:00',
value: 7,
},
{
label: '08:00',
value: 8,
},
{
label: '09:00',
value: 9,
},
{
label: '10:00',
value: 10,
},
{
label: '11:00',
value: 11,
},
{
label: '12:00',
value: 12,
},
{
label: '13:00',
value: 13,
},
{
label: '14:00',
value: 14,
},
{
label: '15:00',
value: 15,
},
{
label: '16:00',
value: 16,
},
{
label: '17:00',
value: 17,
},
{
label: '18:00',
value: 18,
},
{
label: '19:00',
value: 19,
},
{
label: '20:00',
value: 20,
},
{
label: '21:00',
value: 21,
},
{
label: '22:00',
value: 22,
},
{
label: '23:00',
value: 23,
},
],
}, },
], ],

View File

@@ -6,28 +6,14 @@ export default defineTrigger({
key: 'receiveSms', key: 'receiveSms',
pollInterval: 15, pollInterval: 15,
description: 'Will be triggered when a new SMS is received.', description: 'Will be triggered when a new SMS is received.',
substeps: [ arguments: [
{ {
key: 'chooseConnection', label: 'To Number',
name: 'Choose connection', key: 'toNumber',
}, type: 'string',
{ required: true,
key: 'chooseTrigger', description:
name: 'Set up a trigger', 'The number to receive the SMS on. It should be a Twilio number.',
arguments: [
{
label: 'To Number',
key: 'toNumber',
type: 'string',
required: true,
description:
'The number to receive the SMS on. It should be a Twilio number.',
},
],
},
{
key: 'testStep',
name: 'Test trigger',
}, },
], ],

View File

@@ -6,16 +6,6 @@ export default defineTrigger({
key: 'myTweets', key: 'myTweets',
pollInterval: 15, pollInterval: 15,
description: 'Will be triggered when you tweet something new.', description: 'Will be triggered when you tweet something new.',
substeps: [
{
key: 'chooseConnection',
name: 'Choose connection',
},
{
key: 'testStep',
name: 'Test trigger',
},
],
async run($) { async run($) {
await getUserTweets($, { currentUser: true }); await getUserTweets($, { currentUser: true });

View File

@@ -6,16 +6,6 @@ export default defineTrigger({
key: 'myFollowers', key: 'myFollowers',
pollInterval: 15, pollInterval: 15,
description: 'Will be triggered when you have a new follower.', description: 'Will be triggered when you have a new follower.',
substeps: [
{
key: 'chooseConnection',
name: 'Choose connection',
},
{
key: 'testStep',
name: 'Test trigger',
},
],
async run($) { async run($) {
await myFollowers($); await myFollowers($);

View File

@@ -7,26 +7,12 @@ export default defineTrigger({
pollInterval: 15, pollInterval: 15,
description: description:
'Will be triggered when any user tweet something containing a specific keyword, phrase, username or hashtag.', 'Will be triggered when any user tweet something containing a specific keyword, phrase, username or hashtag.',
substeps: [ arguments: [
{ {
key: 'chooseConnection', label: 'Search Term',
name: 'Choose connection', key: 'searchTerm',
}, type: 'string' as const,
{ required: true,
key: 'chooseTrigger',
name: 'Set up a trigger',
arguments: [
{
label: 'Search Term',
key: 'searchTerm',
type: 'string' as const,
required: true,
},
],
},
{
key: 'testStep',
name: 'Test trigger',
}, },
], ],

View File

@@ -6,26 +6,12 @@ export default defineTrigger({
key: 'userTweets', key: 'userTweets',
pollInterval: 15, pollInterval: 15,
description: 'Will be triggered when a specific user tweet something new.', description: 'Will be triggered when a specific user tweet something new.',
substeps: [ arguments: [
{ {
key: 'chooseConnection', label: 'Username',
name: 'Choose connection', key: 'username',
}, type: 'string' as const,
{ required: true,
key: 'chooseTrigger',
name: 'Set up a trigger',
arguments: [
{
label: 'Username',
key: 'username',
type: 'string' as const,
required: true,
},
],
},
{
key: 'testStep',
name: 'Test trigger',
}, },
], ],

View File

@@ -1,5 +1,7 @@
import { ITrigger } from '@automatisch/types'; import { IRawTrigger } from '@automatisch/types';
export default function defineTrigger(triggerDefinition: ITrigger): ITrigger { export default function defineTrigger(
triggerDefinition: IRawTrigger
): IRawTrigger {
return triggerDefinition; return triggerDefinition;
} }

View File

@@ -1,4 +1,5 @@
import { IApp } from '@automatisch/types'; import { IApp, IRawTrigger, ITrigger } from '@automatisch/types';
import { omit, cloneDeep } from 'lodash';
async function getDefaultExport(path: string) { async function getDefaultExport(path: string) {
return (await import(path)).default; return (await import(path)).default;
@@ -8,8 +9,40 @@ function stripFunctions<C>(data: C): C {
return JSON.parse(JSON.stringify(data)); return JSON.parse(JSON.stringify(data));
} }
const chooseConnectionStep = {
key: 'chooseConnection',
name: 'Choose connection',
};
const testStep = {
key: 'testStep',
name: 'Test trigger',
};
const getApp = async (appKey: string, stripFuncs = true) => { const getApp = async (appKey: string, stripFuncs = true) => {
const appData: IApp = await getDefaultExport(`../apps/${appKey}`); const appData: IApp = cloneDeep(await getDefaultExport(`../apps/${appKey}`));
appData.triggers = appData?.triggers?.map((trigger: IRawTrigger) => {
const computedTrigger: ITrigger = omit(trigger, ['arguments']);
computedTrigger.substeps = [];
if (appData.supportsConnections) {
computedTrigger.substeps.push(chooseConnectionStep);
}
if (trigger.arguments) {
computedTrigger.substeps.push({
key: 'chooseTrigger',
name: 'Set up a trigger',
arguments: trigger.arguments,
});
}
computedTrigger.substeps.push(testStep);
return computedTrigger;
});
if (stripFuncs) { if (stripFuncs) {
return stripFunctions(appData); return stripFunctions(appData);

View File

@@ -205,17 +205,24 @@ export interface ITriggerItem {
}; };
} }
export interface ITrigger { export interface IBaseTrigger {
name: string; name: string;
key: string; key: string;
pollInterval?: number; pollInterval?: number;
description: string; description: string;
substeps: ISubstep[];
getInterval?(parameters: IStep['parameters']): string; getInterval?(parameters: IStep['parameters']): string;
run($: IGlobalVariable): Promise<void>; run($: IGlobalVariable): Promise<void>;
sort?(item: ITriggerItem, nextItem: ITriggerItem): number; sort?(item: ITriggerItem, nextItem: ITriggerItem): number;
} }
export interface IRawTrigger extends IBaseTrigger {
arguments?: IField[];
}
export interface ITrigger extends IBaseTrigger {
substeps?: ISubstep[];
}
export interface IActionOutput { export interface IActionOutput {
data: IActionItem; data: IActionItem;
error?: IJSONObject; error?: IJSONObject;