Skip to content

Commit 6b0f2f6

Browse files
committed
Migrate Conversation to Assistant
1 parent 94317c9 commit 6b0f2f6

File tree

5 files changed

+42
-28
lines changed

5 files changed

+42
-28
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ Node-RED Watson Nodes for IBM Cloud
1111
- Move all Discovery calls to latest API version - 2017-11-07
1212
- Updated calls to deprecated discovery methods addJsonDocument and getCollections
1313
- Correct implemetation of passages related options
14-
- Allow highlight option to be specified in Discovery overrides - msg.discoveryparams
14+
- Allow highlight option to be specified in Discovery overrides - msg.discoveryparams
15+
- Rename Conversation Nodes to Assistant
16+
- Use Assistant endpoint
17+
- Move all Assistant calls to latest API version - 2018-02-16
1518

1619
### New in version 0.6.7
1720
- Enable Opt-out option for Conversation Node.

services/conversation/v1-workspace-manager.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
</div>
4646
<div class="form-row">
4747
<label for="node-input-cwm-service-endpoint"><i class="fa fa-tag"></i> Service Endpoint</label>
48-
<input type="text" id="node-input-cwm-service-endpoint" placeholder="https://gateway.watsonplatform.net/conversation/api">
48+
<input type="text" id="node-input-cwm-service-endpoint" placeholder="https://gateway.watsonplatform.net/assistant/api">
4949
</div>
5050

