feat: introduce CustomAutocomplete with variables
This commit is contained in:
@@ -20,7 +20,7 @@ export default defineAction({
|
||||
type: 'dropdown' as const,
|
||||
required: true,
|
||||
description: 'Language to translate the text to.',
|
||||
variables: false,
|
||||
variables: true,
|
||||
value: '',
|
||||
options: [
|
||||
{ label: 'Bulgarian', value: 'BG' },
|
||||
|
@@ -13,7 +13,7 @@ export default defineAction({
|
||||
required: true,
|
||||
value: null,
|
||||
description: 'Delay for unit, e.g. minutes, hours, days, weeks.',
|
||||
variables: false,
|
||||
variables: true,
|
||||
options: [
|
||||
{
|
||||
label: 'Minutes',
|
||||
|
@@ -11,7 +11,7 @@ export default defineAction({
|
||||
type: 'dropdown' as const,
|
||||
required: true,
|
||||
description: 'Pick a channel to send the message to.',
|
||||
variables: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
|
@@ -11,7 +11,7 @@ export default defineAction({
|
||||
key: 'repo',
|
||||
type: 'dropdown' as const,
|
||||
required: false,
|
||||
variables: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
|
@@ -21,7 +21,7 @@ export default defineAction({
|
||||
required: false,
|
||||
description:
|
||||
'The Google Drive where your spreadsheet resides. If nothing is selected, then your personal Google Drive will be used.',
|
||||
variables: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
@@ -40,7 +40,7 @@ export default defineAction({
|
||||
required: true,
|
||||
dependsOn: ['parameters.driveId'],
|
||||
description: 'The spreadsheets in your Google Drive.',
|
||||
variables: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
@@ -63,7 +63,7 @@ export default defineAction({
|
||||
required: true,
|
||||
dependsOn: ['parameters.spreadsheetId'],
|
||||
description: 'The worksheets in your selected spreadsheet.',
|
||||
variables: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
|
@@ -84,7 +84,7 @@ export default defineAction({
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
description: 'Header key',
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
@@ -132,7 +132,7 @@ export default defineAction({
|
||||
|
||||
throwIfFileSizeExceedsLimit(metadataResponse.headers['content-length']);
|
||||
// eslint-disable-next-line no-empty
|
||||
} catch {}
|
||||
} catch { }
|
||||
|
||||
const requestData: AxiosRequestConfig = {
|
||||
url,
|
||||
|
@@ -19,7 +19,7 @@ export default defineAction({
|
||||
key: 'model',
|
||||
type: 'dropdown' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
@@ -35,7 +35,7 @@ export default defineAction({
|
||||
label: 'Messages',
|
||||
key: 'messages',
|
||||
type: 'dynamic' as const,
|
||||
required: false,
|
||||
required: true,
|
||||
description: 'Add or remove messages as needed',
|
||||
value: [{ role: 'system', body: '' }],
|
||||
fields: [
|
||||
|
@@ -14,7 +14,7 @@ export default defineAction({
|
||||
key: 'model',
|
||||
type: 'dropdown' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
|
@@ -18,14 +18,14 @@ export default defineAction({
|
||||
type: 'string' as const,
|
||||
value: 'public',
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Table name',
|
||||
key: 'table',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Where clause entries',
|
||||
@@ -38,14 +38,14 @@ export default defineAction({
|
||||
key: 'columnName',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Operator',
|
||||
key: 'operator',
|
||||
type: 'dropdown' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
options: whereClauseOperators
|
||||
},
|
||||
{
|
||||
@@ -69,7 +69,7 @@ export default defineAction({
|
||||
key: 'parameter',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
|
@@ -16,14 +16,14 @@ export default defineAction({
|
||||
type: 'string' as const,
|
||||
value: 'public',
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Table name',
|
||||
key: 'table',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Column - value entries',
|
||||
@@ -37,7 +37,7 @@ export default defineAction({
|
||||
key: 'columnName',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
@@ -52,7 +52,7 @@ export default defineAction({
|
||||
label: 'Run-time parameters',
|
||||
key: 'params',
|
||||
type: 'dynamic' as const,
|
||||
required: false,
|
||||
required: true,
|
||||
description: 'Change run-time configuration parameters with SET command',
|
||||
fields: [
|
||||
{
|
||||
@@ -60,7 +60,7 @@ export default defineAction({
|
||||
key: 'parameter',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
|
@@ -27,7 +27,7 @@ export default defineAction({
|
||||
key: 'parameter',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
|
@@ -19,14 +19,14 @@ export default defineAction({
|
||||
type: 'string' as const,
|
||||
value: 'public',
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Table name',
|
||||
key: 'table',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Where clause entries',
|
||||
@@ -39,14 +39,14 @@ export default defineAction({
|
||||
key: 'columnName',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Operator',
|
||||
key: 'operator',
|
||||
type: 'dropdown' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
options: whereClauseOperators
|
||||
},
|
||||
{
|
||||
@@ -70,7 +70,7 @@ export default defineAction({
|
||||
key: 'columnName',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
@@ -93,7 +93,7 @@ export default defineAction({
|
||||
key: 'parameter',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
|
@@ -10,6 +10,7 @@ export default defineAction({
|
||||
key: 'object',
|
||||
type: 'dropdown' as const,
|
||||
required: true,
|
||||
variables: true,
|
||||
description: 'Pick which type of object you want to search for.',
|
||||
source: {
|
||||
type: 'query',
|
||||
@@ -28,7 +29,7 @@ export default defineAction({
|
||||
type: 'dropdown' as const,
|
||||
description: 'Pick which field to search by',
|
||||
required: true,
|
||||
variables: false,
|
||||
variables: true,
|
||||
dependsOn: ['parameters.object'],
|
||||
source: {
|
||||
type: 'query',
|
||||
|
@@ -23,7 +23,7 @@ export default defineAction({
|
||||
'Sort messages by their match strength or by their date. Default is score.',
|
||||
required: true,
|
||||
value: 'score',
|
||||
variables: false,
|
||||
variables: true,
|
||||
options: [
|
||||
{
|
||||
label: 'Match strength',
|
||||
@@ -43,7 +43,7 @@ export default defineAction({
|
||||
'Sort matching messages in ascending or descending order. Default is descending.',
|
||||
required: true,
|
||||
value: 'desc',
|
||||
variables: false,
|
||||
variables: true,
|
||||
options: [
|
||||
{
|
||||
label: 'Descending (newest or best match first)',
|
||||
|
@@ -12,7 +12,7 @@ export default defineAction({
|
||||
type: 'dropdown' as const,
|
||||
required: true,
|
||||
description: 'Pick a user to send the message to.',
|
||||
variables: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
@@ -40,7 +40,7 @@ export default defineAction({
|
||||
value: false,
|
||||
description:
|
||||
'If you choose no, this message will appear to come from you. Direct messages are always sent by bots.',
|
||||
variables: false,
|
||||
variables: true,
|
||||
options: [
|
||||
{
|
||||
label: 'Yes',
|
||||
|
@@ -12,7 +12,7 @@ export default defineAction({
|
||||
type: 'dropdown' as const,
|
||||
required: true,
|
||||
description: 'Pick a channel to send the message to.',
|
||||
variables: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
@@ -40,7 +40,7 @@ export default defineAction({
|
||||
value: false,
|
||||
description:
|
||||
'If you choose no, this message will appear to come from you. Direct messages are always sent by bots.',
|
||||
variables: false,
|
||||
variables: true,
|
||||
options: [
|
||||
{
|
||||
label: 'Yes',
|
||||
|
@@ -29,7 +29,7 @@ export default defineAction({
|
||||
required: false,
|
||||
value: false,
|
||||
description: 'Sends the message silently. Users will receive a notification with no sound.',
|
||||
variables: false,
|
||||
variables: true,
|
||||
options: [
|
||||
{
|
||||
label: 'Yes',
|
||||
|
@@ -10,7 +10,7 @@ export default defineAction({
|
||||
key: 'projectId',
|
||||
type: 'dropdown' as const,
|
||||
required: false,
|
||||
variables: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
@@ -27,7 +27,7 @@ export default defineAction({
|
||||
key: 'sectionId',
|
||||
type: 'dropdown' as const,
|
||||
required: false,
|
||||
variables: false,
|
||||
variables: true,
|
||||
dependsOn: ['parameters.projectId'],
|
||||
source: {
|
||||
type: 'query',
|
||||
|
@@ -13,7 +13,7 @@ export default defineAction({
|
||||
required: true,
|
||||
description:
|
||||
'The number to send the SMS from. Include country code. Example: 15551234567',
|
||||
variables: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
|
@@ -1,7 +1,9 @@
|
||||
import { IDynamicData, IJSONObject } from '@automatisch/types';
|
||||
import Context from '../../types/express/context';
|
||||
import App from '../../models/app';
|
||||
import ExecutionStep from '../../models/execution-step';
|
||||
import globalVariable from '../../helpers/global-variable';
|
||||
import computeParameters from '../../helpers/compute-parameters';
|
||||
|
||||
type Params = {
|
||||
stepId: string;
|
||||
@@ -28,18 +30,29 @@ const getDynamicData = async (
|
||||
|
||||
if (!connection || !step.appKey) return null;
|
||||
|
||||
const flow = step.flow;
|
||||
const app = await App.findOneByKey(step.appKey);
|
||||
const $ = await globalVariable({ connection, app, flow: step.flow, step });
|
||||
const $ = await globalVariable({ connection, app, flow, step });
|
||||
|
||||
const command = app.dynamicData.find(
|
||||
(data: IDynamicData) => data.key === params.key
|
||||
);
|
||||
|
||||
// apply run-time parameters that're not persisted yet
|
||||
for (const parameterKey in params.parameters) {
|
||||
const parameterValue = params.parameters[parameterKey];
|
||||
$.step.parameters[parameterKey] = parameterValue;
|
||||
}
|
||||
|
||||
const priorExecutionSteps = await ExecutionStep.query().where({
|
||||
execution_id: (await flow.$relatedQuery('lastExecution')).id,
|
||||
});
|
||||
|
||||
// compute variables in parameters
|
||||
const computedParameters = computeParameters($.step.parameters, priorExecutionSteps);
|
||||
|
||||
$.step.parameters = computedParameters;
|
||||
|
||||
const fetchedData = await command.run($);
|
||||
|
||||
if (fetchedData.error) {
|
||||
|
@@ -21,6 +21,7 @@ class Flow extends Base {
|
||||
published_at: string;
|
||||
remoteWebhookId: string;
|
||||
executions?: Execution[];
|
||||
lastExecution?: Execution;
|
||||
user?: User;
|
||||
|
||||
static tableName = 'flows';
|
||||
@@ -58,6 +59,17 @@ class Flow extends Base {
|
||||
to: 'executions.flow_id',
|
||||
},
|
||||
},
|
||||
lastExecution: {
|
||||
relation: Base.HasOneRelation,
|
||||
modelClass: Execution,
|
||||
join: {
|
||||
from: 'flows.id',
|
||||
to: 'executions.flow_id',
|
||||
},
|
||||
filter(builder: ExtendedQueryBuilder<Execution>) {
|
||||
builder.orderBy('created_at', 'desc').limit(1).first();
|
||||
},
|
||||
},
|
||||
user: {
|
||||
relation: Base.HasOneRelation,
|
||||
modelClass: User,
|
||||
@@ -89,10 +101,7 @@ class Flow extends Base {
|
||||
}
|
||||
|
||||
async lastInternalId() {
|
||||
const lastExecution = await this.$relatedQuery('executions')
|
||||
.orderBy('created_at', 'desc')
|
||||
.limit(1)
|
||||
.first();
|
||||
const lastExecution = await this.$relatedQuery('lastExecution');
|
||||
|
||||
return lastExecution ? (lastExecution as Execution).internalId : null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user