Skip to content

Commit a939b98

Browse files
chore(SDK):Update to latest SDK (#20)
chore(SDK):Update to latest SDK
2 parents bc7bab9 + 89ae519 commit a939b98

File tree

7 files changed

+244
-172
lines changed

7 files changed

+244
-172
lines changed

.env.example

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Environment variables
2-
ASSISTANT_URL=https://gateway.watsonplatform.net/assistant/api
2+
ASSISTANT_ID=
3+
# You need to provide your IAM API key and URL
34
ASSISTANT_IAM_APIKEY=
4-
ASSISTANT_ID=
5+
ASSISTANT_IAM_URL=
6+
ASSISTANT_URL=https://gateway.watsonplatform.net/assistant/api

index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ require('./config/express')(app);
2121
const AssistantV2 = require('ibm-watson/assistant/v2');
2222
const uuidV1 = require('uuid/v1');
2323
const NodeCache = require('node-cache');
24+
const { IamAuthenticator } = require('ibm-watson/auth');
2425
const bank = require('./lib/bankFunctions');
2526
// stdTTL time in seconds (15 mins)
2627
const searchCache = new NodeCache({ stdTTL: 900 });
2728

2829
// declare Watson Assistant service
2930
const assistant = new AssistantV2({
3031
version: '2019-02-28',
32+
authenticator: new IamAuthenticator({
33+
apikey: process.env.ASSISTANT_IAM_APIKEY,
34+
}),
35+
url: process.env.ASSISTANT_IAM_URL,
3136
});
3237

3338
const date = new Date();
@@ -100,8 +105,8 @@ app.post('/api/message', (req, res) => {
100105

101106
// assemble assistant payload
102107
const payload = {
103-
assistant_id: assistantId,
104-
session_id: req.body.session_id,
108+
assistantId,
109+
sessionId: req.body.session_id,
105110
input: {
106111
message_type: 'text',
107112
text: textIn,
@@ -151,7 +156,7 @@ app.get('/bank/statement', (req, res) => {
151156

152157
app.get('/api/session', (req, res) => {
153158
assistant.createSession({
154-
assistant_id: process.env.ASSISTANT_ID || '{assistant_id}',
159+
assistantId: process.env.ASSISTANT_ID || '{assistant_id}',
155160
}, (error, response) => {
156161
if (error) {
157162
console.log(error);

0 commit comments

Comments
 (0)