bottender-chatbase
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -0,3 +1,7 @@ | ||
# 0.2.0 / 2017-12-07 | ||
* [new] Support koa middleware | ||
# 0.1.0 / 2017-12-05 | ||
* [new] Support express middleware |
@@ -12,2 +12,6 @@ 'use strict'; | ||
var _setInterceptors = require('./setInterceptors'); | ||
var _setInterceptors2 = _interopRequireDefault(_setInterceptors); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -18,23 +22,10 @@ | ||
const { client } = bot.connector; | ||
const axios = client.axios; | ||
(0, _setInterceptors2.default)(bot, chatbase); | ||
// Add a response interceptor | ||
axios.interceptors.response.use(response => { | ||
const { config } = response; | ||
if (/graph\.facebook\.com.*\/me\/messages/.test(config.url)) { | ||
const { recipient: { id }, message: { text } } = JSON.parse(config.data); | ||
chatbase.newMessage().setAsTypeAgent().setUserId(id).setTimestamp(Date.now().toString()).setMessage(text).send().catch(e => console.error(e)); | ||
} | ||
return response; | ||
}); | ||
return (req, res, next) => { | ||
const { | ||
sender: { id }, | ||
message: { text } | ||
} = req.body.entry[0].messaging[0]; | ||
req.body.entry.forEach(entry => { | ||
const { sender: { id }, message: { text } } = entry.messaging[0]; | ||
chatbase.newMessage().setAsTypeUser().setUserId(id).setTimestamp(Date.now().toString()).setMessage(text).send().catch(e => console.error(e)); | ||
chatbase.newMessage().setAsTypeUser().setUserId(id).setTimestamp(Date.now().toString()).setMessage(text).send().catch(console.error); | ||
}); | ||
@@ -41,0 +32,0 @@ next(); |
{ | ||
"name": "bottender-chatbase", | ||
"version": "0.1.0", | ||
"description": "Middleware for using Chatbase with Bottender.", | ||
"main": "lib/index.js", | ||
"keywords": [ | ||
"bottender", | ||
"chatbase" | ||
], | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=7.6" | ||
}, | ||
"repository": { | ||
@@ -18,6 +9,8 @@ "type": "git", | ||
}, | ||
"version": "0.2.0", | ||
"main": "lib/index.js", | ||
"files": [ | ||
"lib", | ||
"express.js", | ||
"koa.js", | ||
"lib", | ||
"micro.js", | ||
@@ -29,6 +22,7 @@ "restify.js" | ||
"clean": "rimraf lib", | ||
"precommit": "lint-staged", | ||
"lint": "eslint src", | ||
"lint:fix": "npm run lint -- --fix", | ||
"lint:staged": "lint-staged", | ||
"precommit": "lint-staged", | ||
"prepublish": "npm run build", | ||
"test": "npm run lint:fix && npm run testonly", | ||
@@ -38,5 +32,7 @@ "testonly": "jest", | ||
"testonly:watch": "jest --watch", | ||
"preversion": "npm test", | ||
"prepublish": "npm run build" | ||
"preversion": "npm test" | ||
}, | ||
"dependencies": { | ||
"@google/chatbase": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -58,4 +54,12 @@ "babel-cli": "^6.26.0", | ||
"prettier": "^1.8.2", | ||
"prettier-package-json": "^1.4.0", | ||
"rimraf": "^2.6.2" | ||
}, | ||
"keywords": [ | ||
"bottender", | ||
"chatbase" | ||
], | ||
"engines": { | ||
"node": ">=7.6" | ||
}, | ||
"jest": { | ||
@@ -68,2 +72,6 @@ "testEnvironment": "node", | ||
"lint-staged": { | ||
"package.json": [ | ||
"prettier-package-json --write", | ||
"git add" | ||
], | ||
"*.js": [ | ||
@@ -73,6 +81,3 @@ "eslint --fix", | ||
] | ||
}, | ||
"dependencies": { | ||
"@google/chatbase": "^1.0.0" | ||
} | ||
} |
@@ -45,2 +45,21 @@ # Bottender Chatbase | ||
## Server | ||
Supported server: | ||
1. express | ||
2. koa | ||
### [express](https://github.com/expressjs/express) | ||
```js | ||
const chatbaseMiddleware = require('bottender-chatbase/express'); | ||
``` | ||
### [koa](https://github.com/koajs/koa) | ||
```js | ||
const chatbaseMiddleware = require('bottender-chatbase/koa'); | ||
``` | ||
## Contributing | ||
@@ -47,0 +66,0 @@ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
8038
10
59
93
17
1