Skip to content

Commit e992570

Browse files
Merge pull request #248 from Oliver-I/chore-update-sdk
chore(SDK):Update to latest SDK
2 parents c298991 + 074a5d3 commit e992570

6 files changed

Lines changed: 1530 additions & 869 deletions

File tree

.env.example

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# Environment variables
22
ASSISTANT_ID=
3-
# You need to provide either username and password
4-
ASSISTANT_USERNAME=
5-
ASSISTANT_PASSWORD=
6-
# OR IAM API key and URL
3+
# You need to provide your IAM API key and URL
74
ASSISTANT_IAM_APIKEY=
85
ASSISTANT_IAM_URL=
96
ASSISTANT_URL=https://gateway.watsonplatform.net/assistant/api

app.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
var express = require('express'); // app server
2121
var bodyParser = require('body-parser'); // parser for post requests
2222
var AssistantV2 = require('ibm-watson/assistant/v2'); // watson sdk
23+
const { IamAuthenticator } = require('ibm-watson/auth');
2324

2425
var app = express();
2526

@@ -30,13 +31,17 @@ app.use(bodyParser.json());
3031
// Create the service wrapper
3132

3233
var assistant = new AssistantV2({
33-
version: '2019-02-28'
34+
version: '2019-02-28',
35+
authenticator: new IamAuthenticator({
36+
apikey: process.env.ASSISTANT_IAM_APIKEY
37+
}),
38+
url: process.env.ASSISTANT_IAM_URL,
3439
});
3540

3641

3742
// Endpoint to be call from the client side
3843
app.post('/api/message', function (req, res) {
39-
var assistantId = process.env.ASSISTANT_ID || '<assistant-id>';
44+
let assistantId = process.env.ASSISTANT_ID || '<assistant-id>';
4045
if (!assistantId || assistantId === '<assistant-id>') {
4146
return res.json({
4247
'output': {
@@ -52,8 +57,8 @@ app.post('/api/message', function (req, res) {
5257
}
5358

5459
var payload = {
55-
assistant_id: assistantId,
56-
session_id: req.body.session_id,
60+
assistantId: assistantId,
61+
sessionId: req.body.session_id,
5762
input: {
5863
message_type : 'text',
5964
text : textIn
@@ -73,7 +78,7 @@ app.post('/api/message', function (req, res) {
7378

7479
app.get('/api/session', function (req, res) {
7580
assistant.createSession({
76-
assistant_id: process.env.ASSISTANT_ID || '{assistant_id}',
81+
assistantId: process.env.ASSISTANT_ID || '{assistant_id}',
7782
}, function (error, response) {
7883
if (error) {
7984
return res.send(error);

0 commit comments

Comments
 (0)