Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
node-wit
is the Node.js SDK for Wit.ai.
In your Node.js project, run:
npm install --save node-wit
Run in your terminal:
node examples/template.js <your_token>
See examples
folder for more examples.
The Wit module provides a Wit class with the following methods:
message
- the Wit message APIconverse
- the low-level Wit converse APIrunActions
- a higher-level method to the Wit converse APIinteractive
- starts an interactive conversation with your botThe Wit constructor takes the following parameters:
token
- the access token of your Wit instanceactions
- the object with your actionslogger
- (optional) the object handling the logging.The actions
object has action names as properties, and action implementations as values.
You need to provide at least an implementation for the special actions say
, merge
and error
.
A minimal actions
object looks like this:
const actions = {
say(sessionId, context, message, cb) {
console.log(message);
cb();
},
merge(sessionId, context, entities, message, cb) {
cb(context);
},
error(sessionId, context, error) {
console.log(error.message);
},
};
A custom action takes the following parameters:
sessionId
- a unique identifier describing the user sessioncontext
- the object representing the session statecb(context)
- a callback function to fire at the end of your action with the updated context.Example:
const Wit = require('node-wit').Wit;
const client = new Wit(token, actions);
The logger
object should implement the methods debug
, log
, warn
and error
.
All methods take a single parameter message
.
For convenience, we provide a Logger
, taking a log level parameter (provided as logLevels
).
The following levels are defined: DEBUG
, LOG
, WARN
, ERROR
.
Example:
const Logger = require('node-wit').Logger;
const levels = require('node-wit').logLevels;
const Wit = require('node-wit').Wit;
const logger = new Logger(levels.DEBUG);
const client = new Wit(token, actions, logger);
The Wit message API.
Takes the following parameters:
message
- the text you want Wit.ai to extract the information fromcontext
- (optional) the object representing the session statecb(error, data)
- a callback function with the JSON responseExample:
const context = {};
client.message('what is the weather in London?', context, (error, data) => {
if (error) {
console.log('Oops! Got an error: ' + error);
} else {
console.log('Yay, got Wit.ai response: ' + JSON.stringify(data));
}
});
A higher-level method to the Wit converse API.
Takes the following parameters:
sessionId
- a unique identifier describing the user sessionmessage
- the text received from the usercontext
- the object representing the session statecb(error, context)
- a callback function with the updated contextmaxSteps
- (optional) the maximum number of actions to execute (defaults to 5)Example:
const session = 'my-user-session-42';
const context0 = {};
client.runActions(session, 'what is the weather in London?', context0, (e, context1) => {
if (e) {
console.log('Oops! Got an error: ' + e);
return;
}
console.log('The session state is now: ' + JSON.stringify(context1));
client.runActions(session, 'and in Brussels?', context1, (e, context2) => {
if (e) {
console.log('Oops! Got an error: ' + e);
return;
}
console.log('The session state is now: ' + JSON.stringify(context2));
});
});
The low-level Wit converse API.
Takes the following parameters:
sessionId
- a unique identifier describing the user sessionmessage
- the text received from the usercontext
- the object representing the session statecb(error, data)
- a callback function with the JSON responseExample:
client.converse('my-user-session-42', 'what is the weather in London?', {}, (error, data) => {
if (error) {
console.log('Oops! Got an error: ' + error);
} else {
console.log('Yay, got Wit.ai response: ' + JSON.stringify(data));
}
});
Starts an interactive conversation with your bot.
Example:
client.interactive();
See the docs for more information.
This quickstart assumes that you have:
npm install body-parser express node-fetch
From here.
./ngrok http 8445
This will provide your_ngrok_domain
(the Forwarding
line).
export WIT_TOKEN=your_access_token
export FB_PAGE_ID=your_page_id
export FB_PAGE_TOKEN=your_page_token
export FB_VERIFY_TOKEN=any_token
node examples/messenger.js
Using your FB_VERIFY_TOKEN
and https://<your_ngrok_domain>/fb
as callback URL.
See the Messenger Platform docs.
v3.3.0
node-fetch
instead of requests
message()
API takes now an optional context as second parameterFAQs
Wit.ai Node.js SDK
The npm package node-wit receives a total of 346 weekly downloads. As such, node-wit popularity was classified as not popular.
We found that node-wit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.