Skip to content

Commit

Permalink
Merge pull request #250 from watson-developer-cloud/depups
Browse files Browse the repository at this point in the history
Fix travis and update dependencies
  • Loading branch information
germanattanasio authored Nov 7, 2019
2 parents 962d7ff + 2419510 commit d9fa7a3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 45 deletions.
36 changes: 16 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
language: node_js
dist: trusty
sudo: required
node_js: 8
node_js: 12
script:
- npm run test
- npm run test

cache:
directories:
- node_modules
- node_modules
env:
global:
- BX_APP=watson-assistant-simple
- BX_API=https://api.ng.bluemix.net
- BX_ORGANIZATION=WatsonPlatformServices
- BX_SPACE=demos
- BX_APP=watson-assistant-simple
- BX_API=https://api.ng.bluemix.net
- BX_ORGANIZATION=WatsonPlatformServices
- BX_SPACE=demos
before_deploy: npm install -g bx-blue-green
deploy:
- provider: script
skip_cleanup: true
script:
- bx-blue-green-travis
on:
branch: master
repo: watson-developer-cloud/assistant-simple
- provider: script
skip_cleanup: true
script: npx semantic-release
on:
node: 8

- provider: script
skip_cleanup: true
script: bx-blue-green-travis
on:
branch: master
repo: watson-developer-cloud/assistant-simple
- provider: script
skip_cleanup: true
script: npx semantic-release
54 changes: 30 additions & 24 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
*
*
* Copyright 2015 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -33,59 +33,65 @@ 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 || '<assistant-id>';
if (!assistantId || assistantId === '<assistant-id>') {
return res.json({
'output': {
'text': 'The app has not been configured with a <b>ASSISTANT_ID</b> environment variable. Please refer to the ' + '<a href="https://github.com/watson-developer-cloud/assistant-simple">README</a> documentation on how to set this variable. <br>' + 'Once a workspace has been defined the intents may be imported from ' + '<a href="https://github.com/watson-developer-cloud/assistant-simple/blob/master/training/car_workspace.json">here</a> in order to get a working application.'
}
output: {
text:
'The app has not been configured with a <b>ASSISTANT_ID</b> environment variable. Please refer to the ' +
'<a href="https://github.com/watson-developer-cloud/assistant-simple">README</a> documentation on how to set this variable. <br>' +
'Once a workspace has been defined the intents may be imported from ' +
'<a href="https://github.com/watson-developer-cloud/assistant-simple/blob/master/training/car_workspace.json">here</a> in order to get a working application.',
},
});
}

var textIn = '';

if(req.body.input) {
if (req.body.input) {
textIn = req.body.input.text;
}

var payload = {
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);
}

return res.json(data);
});
});

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;
module.exports = app;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"access": "public"
},
"engines": {
"node": ">=8.15.0"
"node": ">=12"
},
"engineStrict": true,
"devDependencies": {
Expand Down

0 comments on commit d9fa7a3

Please sign in to comment.