N
N
Nikita Melikhov2018-11-06 12:08:07
Python
Nikita Melikhov, 2018-11-06 12:08:07

What is your advice on chatbot architecture?

Hello comrades! :)
Need your advice.
I am making a chat bot, as long as there is only a minimal preparation. Something like:

bot.listen();

bot.on('event', (event) => {
    switch(event.type) {
        case 'type1':
            type1EventHandler(event);
            break;
        // ...
        default:
            defaultEventHandler();
    }
});

Of the main functionality, "moderation" and access control are necessary (MAC, it seems, is called). Perhaps it doesn't really matter in this question, but just in case :)
In general, the task is to receive commands, process and perform actions through the API.
I plan to implement the functionality in the form of plugins. Working with chat (authorization, events, etc.), I think, will also be a plugin, so that you can connect any other protocol / API in the future.
I looked at the github on this topic, but I didn’t find anything concrete - either crookedly done, or overloaded. Or I didn't find the right one :)
In general, I need advice on how to implement all this. What patterns can be applied here? Maybe there is an experience of this or open source products are known where you can draw inspiration =)
UPD: I would also like to divide the whole thing into a host process that will control chat bots that will have their own configs, administrators who can be in different channels.
UPD: I'm a little stuck on the workpiece so far. What is - wrote in the question. For a specific type of event, the corresponding handler is called.
Roughly speaking, on the join event, the onJoin() handler is called , which, for example, writes to the log " {date} User {event.user} joined the channel ".
So far I see two main problems:
1. Event handler.
Now I use switch case to handle events, I want to move the "basic" handler to the class and register my handlers (in plugins) to process the necessary events.
2. Event "message" (message in the chat). Since the bot responds to commands like "bot <command> <object> <parameters>", I think this event should be moved to a separate class, implement something like routing / subscribing to a command call. Also in plugins.
I would also like some kind of scaling and abstraction from API / protocols. There can be several bots, in different channels and networks (IRC, Tg, social networks, and so on). Maybe at first it doesn’t make much sense to ask this question, but we should take this nuance into account in advance.
Probably, for starters, I’ll read Design patterns before going to bed. Maybe some useful thoughts :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sowd, 2018-11-06
@Sowd

You write that you analyzed similar solutions on github, none of the solutions suited you for a number of reasons. Based on your statement, we can conclude that you already have an understanding of how it should work and a representation of the architecture. But at the same time, for some sacred reason, you do not want to write your decision. A reasonable question arises, what exactly do you hope to see in the answers? Ready copypasta?

P
Puma Thailand, 2018-11-06
@opium

Why the hell are there patterns?
Write a monolith

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question