From 69fba1ee45a1ecf22c6f5de39e968e097a44e973 Mon Sep 17 00:00:00 2001 From: ibrezm1 Date: Sat, 23 Oct 2021 00:27:33 +0530 Subject: [PATCH 1/6] updated env.example & updated app.js to change url to Serviceurl as per the new V2 code --- .env.example | 7 +++---- app.js | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index a14bcb8d..9bf7f12b 100644 --- a/.env.example +++ b/.env.example @@ -1,10 +1,9 @@ # 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= diff --git a/app.js b/app.js index fddf7ca4..6fbc3396 100644 --- a/app.js +++ b/app.js @@ -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 From 5689ce62d5ffb3caebd9dc4e2f94c8ffc9ee6a8c Mon Sep 17 00:00:00 2001 From: ibrezm1 Date: Sat, 23 Oct 2021 00:40:26 +0530 Subject: [PATCH 2/6] updated node version due to travis ci error --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 20ab1f03..72072e7c 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "access": "public" }, "engines": { - "node": ">=12" + "node": ">=14" }, "engineStrict": true, "devDependencies": { From f61561fc7132e9ad67a3415f5694d7d4440e70d5 Mon Sep 17 00:00:00 2001 From: ibrezm1 <59130871+ibrezm1@users.noreply.github.com> Date: Sat, 23 Oct 2021 00:46:17 +0530 Subject: [PATCH 3/6] Update .travis.yml updated travis for NPM version update to 14 due to https://github.com/semantic-release/semantic-release/blob/master/docs/support/node-version.md error --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c631fde6..d290e1e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js dist: trusty sudo: required -node_js: 12 +node_js: 14 script: - npm run test @@ -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" From af5d04dc5321507b6103df720490e13c6af7f5be Mon Sep 17 00:00:00 2001 From: ibrezm1 Date: Sat, 23 Oct 2021 08:28:19 +0530 Subject: [PATCH 4/6] added upload script --- .env.example | 13 ++++++++++++- upload.sh | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100755 upload.sh diff --git a/.env.example b/.env.example index 9bf7f12b..a736943b 100644 --- a/.env.example +++ b/.env.example @@ -7,4 +7,15 @@ ASSISTANT_IAM_APIKEY=5u30uOLxxxxxxxxxxxxxxxxxxxxxxxhKksG # Cloud Pak for Data connection parameters BEARER_TOKEN= -DISABLE_SSL_VERIFICATION=false \ No newline at end of file +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 diff --git a/upload.sh b/upload.sh new file mode 100755 index 00000000..ac051ef5 --- /dev/null +++ b/upload.sh @@ -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" From a0f4b68a5fdcc9b600cd709b80f1e50a12b536a4 Mon Sep 17 00:00:00 2001 From: ibrezm1 Date: Sat, 23 Oct 2021 08:38:03 +0530 Subject: [PATCH 5/6] updated readme for upload.sh --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 97361ceb..573591e8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

🚀 Watson Assistant (formerly Conversation) Sample Application

+

🚀 Watson Assistant Sample Application

This Node.js app demonstrates the Watson Assistant service in a simple interface engaging in a series of simple simulated banking tasks.

@@ -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* From 6fcd18b5a9778b72d142062c0060ce8de18b1ded Mon Sep 17 00:00:00 2001 From: ibrezm1 Date: Sat, 23 Oct 2021 09:31:03 +0530 Subject: [PATCH 6/6] access context --- app.js | 7 ++++++- public/js/api.js | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index 6fbc3396..2f2b9c1b 100644 --- a/app.js +++ b/app.js @@ -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 diff --git a/public/js/api.js b/public/js/api.js index f1524618..ab17aa3e 100644 --- a/public/js/api.js +++ b/public/js/api.js @@ -57,6 +57,9 @@ var Api = (function() { payloadToWatson.input = { message_type: 'text', text: text, + options: { + 'return_context': true + } };