Socket
Socket
Sign inDemoInstall

api-ai-botkit-facebook

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-ai-botkit-facebook - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

124

api-ai-botkit-facebook.js

@@ -1,6 +0,5 @@

/* jshint node: true, devel: true */
/* jshint node: true */
'use strict';
const
Botkit = require('botkit'),
apiai = require('apiai'),

@@ -18,87 +17,84 @@ uuid = require('node-uuid'),

if (typeof obj == 'undefined') {
return false;
return false;
}
if (!obj) {
return false;
return false;
}
return obj != null;
return obj !== null;
}
function createApiAiProcessing(token) {
var worker = {};
var worker = {};
worker.apiaiService = apiai(token, "subscription_key");
worker.sessionIds = {};
worker.apiaiService = apiai(token, "subscription_key");
worker.sessionIds = {};
worker.actionCallbacks = {};
worker.allCallback = [];
worker.actionCallbacks = {};
worker.allCallback = [];
worker.action = function (action, callback) {
if (worker.actionCallbacks[action]) {
worker.actionCallbacks[action].push(callback);
} else {
worker.actionCallbacks[action] = [callback];
}
worker.action = function (action, callback) {
if (worker.actionCallbacks[action]) {
worker.actionCallbacks[action].push(callback);
} else {
worker.actionCallbacks[action] = [callback];
}
return worker;
};
return worker;
};
worker.all = function (callback) {
worker.allCallback.push(callback);
return worker;
};
worker.all = function (callback) {
worker.allCallback.push(callback);
return worker;
};
worker.process = function (message, bot) {
try {
if (message.type == 'user_message') {
var requestText = decoder.decode(message.text);
requestText = requestText.replace("’", "'");
worker.process = function (message, bot) {
try {
if (message.type == 'user_message') {
var requestText = decoder.decode(message.text);
requestText = requestText.replace("’", "'");
var channel = message.channel;
var channel = message.channel;
if (!(channel in worker.sessionIds)) {
worker.sessionIds[channel] = uuid.v1();
}
var request = worker.apiaiService.textRequest(
requestText,
{ sessionId: worker.sessionIds[channel] }
);
if (!(channel in worker.sessionIds)) {
worker.sessionIds[channel] = uuid.v1();
}
var request = worker.apiaiService.textRequest(requestText,
{
sessionId: worker.sessionIds[channel]
});
request.on('response', function (response) {
request.on('response', function (response) {
worker.allCallback.forEach(function (callback) {
callback(message, response, bot);
});
worker.allCallback.forEach(function (callback) {
callback(message, response, bot);
});
if (isDefined(response.result)) {
var action = response.result.action;
// set action to null if action is not defined or used
action = isDefined(action) && worker.actionCallbacks[action] ?
action : null;
if (isDefined(response.result)) {
var action = response.result.action;
if (worker.actionCallbacks[action]) {
worker.actionCallbacks[action].forEach(function (callback) {
callback(message, response, bot);
});
}
}
});
if (isDefined(action)) {
if (worker.actionCallbacks[action]) {
worker.actionCallbacks[action].forEach(function (callback) {
callback(message, response, bot);
});
}
}
}
});
request.on('error', function (error) {
console.error(error);
});
request.on('error', function (error) {
console.error(error);
});
request.end();
}
} catch (err) {
console.error(err);
}
};
request.end();
}
} catch (err) {
console.error(err);
}
};
return worker;
return worker;
}
{
"name": "api-ai-botkit-facebook",
"version": "1.0.1",
"version": "1.0.2",
"description": "Utility lib for creating Facebook Messenger bots with Botkit and api.ai",

@@ -26,3 +26,2 @@ "main": "api-ai-botkit-facebook.js",

"apiai": "^3.0.3",
"botkit": "^0.4.6",
"html-entities": "^1.2.0",

@@ -29,0 +28,0 @@ "node-uuid": "^1.4.7"

@@ -36,9 +36,16 @@ # api-ai-botkit-facebook

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('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);
})
;
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc