api-ai-botkit-facebook
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -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); | ||
}) | ||
; | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
51
5754
- Removedbotkit@^0.4.6
- Removed@types/async@2.4.2(transitive)
- Removed@types/body-parser@1.19.5(transitive)
- Removed@types/caseless@0.12.5(transitive)
- Removed@types/clone-deep@4.0.4(transitive)
- Removed@types/connect@3.4.38(transitive)
- Removed@types/express@4.17.21(transitive)
- Removed@types/express-serve-static-core@4.19.6(transitive)
- Removed@types/form-data@2.5.0(transitive)
- Removed@types/http-errors@2.0.4(transitive)
- Removed@types/jsonwebtoken@7.2.8(transitive)
- Removed@types/mime@1.3.5(transitive)
- Removed@types/node@9.6.61(transitive)
- Removed@types/qs@6.9.16(transitive)
- Removed@types/range-parser@1.2.7(transitive)
- Removed@types/request@2.48.12(transitive)
- Removed@types/send@0.17.4(transitive)
- Removed@types/serve-static@1.15.7(transitive)
- Removed@types/sprintf-js@1.1.4(transitive)
- Removed@types/tough-cookie@4.0.5(transitive)
- Removed@types/url-join@0.8.6(transitive)
- Removedaccepts@1.3.8(transitive)
- Removedagent-base@2.1.1(transitive)
- Removedajv@6.12.6(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedarray-back@1.0.4(transitive)
- Removedarray-flatten@1.1.1(transitive)
- Removedasap@2.0.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@0.2.01.0.0(transitive)
- Removedasync@1.2.11.5.22.6.4(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.6.00.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedaxios@0.19.0(transitive)
- Removedback@1.0.2(transitive)
- Removedbase64url@3.0.1(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbl@1.1.2(transitive)
- Removedbody-parser@1.20.3(transitive)
- Removedboom@2.10.1(transitive)
- Removedbotbuilder@3.30.0(transitive)
- Removedbotkit@0.4.10(transitive)
- Removedbotkit-studio-sdk@1.0.9(transitive)
- Removedbuffer-equal-constant-time@1.0.1(transitive)
- Removedbytes@3.1.2(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedcamelcase@3.0.0(transitive)
- Removedcaseless@0.11.00.12.0(transitive)
- Removedchalk@1.1.3(transitive)
- Removedcharenc@0.0.2(transitive)
- Removedchrono-node@1.4.9(transitive)
- Removedcliui@3.2.0(transitive)
- Removedclone@1.0.42.0.0(transitive)
- Removedclone-deep@4.0.1(transitive)
- Removedco@3.1.0(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcommand-line-args@3.0.5(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcontent-disposition@0.5.4(transitive)
- Removedcontent-type@1.0.5(transitive)
- Removedcookie@0.6.0(transitive)
- Removedcookie-signature@1.0.6(transitive)
- Removedcore-util-is@1.0.21.0.3(transitive)
- Removedcrypt@0.0.2(transitive)
- Removedcryptiles@2.0.5(transitive)
- Removedcrypto@0.0.3(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddayjs@1.11.13(transitive)
- Removeddebug@2.6.94.1.1(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddepd@2.0.0(transitive)
- Removeddeprecate@0.1.0(transitive)
- Removeddestroy@1.2.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedecdsa-sig-formatter@1.0.11(transitive)
- Removedee-first@1.1.1(transitive)
- Removedencodeurl@1.0.22.0.0(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedescape-html@1.0.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedetag@1.8.1(transitive)
- Removedexpress@4.21.0(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedfeature-detect-es6@1.5.0(transitive)
- Removedfinalhandler@1.3.1(transitive)
- Removedfind-replace@1.0.3(transitive)
- Removedfind-up@1.1.2(transitive)
- Removedfollow-redirects@1.5.10(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@1.0.12.3.32.5.14.0.0(transitive)
- Removedforwarded@0.2.0(transitive)
- Removedfresh@0.5.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedgenerate-function@2.3.1(transitive)
- Removedgenerate-object-property@1.2.0(transitive)
- Removedget-caller-file@1.0.3(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedgopd@1.0.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@2.0.65.1.5(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhawk@3.1.3(transitive)
- Removedhoek@2.16.3(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedhttp-errors@2.0.0(transitive)
- Removedhttp-signature@1.1.11.2.0(transitive)
- Removedhttps-proxy-agent@1.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedinherits@2.0.4(transitive)
- Removedinvert-kv@1.0.0(transitive)
- Removedipaddr.js@1.9.1(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-buffer@1.1.62.0.5(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-fullwidth-code-point@1.0.0(transitive)
- Removedis-my-ip-valid@1.0.1(transitive)
- Removedis-my-json-valid@2.20.6(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedis-property@1.0.2(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedisarray@1.0.0(transitive)
- Removedisobject@3.0.1(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjfs@0.2.6(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsonpointer@5.0.1(transitive)
- Removedjsonwebtoken@5.4.18.5.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedjwa@1.4.1(transitive)
- Removedjws@3.2.2(transitive)
- Removedkind-of@6.0.3(transitive)
- Removedlcid@1.0.0(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removedlocaltunnel@1.9.2(transitive)
- Removedlodash@4.17.21(transitive)
- Removedlodash.includes@4.3.0(transitive)
- Removedlodash.isboolean@3.0.3(transitive)
- Removedlodash.isinteger@4.0.4(transitive)
- Removedlodash.isnumber@3.0.3(transitive)
- Removedlodash.isplainobject@4.0.6(transitive)
- Removedlodash.isstring@4.0.1(transitive)
- Removedlodash.once@4.1.1(transitive)
- Removedmd5@2.3.0(transitive)
- Removedmedia-typer@0.3.0(transitive)
- Removedmerge-descriptors@1.0.3(transitive)
- Removedmethods@1.1.2(transitive)
- Removedmime@1.6.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedms@0.7.32.0.02.1.3(transitive)
- Removedmustache@2.3.2(transitive)
- Removednegotiator@0.6.3(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedoauth-sign@0.8.20.9.0(transitive)
- Removedobject-inspect@1.13.2(transitive)
- Removedon-finished@2.4.1(transitive)
- Removedopenurl@1.1.1(transitive)
- Removedoptions@0.0.6(transitive)
- Removedos-locale@1.4.0(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedparseurl@1.3.3(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-to-regexp@0.1.10(transitive)
- Removedpath-type@1.1.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedprocess-nextick-args@1.0.7(transitive)
- Removedpromise@7.3.18.3.0(transitive)
- Removedproxy-addr@2.0.7(transitive)
- Removedpsl@1.9.0(transitive)
- Removedpunycode@1.4.12.3.1(transitive)
- Removedq@0.9.7(transitive)
- Removedqs@6.13.06.2.46.5.3(transitive)
- Removedrandombytes@2.0.3(transitive)
- Removedrandomstring@1.3.0(transitive)
- Removedrange-parser@1.2.1(transitive)
- Removedraw-body@2.5.2(transitive)
- Removedread-pkg@1.1.0(transitive)
- Removedread-pkg-up@1.0.1(transitive)
- Removedreadable-stream@2.0.6(transitive)
- Removedrequest@2.74.02.88.2(transitive)
- Removedrequire-directory@2.1.1(transitive)
- Removedrequire-main-filename@1.0.1(transitive)
- Removedresolve@1.22.8(transitive)
- Removedrsa-pem-from-mod-exp@0.8.6(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedscmp@0.0.3(transitive)
- Removedsemver@5.0.35.7.2(transitive)
- Removedsend@0.19.0(transitive)
- Removedserve-static@1.16.2(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedsetprototypeof@1.2.0(transitive)
- Removedshallow-clone@3.0.1(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedsntp@1.0.9(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedsprintf-js@1.1.3(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstatuses@2.0.1(transitive)
- Removedstring-width@1.0.2(transitive)
- Removedstring.prototype.startswith@0.2.0(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedstringstream@0.0.6(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtest-value@2.1.0(transitive)
- Removedtoidentifier@1.0.1(transitive)
- Removedtough-cookie@2.3.42.5.0(transitive)
- Removedtunnel-agent@0.4.30.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removedtwilio@2.11.1(transitive)
- Removedtype-is@1.6.18(transitive)
- Removedtypical@2.6.1(transitive)
- Removedultron@1.0.2(transitive)
- Removedunderscore@1.13.7(transitive)
- Removedunpipe@1.0.0(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedurl-join@1.1.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedutils-merge@1.0.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
- Removedvary@1.1.2(transitive)
- Removedverror@1.10.0(transitive)
- Removedware@1.3.0(transitive)
- Removedwhich-module@1.0.0(transitive)
- Removedwrap-ansi@2.1.0(transitive)
- Removedwrap-fn@0.1.5(transitive)
- Removedws@1.1.5(transitive)
- Removedxtend@4.0.2(transitive)
- Removedy18n@3.2.2(transitive)
- Removedyargs@6.6.0(transitive)
- Removedyargs-parser@4.2.1(transitive)