You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The goal is to create a simple API to kickstart a chat bot project with very few technical skills, but enough flexibility to create a full featured one.
So the basic idea (inspired by express) is to have:
Adapters: Network application that will make the bridge between the protocol/service and the bot (sending requests to the bot and receiving response/actions)
Middleware: Functions that will be in charge of taking actions (response) from the context (request)
From this we can create a very simple bot framework but it can become messy and not that easy to implement. To abstract the complexity of creating middleware functions, we could add some functions to compose middleware easily. These function can be splitted in 2 categories, filters and actions, but we will add events (which is a filter) category to make it clearer.
Filterstaking only requests that respond to specific conditions
Eventtaking only a certain type of requests
Actionstaking actions when passed filters
So basically using the 3 categories in a function middleware could look like:
So this should have the same behavior than the first middleware function.
Here is a draft of what can be done with the API:
importfatbot,{irc}from'fatbot'// bot and built-in adapterimporttelegramfrom'fatbot-telegram'// third-party adaptervarbot=fatbot()// Create a botbot.add(irc,{// Add an adapterserver: 'freenode',username: 'fatbot',channels: ['#fatbot','#chatbot']})bot.add(telegram,{// Add a second adapterkey: KEYS.TELEGRAM})bot(function(req,res,next){// Add custom middlewarebot.log(`Message of type ${req.type} received`)next()})// Easy middleware creationbot().channel('#fatbot')// Filter to specific thread/channel.on('talk')// Listen to specific event.match(/hello/)// Filter by regex.say('Yo man.')// Action takenbot().on('message').on('private')// Listen to several events.match(/fuck|shit/).ban()// Events/Filters/Actions can be defined by adapterbot().on('connect').self(true)// Filter only bot messages.log('I am connected')bot().on('connect').say('Hello {username}!')// Template tags bound to request objectbot().channel('#fatbot').use(FATBOT_MIDDLEWARE)// Filter middleware usagebot().on('message').match(/hello/).say(req=>`Hello ${req.name}!`)// Function can also be passed.kick().say('Oops. I did it again.')// Chain actions in orderbot.connect()// Launch the bot
The text was updated successfully, but these errors were encountered:
The goal is to create a simple API to kickstart a chat bot project with very few technical skills, but enough flexibility to create a full featured one.
So the basic idea (inspired by express) is to have:
response
) from the context (request
)From this we can create a very simple bot framework but it can become messy and not that easy to implement. To abstract the complexity of creating middleware functions, we could add some functions to compose middleware easily. These function can be splitted in 2 categories, filters and actions, but we will add events (which is a filter) category to make it clearer.
So basically using the 3 categories in a function middleware could look like:
With composing we could do:
And finally what looks the best to me for it's simplicity:
So this should have the same behavior than the first middleware function.
Here is a draft of what can be done with the API:
The text was updated successfully, but these errors were encountered: