publiclab / multibot

A general-purpose Node.js bot library for writing interactive bot behaviors on various platforms
GNU General Public License v3.0
1 stars 2 forks source link

Design Pattern idea #2

Open priyansh1161 opened 7 years ago

priyansh1161 commented 7 years ago

Since we are interested in creating an interface to connect to multiple chat rooms, my proposal is to use a middleware based architectural approach ( something like express, koa does ). Now, these middlewares can be platform dependent/independent but they will have specified features e.g NLP, welcome message, reply in 10mins if no human interaction etc.

For now, these middlewares will be divided into two parts

  1. Those who provide an actual communication to a particular chat room
  2. Those who compliment this communication like providing NLP support etc

In my opinion using generators will provide a really great flexibility, we can use async-await as well but generators will provide greater control over the middlewares in general.

priyansh1161 commented 7 years ago

A higher level abstraction will look something like this

const multibot = new Multibot()
multibot.addInterface(IRCclient(config));
multibot.addInterface(Slackbot(slackConfig));
multibot.addParser(NLPparser({'utf-8': true}));
multibot.on('connected', greetings.welcome);  //these events will be triggerd by Interface, parser or any other middleware  
multibot.on('newUser', greetings.helper)