How to use the node-wit.Wit function in node-wit

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 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 jw84 / messenger-bot-witai-tutorial / services / wit.js View on Github external
var getWit = function () {
	console.log('GRABBING WIT')
	return new Wit(Config.WIT_TOKEN, actions)
}
github hunkim / Wit-Facebook / bot.js View on Github external
const getWit = () => {
  return new Wit(Config.WIT_TOKEN, actions);
};
github ovh-ux / ovh-chatbot / utils / wit.js View on Github external
"use strict";

const { Wit, log } = require("node-wit");
const config = require("../config/config-loader").load();

const client = new Wit({
  accessToken: config.wit.token,
  logger: new log.Logger(log.DEBUG)
});

module.exports = client;

node-wit

Wit.ai Node.js SDK

Unrecognized
Latest version published 2 years ago

Package Health Score

54 / 100
Full package analysis