msg-router
Simple intermediate layer router for data messages in JSON format
Installation
npm install msg-route --save
usage
This module can be used to route any data to their handlers. For more glkbokog understanding, consider the following example of routing telegram bot messages.
Eхample for telegram bot
stc/bot.main.js
const Telegraf = ;const MsgRouter = ; const bot = "your telegram token";const router = ; // connect routersconst routerForHelp = router; const routerForWeather = router; // the error handler must be the last in the handler chain. // The error handler function, unlike a regular handler, takes 3 arguments:// error - an object with information about the error// message - the message, the processing of which led to the generation of // an exception// next - a function whose call will result in the transfer of control // to the next handler (if when calling next (argument) the // argument is not defined then the next handler will be called,// if defined, then the next error handler will be calledrouter; // install a message handler that starts routing via MsgRouterbot // launch the botbot
the router files (src/routers/command.help.js and src/routers/command.weather.js) will be something like this:
const MsgRouter = ;const router = ; // handler argument to / help commandrouter; // Error handlerrouter; // exporting the routermoduleexports = exports = router;
Another, simple, abstracted example
const MsgRouter = ; /*************************************** */const route_aaa = ;const route_bbb = ;const route_ccc = ; /*************************************** */route_aaa; route_aaa; route_aaa; route_aaa; route_aaa; /*************************************** */route_bbb; route_bbb; route_bbb; route_bbb; /*************************************** */route_ccc; route_ccc; route_ccc; /*************************************** */// route_aaa.process({ targetPath: '/aaa', data: 'aaa' });route_aaa;
... documentation in processed
Participation in development
https://github.com/lastuniverse/msg-router/issues
License
MIT