Skip to content

Commit c9278bb

Browse files
author
Steve Green
authored
Merge pull request #239 from Oliver-I/chore/refactor-context-for-v2-api
chore(context):Removed context in line with API V2
2 parents cbbbb78 + f7b93da commit c9278bb

5 files changed

Lines changed: 304 additions & 215 deletions

File tree

app.js

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
2+
*
23
* Copyright 2015 IBM Corp. All Rights Reserved.
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +19,7 @@
1819

1920
var express = require('express'); // app server
2021
var bodyParser = require('body-parser'); // parser for post requests
21-
var AssistantV2 = require('watson-developer-cloud/assistant/v2'); // watson sdk
22+
var AssistantV2 = require('ibm-watson/assistant/v2'); // watson sdk
2223

2324
var app = express();
2425

@@ -29,34 +30,20 @@ app.use(bodyParser.json());
2930
// Create the service wrapper
3031

3132
var assistant = new AssistantV2({
32-
version: '2018-11-08'
33+
version: '2019-02-28'
3334
});
3435

35-
var newContext = {
36-
global : {
37-
system : {
38-
turn_count : 1
39-
}
40-
}
41-
};
4236

4337
// Endpoint to be call from the client side
4438
app.post('/api/message', function (req, res) {
4539
var assistantId = process.env.ASSISTANT_ID || '<assistant-id>';
46-
if (!assistantId || assistantId === '<assistant-id>>') {
40+
if (!assistantId || assistantId === '<assistant-id>') {
4741
return res.json({
4842
'output': {
4943
'text': 'The app has not been configured with a <b>ASSISTANT_ID</b> environment variable. Please refer to the ' + '<a href="https://github.com/watson-developer-cloud/assistant-simple">README</a> documentation on how to set this variable. <br>' + 'Once a workspace has been defined the intents may be imported from ' + '<a href="https://github.com/watson-developer-cloud/assistant-simple/blob/master/training/car_workspace.json">here</a> in order to get a working application.'
5044
}
5145
});
5246
}
53-
var contextWithAcc = (req.body.context) ? req.body.context : newContext;
54-
55-
if (req.body.context) {
56-
contextWithAcc.global.system.turn_count += 1;
57-
}
58-
59-
//console.log(JSON.stringify(contextWithAcc, null, 2));
6047

6148
var textIn = '';
6249

@@ -67,13 +54,9 @@ app.post('/api/message', function (req, res) {
6754
var payload = {
6855
assistant_id: assistantId,
6956
session_id: req.body.session_id,
70-
context: contextWithAcc,
7157
input: {
7258
message_type : 'text',
73-
text : textIn,
74-
options : {
75-
return_context : true
76-
}
59+
text : textIn
7760
}
7861
};
7962

0 commit comments

Comments
 (0)