![New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions](https://cdn.sanity.io/images/cgdhsj6q/production/86e6ebdea652d20da070ebbda20134b839972db7-1024x1024.webp?w=800&fit=max&auto=format)
Security News
New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
api-ai-botkit-facebook
Advanced tools
Readme
Utility lib for creating Facebook Messenger bots with Botkit and api.ai. Based off of the api-ai-botkit.
For usage sample code see examples/sample_bot.js
Install library from npm
npm install --save api-ai-botkit-facebook
Import Library
const apiaibotkit = require('api-ai-botkit-facebook');
Create apiai
object using token from http://api.ai website
const apiai = apiaibotkit(apiaiToken);
Use apiai
object in controller.hears
controller.hears('.*', 'message_received', function (bot, message) {
apiai.process(message, bot);
});
Implement different reactions to appropriate actions
apiai
.action('greetings', function (message, resp, bot) {
var responseText = resp.result.fulfillment.speech;
bot.reply(message, responseText);
})
.action('input.unknown', function (message, resp, bot) {
bot.reply(message, "Sorry, I don't understand");
})
.action(null, function(message, resp, bot) {
// handle all actions no not specified with
// other actions (e.g., greetings and input.unknown)
var responseText = resp.result.fulfillment.speech;
bot.reply(message, responseText);
})
;
The functionality can be extended using middleware functions. These functions can plugin to the api.ai running processes at couple useful places and make changes to both the query or response.
The module currently supports middleware insertion in two places:
Query and Response middleware functions are added to the module using an Express-style "use" syntax. Each function receives a set of parameters and a next function which must be called to continue processing the middleware stack.
Query middleware can be used to do things like preprocess the query or options before it gets sent out to api.ai.
apiai.middleware.query.use((query, options, next) => {
// do something...
// options.contexts.resetContexts = true;
next();
});
Response middleware can be used to do things like preprocess the response content. Additional information can be added to the response object for use down the chain.
apiai.middleware.response.use((message, response, bot, next) => {
// do something...
// response.extrainfo = 'bar';
next();
});
Add an apiaiOptions
property to the message
to pass options to api.ai in the query.
controller.hears('contact me', 'message_received', function (bot, message) {
message.apiaiOptions = {
contexts: [
{
"name": "contact",
"lifespan": 4,
"parameters": {
"username": "fred"
}
}
]
};
apiai.process(message, bot);
});
Add an event
property to the message
to call the eventRequest
function. By default, process
calls the textRequest
function.
controller.hears('trigger event', 'message_received', function (bot, message) {
message.event = {
name: 'Event1',
data: {
parameterName: 'parameter_value',
foo: 'bar'
}
};
apiai.process(message, bot);
});
FAQs
Utility lib for creating Facebook Messenger bots with Botkit and api.ai
The npm package api-ai-botkit-facebook receives a total of 0 weekly downloads. As such, api-ai-botkit-facebook popularity was classified as not popular.
We found that api-ai-botkit-facebook demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
Security News
Results from the 2023 State of JavaScript Survey highlight key trends, including Vite's dominance, rising TypeScript adoption, and the enduring popularity of React. Discover more insights on developer preferences and technology usage.
Security News
The US Justice Department has penalized two consulting firms $11.3 million for failing to meet cybersecurity requirements on federally funded projects, emphasizing strict enforcement to protect sensitive government data.