Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Npm package is outdated. #17

Open
Magellol opened this issue Oct 11, 2016 · 3 comments
Open

Npm package is outdated. #17

Magellol opened this issue Oct 11, 2016 · 3 comments
Labels

Comments

@Magellol
Copy link

Hey guys, just a headsup about the npm package.
It looks like it's not up to date to the latest release from this repo and thus doesn't work with the current Wit API version.

To make it work, I've downloaded the code from this repo directly and included in my project.

@simpixelated
Copy link

You can also point directly to the github repo:

npm install https://github.com/howdyai/botkit-middleware-witai.git

@peterswimm peterswimm added the bug label Nov 28, 2016
@jason-riddle
Copy link

For others who may be watching this issue, the botkit-witai middleware looks like it's more up to date.

With that library I was able to put the following together which assumes that you have already completed at least up to 4) in https://wit.ai/docs/quickstart. Also, Javascript is not my strong suit, but the code should be clear enough to get the message across.

let config = null;

try {
  config = require('./config.json');
} catch (e) {
  console.log('Unable to load ./config.json')
}

const Botkit = require('botkit');
const wit = require('botkit-witai')({
  accessToken: process.env.WIT_TOKEN || config.WIT_TOKEN,
  minConfidence: 0.4,
  logLevel: 'debug'
});

const controller = Botkit.slackbot({
  debug: false
});

const bot = controller.spawn({
  token: process.env.SLACK_TOKEN || config.SLACK_TOKEN
}).startRTM();

controller.setupWebserver(process.env.PORT || 3001, (err, webserver) => {
  controller.createWebhookEndpoints(webserver, bot);
});

controller.middleware.receive.use(wit.receive);

controller.hears(['weather'], 'direct_message', (bot, message) => {
  bot.botkit.log("Wit.ai detected entities", message.entities);
  bot.botkit.log(`Message: ${prettyJSON(message)}`);
  const intent = firstEntityValue(message.entities, 'intent');
  bot.botkit.log(`Intent: ${intent}`);
  const location = firstEntityValue(message.entities, 'location');
  bot.botkit.log(`Location: ${location}`);
  bot.reply(message, `You want to know more about ${intent} for ${location} correct?`);
});

const firstEntityValue = (entities, entity) => {
  const val = entities && entities[entity] &&
    Array.isArray(entities[entity]) &&
    entities[entity].length > 0 &&
    entities[entity][0].value
  ;
  if (!val) {
    return null;
  }
  return typeof val === 'object' ? val.value : val;
};

function prettyJSON(obj) {
  return JSON.stringify(obj, null, 2);
}

@michaelmior
Copy link
Contributor

botkit-witai is currently broken due to changes on how intents are handled.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants