Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# Environment variables
ASSISTANT_URL=https://gateway.watsonplatform.net/assistant/api
ASSISTANT_ID=
ASSISTANT_URL=https://api.eu-gb.assistant.watson.cloud.ibm.com
ASSISTANT_ID=3xxxxx-xxxx-xxxx-xxxx-c508e6a7d3b2

# IBM Cloud connection parameters
ASSISTANT_IAM_APIKEY=
ASSISTANT_IAM_URL=
ASSISTANT_IAM_APIKEY=5u30uOLxxxxxxxxxxxxxxxxxxxxxxxhKksG

# Cloud Pak for Data connection parameters
BEARER_TOKEN=
DISABLE_SSL_VERIFICATION=false
DISABLE_SSL_VERIFICATION=false



#Upload parameters
# Use V1 to update workspace
# workspaceid is the skill id
# https://cloud.ibm.com/apidocs/assistant/assistant-v1?code=node#updateworkspace

apikey=
workspace_id=20adfxxxx-xxxx-xxxx-xxxx-axxxxx75929
url=https://api.eu-gb.assistant.watson.cloud.ibm.com
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
dist: trusty
sudo: required
node_js: 12
node_js: 14
script:
- npm run test

Expand All @@ -24,4 +24,4 @@ deploy:
repo: watson-developer-cloud/assistant-simple
- provider: script
skip_cleanup: true
script: npx semantic-release
script: npx -p node@14 -c "npx semantic-release"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 align="center" style="border-bottom: none;">🚀 Watson Assistant (formerly Conversation) Sample Application</h1>
<h1 align="center" style="border-bottom: none;">🚀 Watson Assistant Sample Application</h1>
<h3 align="center">This Node.js app demonstrates the Watson Assistant service in a simple interface engaging in a series of simple simulated banking tasks.</h3>
<p align="center">
<a href="http://travis-ci.org/watson-developer-cloud/assistant-simple">
Expand Down Expand Up @@ -46,6 +46,7 @@ If you need more information about the V1 API, you can go to the [Watson Assista
5. Click the ![Copy](readme_images/copy_icon.png) icon to copy the workspace ID to the clipboard.

![Steps to get credentials](readme_images/assistant-simple.gif)
6. Alternate way is to setup workspace using upload.sh also set up env for the workspace.

6. In the application folder, copy the *.env.example* file and create a file called *.env*

Expand Down
11 changes: 8 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ if (process.env.ASSISTANT_IAM_APIKEY) {
var assistant = new AssistantV2({
version: '2019-02-28',
authenticator: authenticator,
url: process.env.ASSISTANT_URL,
disableSslVerification: process.env.DISABLE_SSL_VERIFICATION === 'true' ? true : false
serviceUrl: process.env.ASSISTANT_URL
//disableSslVerification: process.env.DISABLE_SSL_VERIFICATION === 'true' ? true : false
});

// Endpoint to be call from the client side
Expand All @@ -69,14 +69,19 @@ app.post('/api/message', function(req, res) {
if (req.body.input) {
textIn = req.body.input.text;
}

// accessing context data
//https://cloud.ibm.com/docs/assistant-data?topic=assistant-data-api-client-get-context&code=javascript
var payload = {
assistantId: assistantId,
sessionId: req.body.session_id,
input: {
message_type: 'text',
text: textIn,
options: {
'return_context': true
}
},

};

// Send the input to the assistant service
Expand Down
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": ">=12"
"node": ">=14"
},
"engineStrict": true,
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions public/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ var Api = (function() {
payloadToWatson.input = {
message_type: 'text',
text: text,
options: {
'return_context': true
}
};


Expand Down
12 changes: 12 additions & 0 deletions upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Local .env
# https://gist.github.com/mihow/9c7f559807069a03e302605691f85572
if [ -f .env ]; then
# Load Environment Variables
export $(cat .env | grep -v '#' | awk '/=/ {print $1}')
# For instance, will be example_kaggle_key
# echo $KAGGLE_KEY
fi

curl -X POST -u "apikey:${apikey}" --header "Content-Type: application/json" \
-d @training/bank_simple_workspace.json\
"${url}/v1/workspaces/${workspace_id}?version=2021-06-14"