Chat for a website. How does it work?

ImbaChat
6 min readMay 11, 2020

--

This is one of the communication channels over the network along with e-mail and phone calls. This is the basis of all social networks and instant messengers. But not only.

Chat Architecture

All chats work on a similar principle. Let’s take a closer look at the chat architecture using the ImbaChat plugin as an example.

The basis of the chat is the exchange of data between the browser and the server, when sending and receiving messages, through a permanent connection. This connection is provided by WebSocket technology (WebSocket Protocol). WebSocket is especially good for services that need constant data exchange, for example, online games, real-time trading platforms.

Through these protocols, all users connect to the CppComet server comets. It is written in C ++ and is multi-threaded, so it can withstand a large load of several tens of thousands of connections.

CppComet provides an API for sending messages from the chat backend to the frontend via web sockets, i.e. a description of the sending process. In general, an API (Application programming interface) is a set of functions that describe the conditions for the interaction of two programs or two sites.

The chat backend is written in PHP and designed as a plugin for October CMS. This platform provides a convenient admin panel, functions for working with site files and many other additional plugins that may be useful. In addition, October CMS is a fairly flexible and fast system based on Laravel. This does not slow down the code compared to if the code was written without using CMS. October CMS also provides a mechanism for caching to choose from: Redis, Memcached or cache in files.

Chat frontend is written in JavaScript using jQuery. To manage the database using MySQL or MariaDB.

The chat load will be significantly affected by user behaviour, how often they send messages and switch between dialogues. If the user is online, but does nothing, then he only slightly loads the server. When performing active actions, sending messages, requests must be processed by the server and messages are saved in the database.

There is another excellent mechanism built into chat — caching of correspondence in the Indexed Database API. This is a database that can be used inside any browser to store large amounts of data. When switching dialogues, the user receives the result from the local cache of his browser instantly. Then, in the background, a request is sent from the server to check for messages that are not in the cache. This mechanism allows the chat to work even if there is no Internet connection. Correspondence data will simply be retrieved from the cache. And if the user writes a message, it will go to the browser cache and will be transferred to the server in the background when the network resumes.

As a result, thanks to the caching of all messages and dialogues in indexddb, the user almost always receives a response instantly before being processed by his server. And, if it is overloaded, then the message can be sent a little longer. But the chat itself will still work.

If the chat runs on the Cordova application, then the files in the messages (images, audio, etc.) also get into the cache and the application works like a standard messenger.

Chat application

Let’s analyse how you can use chat on the site. For example, take a chat for medical consultation website. User interaction via chat can significantly optimize the operation of this service. If you have a good base of specialists and connect them to the chat, there are a lot of opportunities for effective treatment and counselling:

  • Attracting patients the opportunity to get a consultation here and now in emergency situations or in the absence of the need to be in the doctor’s office
  • Attracting medical professionals with additional income when monetizing online consultations
  • Convenient exchange of medical certificates, documents and patient records using the file sharing function

Creation of focus groups of patients with similar diseases. For example, chat people with diabetes. Specialists can post recommendations, write notes in each of these groups, and patients support each other.

Another example of a successful application is chat on a site with online courses. Distance lessons that are relevant today, it is impossible to conduct without the constant interaction of the student and teacher. It should be noted that the involvement in the educational process through chat is quite good, which can be explained by the active participation and the presence of a social example in the form of other students. Thanks to the built-in chat widget, the user will always have dialogues with his teachers or fellow students at hand.

Create online community

Everyone knows online consultants (chat-bots). Pretty annoying pop-ups “how can I help you” are common. What effect such a chat will have on users — annoyance or a desire to ask, depends on how well the chat is configured. Abandoned chatbots cause the most annoyance when a soulless bot wants to help annoyingly, there is only one desire — to leave the site quickly.

Chat on the site can act not only as an online consultant. Chat is an integral part of any web community. Be it a thematic forum, an educational platform, a fan group. On any site where it is important to bring people together, this is an indispensable thing. Chat is a platform for direct communication between members of the web community. Man is a social being, it is known to all. Even in the full vinaigrette of messages, the user will feel community, unity with all these people on the other side of the screen.

And if you take for example some thematic online community? People came to such a site not just like that, but in order to understand their problems, express an opinion on a topic or share an idea. On such sites, people usually share similar interests. Chat will help to structure the theme of the site in the minds of each individual user. He sees what kind of people on this site actually are, finds a common language with other similar users. This strengthens the social connections on the site. And this at a psychological level makes the user come back again and again. But how not to return? After all, there are so many like-minded people. And here is the main thing — how much the topic of your online community is in demand in principle. Although there are so many people, so many interests. On any topic there are lovers.

Good UX website design + clear structure + high-quality content (this includes exciting and unique articles, if you have a narrowly focused topic, do not skimp and hire a specialist in this field to work as a copywriter) + the ability to create an internal network of acquaintances and contacts. And we will get an online community of like-minded people.

How to embed a plugin on a site so that it benefits? It depends on the type of a website. And if you correctly analyse the approximate behaviour of users in the chat and on the basis of this decide to install it (or not install it), then this will at least give a clearer understanding of the needs of the site’s audience, and at the very least, unite users, improve usability and conversion. Chat is easy to install. There are many free chat plugins with no time limits, including this one. You can use it effectively on almost any site. But the most important thing is to chose your purpose of chat using.

--

--

ImbaChat

We are a web studio specialized in web and software development providing a wide spectrum of services.