UNPKG

@ibm-adw/skill-toolkit

Version:

Developing your own skills with IBM Automation Digital Worker Skill Toolkit

88 lines (77 loc) 3.48 kB
/* Licensed Materials - Property of IBM 5737-I23 Copyright IBM Corp. 2019, 2020. All Rights Reserved. U.S. Government Users Restricted Rights: Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ 'use strict'; const path = require('path'); module.exports = async function (req, res) { const SKILL_DIR_1 = process.argv[2]; const SKILL_DIR = path.resolve(process.env.PWD, SKILL_DIR_1); try { const skill_to_be_tested = require(`${SKILL_DIR}/skill-config`); const schemaType = req.query.type; if (schemaType === 'input') { if (skill_to_be_tested.inputSchema) { try { const result = await skill_to_be_tested.inputSchema(global.skillConfiguration); global.inputSchema = result; if (req.query.pretty === 'true') { // Sending the result in a pretty format // Since that the result will be converted to string we need to ensure that the content-type is application/json res.set('Content-Type', 'application/json'); res.status(200).send(JSON.stringify(result, null, 2)); } else { // We are not going to prettify the json res.status(200).json(result); } } catch (error) { console.log(error); res.status(500).json({ name: error.name, message: error.message }); } } else { console.log('The function \'inputSchema\' is not implemented'); res.status(404).send('The function \'inputSchema\' is not implemented'); } } else if (schemaType === 'output') { if (skill_to_be_tested.outputSchema) { try { const result = await skill_to_be_tested.outputSchema(global.skillConfiguration); if (req.query.pretty === 'true') { // Sending the result in a pretty format // Since that the result will be converted to string we need to ensure that the content-type is application/json res.set('Content-Type', 'application/json'); res.status(200).send(JSON.stringify(result, null, 2)); } else { // We are not going to prettify the json res.status(200).json(result); } } catch (error) { console.log(error); res.status(500).json({ name: error.name, message: error.message }); } } else { console.log('The function \'outputSchema\' is not implemented'); res.status(404).send('The function \'outputSchema\' is not implemented'); } } else { console.log('The \'type\' should be \'input\' or \'output\''); res.status(422).send('The \'type\' should be \'input\' or \'output\''); } } catch (error) { console.log(error); res.status(500).json({ name: error.name, message: error.message }); } };