Skip to content

Commit

Permalink
Merge pull request #45 from ibmdbgmx/master
Browse files Browse the repository at this point in the history
watson language translator and visual recognition updated to IAM apikey
  • Loading branch information
jweisz authored Oct 8, 2018
2 parents f894fea + 96138ec commit 4370d91
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
27 changes: 11 additions & 16 deletions lib/tjbot.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,14 @@ TJBot.prototype._createServiceAPI = function(service, credentials) {
break;

case 'language_translator':
assert(credentials.hasOwnProperty('username'), "credentials for the " + service + " service missing 'username'");
assert(credentials.hasOwnProperty('password'), "credentials for the " + service + " service missing 'password'");

var LanguageTranslatorV2 = require('watson-developer-cloud/language-translator/v2');
this._languageTranslator = new LanguageTranslatorV2({
username: credentials['username'],
password: credentials['password'],
version: 'v2',
//assert(credentials.hasOwnProperty('username'), "credentials for the " + service + " service missing 'username'");
//assert(credentials.hasOwnProperty('password'), "credentials for the " + service + " service missing 'password'");
assert(credentials.hasOwnProperty('apikey'), "credentials for the " + service + " service missing 'apikey'");

var LanguageTranslatorV3 = require('watson-developer-cloud/language-translator/v3');
this._languageTranslator = new LanguageTranslatorV3({
iam_apikey: credentials['apikey'],
version: '2018-05-01',
url: 'https://gateway.watsonplatform.net/language-translator/api/'
});

Expand Down Expand Up @@ -434,15 +434,10 @@ TJBot.prototype._createServiceAPI = function(service, credentials) {
// https://www.ibm.com/watson/developercloud/visual-recognition/api/v3/node.html?node#authentication
if (credentials['api_key'] != undefined) {
this._visualRecognition = new VisualRecognitionV3({
api_key: credentials['api_key'],
iam_apikey: credentials['api_key'],
version: '2018-03-19'
});
} else if (credentials['iam_apikey'] != undefined) {
this._visualRecognition = new VisualRecognitionV3({
api_key: credentials['iam_apikey'],
version: '2018-03-19'
});
} else {
}else {
throw new Error(
'No authentication credentials specified for visual_recognition service.');
}
Expand Down Expand Up @@ -1320,7 +1315,7 @@ TJBot.prototype._loadLanguageTranslations = function() {
var self = this;
return new Promise(function(resolve, reject) {
if (self._translations == undefined) {
self._languageTranslator.getModels({}, function(err, models) {
self._languageTranslator.listModels({}, function(err, models) {
var translations = {};
if (err) {
winston.error("unable to retrieve list of language models for translation", err);
Expand Down
2 changes: 1 addition & 1 deletion package.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"sleep": "^5.0.0",
"sound-player": "^1.0.4",
"temp": "^0.8.3",
"watson-developer-cloud": "^3.4.5",
"watson-developer-cloud": "^3.10",
"winston": "^2.3.1"
},
"engines": {
Expand Down

0 comments on commit 4370d91

Please sign in to comment.