Merge pull request #2315 from automatisch/add-properties-field-in-virtualq

feat(virtualq/actions): add properties JSON field
This commit is contained in:
Ali BARIN
2025-01-30 15:16:49 +01:00
committed by GitHub
5 changed files with 48 additions and 8 deletions

View File

@@ -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 = {
@@ -118,7 +130,8 @@ export default defineAction({
channel,
source,
appointment,
servicePhoneToCall,
service_phone_to_call: 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 });

View File

@@ -1,4 +1,5 @@
import defineAction from '../../../../helpers/define-action.js';
import isPlainObject from 'lodash/isPlainObject.js';
export default defineAction({
name: 'Update waiter',
@@ -49,7 +50,7 @@ export default defineAction({
description: 'Used to find caller if 0 is used for waiter field',
},
{
label: 'EWT',
label: 'Estimated waiting time',
key: 'serviceWaiterEwt',
type: 'string',
description: 'EWT as calculated by the service',
@@ -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 });

View File

@@ -11,8 +11,8 @@ export default defineApp({
iconUrl: '{BASE_URL}/apps/virtualq/assets/favicon.svg',
authDocUrl: '{DOCS_URL}/apps/virtualq/connection',
supportsConnections: true,
baseUrl: 'https://www.virtualq.io',
apiBaseUrl: 'https://api.virtualq.io/api/',
baseUrl: 'https://www.virtualq.tech',
apiBaseUrl: 'https://api.virtualq.tech/api/',
primaryColor: '#2E3D59',
beforeRequest: [addAuthHeader],
auth,

View File

@@ -51,8 +51,6 @@ export const processAction = async (options) => {
const shouldNotConsiderAsError = shouldEarlyExit || shouldNotProcess;
if (!shouldNotConsiderAsError) {
logger.error(error);
if (error instanceof HttpError) {
$.actionOutput.error = error.details;
} else {
@@ -62,6 +60,8 @@ export const processAction = async (options) => {
$.actionOutput.error = { error: error.message };
}
}
logger.error(error);
}
}

View File

@@ -31,8 +31,6 @@ export const processFlow = async (options) => {
const shouldNotConsiderAsError = shouldEarlyExit || shouldNotProcess;
if (!shouldNotConsiderAsError) {
logger.error(error);
if (error instanceof HttpError) {
$.triggerOutput.error = error.details;
} else {
@@ -42,6 +40,8 @@ export const processFlow = async (options) => {
$.triggerOutput.error = { error: error.message };
}
}
logger.error(error);
}
}