Skip to content

Commit

Permalink
chore(SDK):Update to latest SDK (#20)
Browse files Browse the repository at this point in the history
chore(SDK):Update to latest SDK
  • Loading branch information
germanattanasio authored Oct 25, 2019
2 parents bc7bab9 + 89ae519 commit a939b98
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 172 deletions.
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Environment variables
ASSISTANT_URL=https://gateway.watsonplatform.net/assistant/api
ASSISTANT_ID=
# You need to provide your IAM API key and URL
ASSISTANT_IAM_APIKEY=
ASSISTANT_ID=
ASSISTANT_IAM_URL=
ASSISTANT_URL=https://gateway.watsonplatform.net/assistant/api
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ require('./config/express')(app);
const AssistantV2 = require('ibm-watson/assistant/v2');
const uuidV1 = require('uuid/v1');
const NodeCache = require('node-cache');
const { IamAuthenticator } = require('ibm-watson/auth');
const bank = require('./lib/bankFunctions');
// stdTTL time in seconds (15 mins)
const searchCache = new NodeCache({ stdTTL: 900 });

// declare Watson Assistant service
const assistant = new AssistantV2({
version: '2019-02-28',
authenticator: new IamAuthenticator({
apikey: process.env.ASSISTANT_IAM_APIKEY,
}),
url: process.env.ASSISTANT_IAM_URL,
});

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

// assemble assistant payload
const payload = {
assistant_id: assistantId,
session_id: req.body.session_id,
assistantId,
sessionId: req.body.session_id,
input: {
message_type: 'text',
text: textIn,
Expand Down Expand Up @@ -151,7 +156,7 @@ app.get('/bank/statement', (req, res) => {

app.get('/api/session', (req, res) => {
assistant.createSession({
assistant_id: process.env.ASSISTANT_ID || '{assistant_id}',
assistantId: process.env.ASSISTANT_ID || '{assistant_id}',
}, (error, response) => {
if (error) {
console.log(error);
Expand Down
Loading

0 comments on commit a939b98

Please sign in to comment.