diff --git a/packages/backend/src/apps/virtualq/actions/create-waiter/index.js b/packages/backend/src/apps/virtualq/actions/create-waiter/index.js index af22d2a5..b1233475 100644 --- a/packages/backend/src/apps/virtualq/actions/create-waiter/index.js +++ b/packages/backend/src/apps/virtualq/actions/create-waiter/index.js @@ -1,4 +1,5 @@ import defineAction from '../../../../helpers/define-action.js'; +import isPlainObject from 'lodash/isPlainObject.js'; export default defineAction({ name: 'Create waiter', @@ -97,6 +98,16 @@ export default defineAction({ required: false, variables: true, }, + { + label: 'Properties', + key: 'properties', + type: 'string', + required: false, + variables: false, + valueType: 'parse', + description: 'JSON for the additional properties.', + value: '{}', + }, ], async run($) { const { @@ -107,6 +118,7 @@ export default defineAction({ appointment, appointmentTime, servicePhoneToCall, + properties = {}, } = $.step.parameters; const body = { @@ -119,6 +131,7 @@ export default defineAction({ source, appointment, servicePhoneToCall, + properties, }, }, }; @@ -127,6 +140,12 @@ export default defineAction({ body.data.attributes.appointmentTime = appointmentTime; } + if (!isPlainObject(properties)) { + throw new Error( + `The "properties" field must have a valid JSON. The current value: ${properties}` + ); + } + const { data } = await $.http.post('/v2/waiters', body); $.setActionItem({ raw: data }); diff --git a/packages/backend/src/apps/virtualq/actions/update-waiter/index.js b/packages/backend/src/apps/virtualq/actions/update-waiter/index.js index 51f9d8b4..503f4e14 100644 --- a/packages/backend/src/apps/virtualq/actions/update-waiter/index.js +++ b/packages/backend/src/apps/virtualq/actions/update-waiter/index.js @@ -1,4 +1,5 @@ import defineAction from '../../../../helpers/define-action.js'; +import isPlainObject from 'lodash/isPlainObject.js'; export default defineAction({ name: 'Update waiter', @@ -104,6 +105,15 @@ export default defineAction({ required: false, variables: true, }, + { + label: 'Properties', + key: 'properties', + type: 'string', + required: false, + variables: false, + valueType: 'parse', + description: 'JSON for the additional properties.', + }, ], async run($) { @@ -117,6 +127,7 @@ export default defineAction({ talkTime, agentId, servicePhoneToCall, + properties, } = $.step.parameters; const body = { @@ -150,6 +161,16 @@ export default defineAction({ body.data.attributes.wait_time_when_up = waitTimeWhenUp; } + if (properties) { + if (!isPlainObject(properties)) { + throw new Error( + `The "properties" field must have a valid JSON. The current value: ${properties}` + ); + } + + body.data.attributes.properties = properties; + } + const { data } = await $.http.put(`/v2/waiters/${waiterId}`, body); $.setActionItem({ raw: data });