How to use node-wit - 10 common examples

To help you get started, we’ve selected a few node-wit 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 BeepBoopHQ / witbot / index.js View on Github external
function Witbot (witToken) {
  var self = this

  const actions = {
    say(sessionId, context, message, cb) {
      cb();
    },
    merge(sessionId, context, entities, message, cb) {
      cb(context);
    },
    error(sessionId, context, error) {
      console.log(error.message);
    },
  };

  self._wit = new Wit(witToken, actions)

  // process text with Wit.ai.
  // 1st argument is the text of the message
  // Remaining arguments will be passed as the first arguments of each registered callback
  self.process = function (text, context) {
    var args = Array.prototype.slice.call(arguments)
    var intents = new Intents()
    var matched = false
    args.shift()
    args.shift()
    self._wit.message(text, context, function (err, res) {
      if (err) return console.error('Wit.ai Error: ', err)

      // only consider the 1st outcome
      if (res.outcomes && res.outcomes.length > 0) {
        var outcome = res.outcomes[0]
github hoodsy / messenger-bot-boilerplate / src / api / index.js View on Github external
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
const isAnOption = (options, text) => options.some(option => option === text)

export const createTextQuickReplies = (options) => options.map(option => new QuickReply({
  title: option,
  content_type: 'text',
  payload: 'empty'
}))

//
// Initialize Wit.ai
// ---
// API Reference: https://wit.ai/docs
//
export const wit = new Wit({
  accessToken: WIT_TOKEN,
  actions: actions,
  logger: new log.Logger(log.INFO)
})

// BOT TESTING MODE
if (TESTING_MODE) {
	console.log('Bot testing mode!')
  dbConnect()
	interactive(wit)
}
github JakobReiter / WitAI-Facebook-Messenger-chatbot-boilerplate / index.js View on Github external
var sessions = {};
const findOrCreateSession = (sessions, fbid, cb) => {

    if (!sessions[fbid]) {
        console.log("New Session for:", fbid);
        sessions[fbid] = {context: {}};
    }

    cb(sessions, fbid);
};

// Wit.ai bot specific code

// Import our bot actions and setting everything up
const actions = require('./wit.actions');
const wit = new Wit(config.WIT_TOKEN, actions);

// Starting our webserver and putting it all together
const app = express();
app.set('port', PORT);
app.listen(app.get('port'));
app.use(bodyParser.json());

// Webhook setup
app.get('/', (req, res) => {
    if (!config.FB_VERIFY_TOKEN) {
        throw new Error('missing FB_VERIFY_TOKEN');
    }
    if (req.query['hub.mode'] === 'subscribe' &&
        req.query['hub.verify_token'] === config.FB_VERIFY_TOKEN) {
        res.send(req.query['hub.challenge']);
    } else {
github Donna-ai / Donna / src / plugins / wit-ai.js View on Github external
var err = new Error('Wit.ai is not setup.'+
                              'Could not find access token.');
            donna.logger.warn(err);
            return cb(err);
        }

        // Get textual form of input
        var data = input.getData();

        // Data Types are unique and each have their own
        // specific object format.
        // In this case, a 'text' data type is a simple
        // object with the field 'text'.
        var text = data.text; // Extract text format from data

        wit.captureTextIntent(accessToken, text, function (err, res) {
            // console.log("Response from Wit for text input: ", res);
            if (err) {
                cb(err)
            } else {
                var outcomes = res.outcomes;
                // Iterate thru all intents in response
                var intents = [];
                for (var i = 0, len=outcomes.length; i
github hoodsy / messenger-bot-boilerplate / src / api / index.js View on Github external
export const createTextQuickReplies = (options) => options.map(option => new QuickReply({
  title: option,
  content_type: 'text',
  payload: 'empty'
}))

//
// Initialize Wit.ai
// ---
// API Reference: https://wit.ai/docs
//
export const wit = new Wit({
  accessToken: WIT_TOKEN,
  actions: actions,
  logger: new log.Logger(log.INFO)
})

// BOT TESTING MODE
if (TESTING_MODE) {
	console.log('Bot testing mode!')
  dbConnect()
	interactive(wit)
}
github hoodsy / messenger-bot-boilerplate / src / api / index.js View on Github external
//
// Initialize Wit.ai
// ---
// API Reference: https://wit.ai/docs
//
export const wit = new Wit({
  accessToken: WIT_TOKEN,
  actions: actions,
  logger: new log.Logger(log.INFO)
})

// BOT TESTING MODE
if (TESTING_MODE) {
	console.log('Bot testing mode!')
  dbConnect()
	interactive(wit)
}
github willianjusten / eve / index.js View on Github external
const express = require('express');
const Wit = require('node-wit').Wit;
const settings = require('./settings.js');

// Webserver parameter
const PORT = process.env.PORT || 8445;

// Messenger Helper Functions
const fbMessage = require('./fb-connect.js').fbMessage;
const getFirstMessagingEntry = require('./parser.js').getFirstMessagingEntry;

// Bot Stuff
const findOrCreateSession = require('./sessions.js').findOrCreateSession;
const actions = require('./bot.js').actions;
const sessions = require('./sessions.js').sessions;
const wit = new Wit(settings.WIT_TOKEN, actions);

// Starting our webserver and putting it all together
const app = express();
app.set('port', PORT);
app.listen(app.get('port'));
app.use(bodyParser.json());

// Webhook setup
app.get('/fb', (req, res) => {
  if (!settings.FB_VERIFY_TOKEN) {
    throw new Error('missing FB_VERIFY_TOKEN');
  }

  if (req.query['hub.mode'] === 'subscribe' &&
    req.query['hub.verify_token'] === settings.FB_VERIFY_TOKEN) {
    res.send(req.query['hub.challenge']);
github artnoisenik / facebook-bot / app.js View on Github external
context.temp_max = Math.round(result.main.temp_max * 9/5 - 459.67);
      context.humidity = result.main.humidity;

      cb(context);
    });
  },
};

const apiCall = (location) => {
return axios.get(`http://api.openweathermap.org/data/2.5/weather?q=${location}&appid=${OPEN_WEATHER_TOKEN}`).then((res) => {
  return res.data;
  })
}

// Setting up our bot
const wit = new Wit(WIT_TOKEN, actions);

// Starting our webserver and putting it all together
const app = express();
app.set('port', PORT);
app.listen(app.get('port'));
app.use(bodyParser.json());

// Webhook setup
app.get('/fb', (req, res) => {
  if (!FB_VERIFY_TOKEN) {
    throw new Error('missing FB_VERIFY_TOKEN');
  }
  if (req.query['hub.mode'] === 'subscribe' &&
    req.query['hub.verify_token'] === FB_VERIFY_TOKEN) {
    res.send(req.query['hub.challenge']);
  } else {
github eriklindernoren / HomeAssistant / homeAssistant / routes / index.js View on Github external
return new Promise(function(resolve, reject) {
      var location = firstEntityValue(entities, 'location')
      if (location) {
        context.forecast = 'sunny in ' + location; // we should call a weather API here
        delete context.missingLocation;
      } else {
        context.missingLocation = true;
        delete context.forecast;
      }
      return resolve(context);
    });
  },
};


const client = new Wit({
  accessToken: wit_token,
  actions: actions
});

interactive(client);
github youssef06 / show-around / index.js View on Github external
return;
            })
            .catch(() => {
                context.missingUrl = true;
            })
            .then(() => {
              return context;
            });
    }
};

// Setting up our bot
const wit = new Wit({
    accessToken: config.WIT_TOKEN,
    actions,
    logger: new log.Logger(log.INFO)
});

var app = express();
app.set('port', config.port);
app.use(bodyParser.json({verify: bot.verifyRequestMiddleware()}));

app.get('/', function (req, res) {
    res.status(200).send('Hello world');
});
/*
 * Use your own validation token. Check that the token used in the Webhook
 * setup is the same token used here.
 *
 */
app.get('/webhook', bot.verifyBotMiddleware());

node-wit

Wit.ai Node.js SDK

Unrecognized
Latest version published 2 years ago

Package Health Score

54 / 100
Full package analysis