-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 111f096
Showing
6 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["es2015", "stage-0"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": [ | ||
"eslint-config-evilai" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Logs and databases # | ||
###################### | ||
*.log | ||
*.sql | ||
*.sqlite | ||
npm-debug* | ||
|
||
# OS generated files # | ||
###################### | ||
.DS_Store? | ||
.DS_Store | ||
Icon? | ||
|
||
# NPM Installed stuff # | ||
####################### | ||
|
||
**/node_modules/ | ||
__ | ||
/.idea/ | ||
.sass-cache | ||
/dump.rdb | ||
**/*.map | ||
*.gypi | ||
|
||
# Crypt files # | ||
####################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
exports.default = function (req, res, next) { | ||
if ((0, _isEmpty2.default)(req.body.entry) || !(0, _isArray2.default)(req.body.entry)) { | ||
throw new Error('Data coming from messenger is corrupted. Please, check for all fields.'); | ||
} | ||
|
||
if (!req.bot) { | ||
throw new Error('Field \'bot\' should be initialized in request object.'); | ||
} | ||
|
||
req.bot.normalized = req.body.entry.reduce(function (acc, entry) { | ||
acc = acc.concat(entry.messaging); | ||
return acc; | ||
}, []); | ||
|
||
next(); | ||
}; | ||
|
||
var _isEmpty = require('lodash/isEmpty'); | ||
|
||
var _isEmpty2 = _interopRequireDefault(_isEmpty); | ||
|
||
var _isArray = require('lodash/isArray'); | ||
|
||
var _isArray2 = _interopRequireDefault(_isArray); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "nbp-normaliser-fb-messenger", | ||
"version": "0.0.1", | ||
"description": "Node.js Bot Platform normaliser for requests from Facebook Messenger", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "babel ./src --preset babel-preset-es2015 --out-dir ./dist", | ||
"build:watch": "babel --watch ./src --preset babel-preset-es2015 --out-dir ./dist", | ||
"prepublish": "npm run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/evilai/nbp-normaliser-fb-messenger.git" | ||
}, | ||
"author": "Maxim Vetrenko <[email protected]> (https://github.com/maxmert)", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/evilai/nbp-normaliser-fb-messenger/issues" | ||
}, | ||
"homepage": "https://github.com/evilai/nbp-normaliser-fb-messenger#readme", | ||
"devDependencies": { | ||
"babel-core": "^6.18.0", | ||
"babel-loader": "^6.2.5", | ||
"babel-polyfill": "^6.16.0", | ||
"babel-preset-es2015": "^6.18.0", | ||
"babel-preset-stage-0": "^6.16.0", | ||
"eslint-config-evilai": "0.0.1" | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.16.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import isEmpty from 'lodash/isEmpty'; | ||
import isArray from 'lodash/isArray'; | ||
|
||
/** | ||
* [ | ||
* { | ||
* sender: { id: '823746283746' }, | ||
* recipient: { id: '98234982347' }, | ||
* timestamp: 1475519849260, | ||
* message: { | ||
* mid: 'mid.239849h238fh98', | ||
* seq: 8, | ||
* text: 'hi' | ||
* } | ||
* } | ||
* ] | ||
*/ | ||
|
||
export default function(req, res, next) { | ||
if (isEmpty(req.body.entry) || !isArray(req.body.entry)) { | ||
throw new Error('Data coming from messenger is corrupted. Please, check for all fields.'); | ||
} | ||
|
||
if (!req.bot) { | ||
throw new Error('Field \'bot\' should be initialized in request object.'); | ||
} | ||
|
||
req.bot.normalized = req.body.entry.reduce((acc, entry) => { | ||
acc = acc.concat(entry.messaging); | ||
return acc; | ||
}, []); | ||
|
||
next(); | ||
} |