5151
<div class="form-row">
@@ -351,7 +351,7 @@
351351
</li>
352352
<li>
353353
<code>msg.params.password</code>
354-
</li>
354+
</li>
355355
<li>
356356
<code>msg.params.workspace_id</code>
357357
</li>
@@ -592,7 +592,7 @@
592592
'cwm-dialog-node': {value:""},
593593
'cwm-export-content': {value:false},
594594
'cwm-default-endpoint' :{value: true},
595-
'cwm-service-endpoint' :{value: 'https://gateway.watsonplatform.net/conversation/api'}
595+
'cwm-service-endpoint' :{value: 'https://gateway.watsonplatform.net/assistant/api'}
596596
},
597597
credentials: {
598598
username: {type:'text'},
@@ -602,9 +602,9 @@
602602
inputs: 1,
603603
outputs: 1,
604604
icon: 'conversation-v1-25x25.png',
605-
paletteLabel: 'conversation workspace manager',
605+
paletteLabel: 'assistant workspace manager',
606606
label: function() {
607-
return this.name || 'conversation workspace manager';
607+
return this.name || 'assistant workspace manager';
608608
},
609609
labelStyle: function() {
610610
return this.name ? 'node_label_italic' : '';

services/conversation/v1-workspace-manager.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@
1515
**/
1616

1717
module.exports = function (RED) {
18-
const SERVICE_IDENTIFIER = 'conversation';
18+
const SERVICE_IDENTIFIER = 'assistant';
19+
const OLD_SERVICE_IDENTIFIER = 'conversation';
1920
var pkg = require('../../package.json'),
2021
temp = require('temp'),
2122
fs = require('fs'),
2223
serviceutils = require('../../utilities/service-utils'),
2324
payloadutils = require('../../utilities/payload-utils'),
24-
ConversationV1 = require('watson-developer-cloud/conversation/v1'),
25+
AssistantV1 = require('watson-developer-cloud/assistant/v1'),
2526
service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER),
2627
username = '', password = '', sUsername = '', sPassword = '',
2728
endpoint = '', sEndpoint = '';
2829

30+
if (!service) {
31+
service = serviceutils.getServiceCreds(OLD_SERVICE_IDENTIFIER);
32+
}
33+
2934
temp.track();
3035

3136
// Require the Cloud Foundry Module to pull credentials from bound service
@@ -117,7 +122,7 @@ module.exports = function (RED) {
117122

118123
function executeListIntents(node, conv, params, msg) {
119124
var p = new Promise(function resolver(resolve, reject){
120-
conv.getIntents(params, function (err, response) {
125+
conv.listIntents(params, function (err, response) {
121126
if (err) {
122127
reject(err);
123128
} else {
@@ -193,7 +198,7 @@ module.exports = function (RED) {
193198
// response
194199
function executeListExamples(node, conv, params, msg) {
195200
var p = new Promise(function resolver(resolve, reject){
196-
conv.getExamples(params, function (err, response) {
201+
conv.listExamples(params, function (err, response) {
197202
if (err) {
198203
reject(err);
199204
} else {
@@ -236,7 +241,7 @@ module.exports = function (RED) {
236241

237242
function executeListCounterExamples(node, conv, params, msg) {
238243
var p = new Promise(function resolver(resolve, reject){
239-
conv.getCounterExamples(params, function (err, response) {
244+
conv.listCounterexamples(params, function (err, response) {
240245
if (err) {
241246
reject(err);
242247
} else {
@@ -251,7 +256,7 @@ module.exports = function (RED) {
251256

252257
function executeCreateCounterExample(node, conv, params, msg) {
253258
var p = new Promise(function resolver(resolve, reject){
254-
conv.createCounterExample(params, function (err, response) {
259+
conv.createCounterexample(params, function (err, response) {
255260
if (err) {
256261
reject(err);
257262
} else {
@@ -265,7 +270,7 @@ module.exports = function (RED) {
265270

266271
function executeDeleteCounterExample(node, conv, params, msg) {
267272
var p = new Promise(function resolver(resolve, reject){
268-
conv.deleteCounterExample(params, function (err, response) {
273+
conv.deleteCounterexample(params, function (err, response) {
269274
if (err) {
270275
reject(err);
271276
} else {
@@ -279,7 +284,7 @@ module.exports = function (RED) {
279284

280285
function executeListEntities(node, conv, params, msg) {
281286
var p = new Promise(function resolver(resolve, reject){
282-
conv.getEntities(params, function (err, response) {
287+
conv.listEntities(params, function (err, response) {
283288
if (err) {
284289
reject(err);
285290
} else {
@@ -352,7 +357,7 @@ module.exports = function (RED) {
352357

353358
function executeListEntityValues(node, conv, params, msg) {
354359
var p = new Promise(function resolver(resolve, reject){
355-
conv.getValues(params, function (err, response) {
360+
conv.listValues(params, function (err, response) {
356361
if (err) {
357362
reject(err);
358363
} else {
@@ -422,7 +427,7 @@ module.exports = function (RED) {
422427

423428
function executeListDialogNodes(node, conv, params, msg) {
424429
var p = new Promise(function resolver(resolve, reject){
425-
conv.getDialogNodes(params, function (err, response) {
430+
conv.listDialogNodes(params, function (err, response) {
426431
if (err) {
427432
reject(err);
428433
} else {
@@ -499,7 +504,8 @@ module.exports = function (RED) {
499504
serviceSettings = {
500505
username: username,
501506
password: password,
502-
version_date: '2017-05-26',
507+
version_date: '2018-02-16',
508+
version: '2018-02-16',
503509
headers: {
504510
'User-Agent': pkg.name + '-' + pkg.version
505511
}
@@ -509,7 +515,7 @@ module.exports = function (RED) {
509515
serviceSettings.url = endpoint;
510516
}
511517

512-
conv = new ConversationV1(serviceSettings);
518+
conv = new AssistantV1(serviceSettings);
513519

514520
node.status({fill:'blue', shape:'dot', text:'executing'});
515521

@@ -1068,12 +1074,12 @@ module.exports = function (RED) {
10681074
params = {};
10691075

10701076
username = sUsername || this.credentials.username;
1071-
password = sPassword || this.credentials.password || config.password;
1077+
password = sPassword || this.credentials.password || config.password;
10721078

10731079
// All method to be overridden
10741080
if (msg.params) {
10751081
if (msg.params.method) {
1076-
method = msg.params.method;
1082+
method = msg.params.method;
10771083
}
10781084
if (msg.params.username) {
10791085
username = msg.params.username;

services/conversation/v1.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</div>
4343
<div class="form-row">
4444
<label for="node-input-service-endpoint"><i class="fa fa-tag"></i> Service Endpoint</label>
45-
<input type="text" id="node-input-service-endpoint" placeholder="https://gateway.watsonplatform.net/conversation/api">
45+
<input type="text" id="node-input-service-endpoint" placeholder="https://gateway.watsonplatform.net/assistant/api">
4646
</div>
4747

4848
<div class="form-row">
@@ -159,7 +159,7 @@
159159
context: {value: true},
160160
'empty-payload': {value: false},
161161
'default-endpoint' : {value: true},
162-
'service-endpoint' : {value: 'https://gateway.watsonplatform.net/conversation/api'},
162+
'service-endpoint' : {value: 'https://gateway.watsonplatform.net/assistant/api'},
163163
timeout: {value: '', validate: RED.validators.number(true)},
164164
'optout-learning': {value: false}
165165
},
@@ -171,9 +171,9 @@
171171
inputs: 1,
172172
outputs: 1,
173173
icon: 'conversation-v1-25x25.png',
174-
paletteLabel: 'conversation',
174+
paletteLabel: 'assistant',
175175
label: function() {
176-
return this.name || 'conversation';
176+
return this.name || 'assistant';
177177
},
178178
labelStyle: function() {
179179
return this.name ? 'node_label_italic' : '';

services/conversation/v1.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@
1515
**/
1616

1717
module.exports = function(RED) {
18-
const SERVICE_IDENTIFIER = 'conversation';
18+
const SERVICE_IDENTIFIER = 'assistant';
19+
const OLD_SERVICE_IDENTIFIER = 'conversation';
1920
var pkg = require('../../package.json'),
20-
ConversationV1 = require('watson-developer-cloud/conversation/v1'),
21+
AssistantV1 = require('watson-developer-cloud/assistant/v1'),
2122
serviceutils = require('../../utilities/service-utils'),
2223
service = null,
2324
sUsername = null,
2425
sPassword = null;
2526

2627
service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER);
28+
if (!service) {
29+
service = serviceutils.getServiceCreds(OLD_SERVICE_IDENTIFIER);
30+
}
2731

2832
if (service) {
2933
sUsername = service.username;
@@ -136,7 +140,8 @@ module.exports = function(RED) {
136140
// If msg.params contain credentials then these will Overridde
137141
// the bound or configured credentials.
138142
const serviceSettings = {
139-
version_date: '2017-05-26',
143+
version_date: '2018-02-16',
144+
version: '2018-02-16',
140145
headers: {
141146
'User-Agent': pkg.name + '-' + pkg.version
142147
}
@@ -203,7 +208,7 @@ module.exports = function(RED) {
203208
serviceSettings.timeout = parseInt(msg.params.timeout);
204209
}
205210

206-
node.service = new ConversationV1(serviceSettings);
211+
node.service = new AssistantV1(serviceSettings);
207212
return true;
208213
}
209214

0 commit comments

Comments
 (0)