diff --git a/app.js b/app.js index b5a76a54..5df1e466 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,5 @@ /** - * + * * Copyright 2015 IBM Corp. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,26 +33,29 @@ app.use(bodyParser.json()); var assistant = new AssistantV2({ version: '2019-02-28', authenticator: new IamAuthenticator({ - apikey: process.env.ASSISTANT_IAM_APIKEY + apikey: process.env.ASSISTANT_IAM_APIKEY, }), - url: process.env.ASSISTANT_IAM_URL, + url: process.env.ASSISTANT_URL, }); - // Endpoint to be call from the client side -app.post('/api/message', function (req, res) { +app.post('/api/message', function(req, res) { let assistantId = process.env.ASSISTANT_ID || ''; if (!assistantId || assistantId === '') { return res.json({ - 'output': { - 'text': 'The app has not been configured with a ASSISTANT_ID environment variable. Please refer to the ' + 'README documentation on how to set this variable.
' + 'Once a workspace has been defined the intents may be imported from ' + 'here in order to get a working application.' - } + output: { + text: + 'The app has not been configured with a ASSISTANT_ID environment variable. Please refer to the ' + + 'README documentation on how to set this variable.
' + + 'Once a workspace has been defined the intents may be imported from ' + + 'here in order to get a working application.', + }, }); } var textIn = ''; - if(req.body.input) { + if (req.body.input) { textIn = req.body.input.text; } @@ -60,15 +63,15 @@ app.post('/api/message', function (req, res) { assistantId: assistantId, sessionId: req.body.session_id, input: { - message_type : 'text', - text : textIn - } + message_type: 'text', + text: textIn, + }, }; // Send the input to the assistant service - assistant.message(payload, function (err, data) { + assistant.message(payload, function(err, data) { if (err) { - const status = (err.code !== undefined && err.code > 0)? err.code : 500; + const status = err.code !== undefined && err.code > 0 ? err.code : 500; return res.status(status).json(err); } @@ -76,16 +79,19 @@ app.post('/api/message', function (req, res) { }); }); -app.get('/api/session', function (req, res) { - assistant.createSession({ - assistantId: process.env.ASSISTANT_ID || '{assistant_id}', - }, function (error, response) { - if (error) { - return res.send(error); - } else { - return res.send(response); +app.get('/api/session', function(req, res) { + assistant.createSession( + { + assistantId: process.env.ASSISTANT_ID || '{assistant_id}', + }, + function(error, response) { + if (error) { + return res.send(error); + } else { + return res.send(response); + } } - }); + ); }); -module.exports = app; \ No newline at end of file +module.exports = app; diff --git a/package.json b/package.json index 76d74cd0..20ab1f03 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "access": "public" }, "engines": { - "node": ">=8.15.0" + "node": ">=12" }, "engineStrict": true, "devDependencies": {