How to use the ibm-watson/auth.IamAuthenticator function in ibm-watson

To help you get started, we’ve selected a few ibm-watson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github watson-developer-cloud / natural-language-classifier-nodejs / app.js View on Github external
*/

const express = require('express');

const app = express();
const NaturalLanguageClassifierV1 = require('ibm-watson/natural-language-classifier/v1');
const { IamAuthenticator } = require('ibm-watson/auth');

// Bootstrap application settings
require('./config/express')(app);

// Create the service wrapper

const classifier = new NaturalLanguageClassifierV1({
  version: '2018-04-05',
  authenticator: new IamAuthenticator({
    apikey: process.env.NATURAL_LANGUAGE_CLASSIFIER_IAM_APIKEY || '',
  }),
  url: process.env.NATURAL_LANGUAGE_CLASSIFIER_URL,
});

app.get('/', (req, res) => {
  res.render('index', {
    showHeader: !(req.query.hide_header == 'true' || req.query.hide_header == '1'), // eslint-disable-line
  });
});

/**
 * Classify text
 */
app.post('/api/classify', (req, res, next) => {
  classifier.classify({
github watson-developer-cloud / natural-language-understanding-nodejs / app.js View on Github external
* Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

const express = require('express');
const NaturalLanguageUnderstandingV1 = require('ibm-watson/natural-language-understanding/v1.js');
const { IamAuthenticator } = require('ibm-watson/auth');

const app = express();
// Create the service wrapper
const nlu = new NaturalLanguageUnderstandingV1({
  version: '2018-04-05',
  authenticator: new IamAuthenticator({
    apikey: process.env.NATURAL_LANGUAGE_UNDERSTANDING_IAM_APIKEY || 'type-key-here',
  }),
  url: process.env.NATURAL_LANGUAGE_UNDERSTANDING_URL,
});

// setup body-parser
const bodyParser = require('body-parser');

app.use(bodyParser.json());

// Bootstrap application settings
require('./config/express')(app);

app.get('/', (req, res) => {
  res.render('index');
});
github watson-developer-cloud / assistant-intermediate / app.js View on Github external
var SearchDocs = require('./functions/searchDocs');
var searchDocs = new SearchDocs();

var BankFunctions = require('./functions/bankFunctions');
var bankFunctions = new BankFunctions();

var app = express();

// Bootstrap application settings
app.use(express.static('./public')); // load UI from public folder
app.use(bodyParser.json());

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

var date = new Date();
date.setMonth(date.getMonth() + 1);
var initContext = {
  skills: {
    'main skill': {
      user_defined: {
        acc_minamt: 50,
        acc_currbal: 430,
        acc_paydue: date.getFullYear() + '-' + (date.getMonth() + 1) + '-26 12:00:00',
        accnames: [
          5624,
github watson-developer-cloud / text-to-speech-nodejs / app.js View on Github external
const express = require('express');

const app = express();
const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1.js');
const { IamAuthenticator } = require('ibm-watson/auth');

const textToSpeech = new TextToSpeechV1({
  version: '2018-04-05',
  authenticator: new IamAuthenticator({
    apikey: process.env.TEXT_TO_SPEECH_IAM_APIKEY || 'type-key-here',
  }),
  url: process.env.TEXT_TO_SPEECH_URL,
});

// Bootstrap application settings
require('./config/express')(app);

const getFileExtension = (acceptQuery) => {
  const accept = acceptQuery || '';
  switch (accept) {
    case 'audio/ogg;codecs=opus':
    case 'audio/ogg;codecs=vorbis':
      return 'ogg';
    case 'audio/wav':
      return 'wav';
github watson-developer-cloud / discovery-nodejs / app.js View on Github external
const DISCOVERY_ENVIRONMENT_ID = 'system';
const DISCOVERY_COLLECTION_ID = 'news';

const DiscoveryV1 = require('ibm-watson/discovery/v1');
const { IamAuthenticator } = require('ibm-watson/auth');

// Create the service wrapper
const discovery = new DiscoveryV1({
  version: '2019-02-28',
  authenticator: new IamAuthenticator({
    apikey: process.env.DISCOVERY_IAM_APIKEY,
  }),
  url: process.env.DISCOVERY_URL,
});

// Bootstrap application settings
const express = require('express');
const path = require('path');
const queryBuilder = require('./src/query-builder');

const app = express();
require('./config/express')(app);

function getWidgetQuery(request) {
  const { widgetQueries } = request.query;
github watson-developer-cloud / assistant-demo / index.js View on Github external
const express = require('express');

const app = express();
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_URL,
});

const date = new Date();
date.setMonth(date.getMonth() + 1);
const initContext = {
  skills: {
    'main skill': {
      user_defined: {
        acc_minamt: 50,
        acc_currbal: 430,
        acc_paydue: `${date.getFullYear()}-${date.getMonth() + 1}-26 12:00:00`,
        accnames: [5624, 5893, 9225],
      },
github hubtype / botonic / packages / botonic-plugin-watson / src / index.js View on Github external
async pre({ input, session, lastRoutePath }) {
    let intent = null
    let confidence = 0
    let intents = []
    let entities = []

    try {
      let assistant = new AssistantV1({
        authenticator: new IamAuthenticator({ apikey: this.options.apiKey }),
        url: this.options.url,
        version: '2018-09-19'
      })

      let res = await assistant.message({
        input: { text: input.data },
        workspaceId: this.options.workspaceId
      })
      intent = res.result.intents[0].intent
      confidence = res.result.intents[0].intent.confidence
      intents = res.result.intents
      entities = res.result.entities
    } catch (error) {
      console.log(error)
    }
    Object.assign(input, { intent, confidence, intents, entities })
github watson-developer-cloud / personality-insights-nodejs / helpers / personality-insights.js View on Github external
*
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

const PersonalityInsightsV3 = require('ibm-watson/personality-insights/v3');
const { IamAuthenticator } = require('ibm-watson/auth');

const personalityInsights = new PersonalityInsightsV3({
  version: '2019-10-13',
  authenticator: new IamAuthenticator({
    apikey: process.env.PERSONALITY_INSIGHTS_IAM_APIKEY,
  }),
  url: process.env.PERSONALITY_INSIGHTS_URL,
});

console.log(process.env.PERSONALITY_INSIGHTS_IAM_APIKEY);
console.log(process.env.PERSONALITY_INSIGHTS_URL);

const parentId = function(tweet) {
  if (tweet.in_reply_to_screen_name != null) {
    return tweet.in_reply_to_user_id;
  } else if (tweet.retweeted && (tweet.current_user_retweet != null)) {
    return tweet.current_user_retweet.id_str;
  }
};