
Looking for a long time in the direction of the bots theme for Telegram and Facebook, everything did not take the time to look at what these animals are. And most importantly - there was no intelligible idea why such a bot might be needed in real life, given that neither Tg nor Fb Messanger in my life I actively use.
And quite by chance there was an opportunity to immerse a little in this area and solve an applied task quite to myself. For example, buy cat food without leaving the chat)
On a quiet Saturday morning I accidentally stumbled upon a note that
an international (!) Online Olympiad (!!) in the Perl language (!!!) is being held. Despite the surrealism of the event (about which there were no announcements on any specialized resource including Habr), I signed up and got the task at 10.15am on Monday - to develop a bot for one of the instant messengers that interacts with any online store within 48 hours. Deciding that this is a great chance to immerse yourself in the topic, I took up the task.
')
The choice of online store was simple - in
Yulmart I buy even cat food. Yes, and find out the current price for some piece of iron without putting the application on the phone is sometimes necessary.
The assignment was received on Monday morning and nobody canceled the work affairs, so the main part of the development went on in the evening and at night.
First night
The first night was devoted to writing a parser for mobile issuing of an online store and implementing all the necessary operations with a basket and placing an order (pickup, without registration). Yulmart is represented in different cities and to complete the picture it was necessary to realize the choice of the current city and the pick-up point. Since the perverted parsers are my specialty, there were no special difficulties with this. The only ambush was that I had to spend a couple of hours understanding why an error occurred during the final checkout. It turned out that I too quickly demanded a response from the online store and he does not have time to carry out the order on his internal accounting system. The five-second delay solved the problem and by morning the module implementing the API with the Ulmart site was ready.
Pseudo-API can:
- Get a list of directory partitions
- Search by catalog
- Get a list of catalog items or search results
- Receive information about a product with all its characteristics
- Choose a current city (prices, availability and selection of a pickup point depend on it)
- Manage the basket
- Place an order for pickup from the selected item
I did not manage to implement filters in the catalog due to time constraints. But the basic functionality is there and you can try to transfer it to the Telegram bot platform, about which at this point I only knew that it exists)
Spoiler: now you can buy cat food directly from the Telegram

Second night
Now it's time to get acquainted with the bot capabilities of the Telegram API. Since before that time I did not use Telegram, it was an accelerated immersion in the topic)) I will not paint the details - there are enough articles on this topic. I will note only those features that I noticed in the context of solving my problem. As it turned out, creating a more or less convenient interface for the chat bot of an online store is another task ...
- It was a pity to install a web server, an SSL certificate and study the event-based model of time, so a slow but acceptable for the prototype option was chosen with a long pool of bot requests and single-stream (forgive) their processing
- The platform decides for me all the questions regarding user sessions - great. The initial idea with the implementation of the state machine for storing intermediate information between requests was dropped after some time, since it was easier to pass parameters to the interface elements. Ugly, but quickly.
- For some reason I blunted and did not immediately realize that within the framework of processing a single request, you can form several answers. Therefore, the bot is silent after receiving the request, but does not warn what he thinks (everywhere except handling the search)

- The telegram does not know how to arrange the control buttons in the messages optimally. It is necessary to form the grid of buttons yourself, and if there are a lot of them (and it is not clear how many will be), then this is an additional difficulty. In addition, they can be made a limited number (which is correct), but ...
- ... since besides these buttons and textual input of options for interacting with the bot, this does not complicate the implementation of the selection of goods from the list and pagination.

And when I programmed the list, I still did not understand that it was possible to give several answers (see clause 3), otherwise I could have done it differently - under each position of the list there is my own button “more”. Not the fact that it would be better, but suddenly.
- There is a lack of opportunities to form answers with columns. This would greatly simplify the work with long selection lists. For example, selecting the current city in the bot looks like a list of active buttons:

Or a list of products - it would be optimal to display it in three columns, for example: a picture, a name, a “Details” button, but no.
And so, in general, a simple and pleasant API of the platform allowed to create a chat bot for the night that can do everything that was previously implemented in the pseudo-API.
Including cart management:

Choosing a pickup point:

And final order:

By morning, the bot was finished and running on a test server!
Where can I touch itThe bot is called
@ecom_ulmart_bot and still works on a test bench, accepting and processing requests in the long pool mode in one (!!!) stream.
Therefore, if you torture him - have patience))
Since this is more likely a prototype chatbot, then it has much to develop:
- Make multithreaded request processing through WebHooks
- Poshamanit interface
- Make it possible to embed in other chat rooms as an inline bot (if you suddenly need to know if top mining graphics cards are on sale)
- As a development of functionality, you can add a comparison of prices for selected products with offers from other online stores.
And if someone
gets their hands on it, then you can do this by taking the source
from github and registering your bot (another api-token) for this task.
And what about the international competition?
And nothing)
I never received a response to my decision. Recalling about myself a week later I received an answer that “the results will be about to be summed up,” and then silence.
I think the only one who accidentally saw this ad and sent some solution. So, Larry Wall’s comment on my own crooked code I never received))
It was a fun experience and the next target platform is Facebook Messenger. The idea for a new chat bot is already there!