microfeedback-core
Core library for building microfeedback backends.
What is a microfeedback backend?
In short: an easily-deployable HTTP microservice for collecting user feedback about your apps.
Installation
Requires Node>=8.
npm install microfeedback-core --save
Usage
The microfeedback
function is the only public API. It takes a backend function which contains the code to handle user feedback (e.g. post a GitHub issue, send an email) sent from a client.
The second argument, attributes
, is an Object
that describes the backend (e.g. name
, version
, description
).
The first argument to the backend function
contains the input
which will contain--at a minimum--an entry named body
with the feedback content.
If the PERSPECTIVE_API_KEY
environment variable is set, the first
argument will contain a perspective
Object with information
returned from the Perspective API.
If the AKISMET_API_KEY
environment variable is set, input will be
checked with the Akismet API. If spam is detected, an error response
will be returned. If the ALLOW_SPAM
environment variable is set, an
error response will not be returned and the first argument to the
backend will contain an akismet
Object of the form {spam: Boolean}
.
Perspective and Akismet support can be disabled by setting
PERSPECTIVE_ENABLED=false
and AKISMET_ENABLED=false
in the
environment.
The backend function also receives the request (req
) and response (res
) objects.
See the node http docs for more information about these objects.
The microfeedback
function returns a micro request handler.
// index.jsconst createError = ;const microfeedback = ;const sendEmail = ; const EmailBackend = async { const name body = input; const toxicity = perspective ? perspectivetoxicity : null; const email = processenvFEEDBACK_EMAIL; // where to receive feedback const subject = '[microfeedback] Feedback posted' + name ? `by ` : ''; const content = ` posted feedback on your app: Cheers,The microfeedback Robot`; try const result = await ; return status: resultstatus ; catch err throw ; }; moduleexports = ;
The service can then be run with the micro
CLI via npm start
.
npm start
Backends
Development
- Fork and clone this repo.
cd
into the project directory. npm install
- To run tests:
npm test
- To run the example server with auto-reloading:
npm run dev
Debugging in tests with iron-node
Add debugger
statements, then run the following:
npm install -i iron-node
npm run test:debug
License
MIT Licensed.