Skip to content

Commit

Permalink
Merge pull request #248 from Oliver-I/chore-update-sdk
Browse files Browse the repository at this point in the history
chore(SDK):Update to latest SDK
  • Loading branch information
germanattanasio authored Oct 23, 2019
2 parents c298991 + 074a5d3 commit e992570
Show file tree
Hide file tree
Showing 6 changed files with 1,530 additions and 869 deletions.
5 changes: 1 addition & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Environment variables
ASSISTANT_ID=
# You need to provide either username and password
ASSISTANT_USERNAME=
ASSISTANT_PASSWORD=
# OR IAM API key and URL
# You need to provide your IAM API key and URL
ASSISTANT_IAM_APIKEY=
ASSISTANT_IAM_URL=
ASSISTANT_URL=https://gateway.watsonplatform.net/assistant/api
15 changes: 10 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
var express = require('express'); // app server
var bodyParser = require('body-parser'); // parser for post requests
var AssistantV2 = require('ibm-watson/assistant/v2'); // watson sdk
const { IamAuthenticator } = require('ibm-watson/auth');

var app = express();

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

var assistant = new AssistantV2({
version: '2019-02-28'
version: '2019-02-28',
authenticator: new IamAuthenticator({
apikey: process.env.ASSISTANT_IAM_APIKEY
}),
url: process.env.ASSISTANT_IAM_URL,
});


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

var payload = {
assistant_id: assistantId,
session_id: req.body.session_id,
assistantId: assistantId,
sessionId: req.body.session_id,
input: {
message_type : 'text',
text : textIn
Expand All @@ -73,7 +78,7 @@ app.post('/api/message', function (req, res) {

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

0 comments on commit e992570

Please sign in to comment.