⬆️ ⬇️

How I gathered the skeleton of the bot to order a taxi in Telegram

On the day of the launch of the bots in the Telegram, I assembled a bot in 3 hours, which sends the air temperature in response to the user's geolocation. From the same day, I raved about calling a taxi through a Telegram bot, since I had a taxi service API at hand.



My goal is not just to tell how I put together a bot to call a taxi, but to share this process with others, so that the time I spent on the implementation of the algorithm was not spent by the others. As a result of this work, any taxi service, with an API, can set up a template for this bot in 5 minutes. Or the owner of the bot with a large number of users will be able to quickly connect to a taxi service.



Design and implementation



The first thing I did was draw a simple automat on taxi and order status on paper. I wanted to do it simply and quickly in order to understand how many resources would be spent on such a task from scratch. Since I had access to the taxi service API, I had to implement only logic.

')

In my process, I fixed the minimum functionality - an order for now and payment in cash. Functionally, a bot can only get geolocation without recognizing text addresses. I assembled such minimal functionality with design, implementation and testing in 8 hours.







Later, at the stage of receiving the address from the user, I added text recognition via the Yandex Speech API so that you can send the object name or address instead of geolocation. But since the taxi order API that I use works in its specific address retrieval format, this feature is not added to the assembly.



The next step I transferred the described process and logic from the paper to the admin of Corezoid cloud OS and connected the Telegram API to the process. Already at this stage it was possible to test the receipt of messages from the Telegram into the process. The next step I, in the same order, created the process of ordering a taxi.



This is how the automaton describing the state of Telegram bot users looked like in a draft and how it became in Corezoid.







After creating the skeleton of the taxi order process, I created separate processes: sending a message to Telegram, processing geolocation and working with the taxi service API. It took 5 minutes to test and correct errors. Then he proceeded to create a dashboard.



Realtime Dashboard and Analysis



The main element in Corezoid is the Callback function, in terms of Telegram this is called Webhook. This feature allows the process to wait for a user reaction. There can be several reactions in this particular process: sending a geolocation by the user or canceling an order (when idle or with the command / cancel). Further, the system uses the Callback function to monitor the number of user steps in real time. This allows you to visualize the funnel passing through the process of ordering a taxi by customers. By processing each step, you can analyze which process the client has fallen off, and moderate the process.







Since Corezoid automatically collects statistics on each state of the process, you can go in and see detailed statistics on each user state and order.







Dashboard is one of the process optimization tools. If you are going to use this process, then you will no longer need to build anything - dashboards are out of the box. There you will see how many users have connected the bot, how many use, how many do not use. You can notify individual customers about an update or awaken the sleeping.









You can find @utaxibot in Telegram and go to this dashboard . When you enter the / order command in the bot, you will see how the realtime dashboard works.



How to use the template



I untied the bot from the existing taxi service API. So you can copy yourself a folder with a template and connect a local taxi order service through the API. Just enter the key of your Telegram bot on the one hand and the taxi service API on the other.



Step 1 . Login in 2 clicks on Corezoid.com



Step 2 . Copy the folder with the process .







Step 3 . We register our Telegram bot in the @BotFather chat and bind its key to the process in Corezoid.







Step 4 . We connect API taxi service according to the documentation .

Requirements for the taxi taxi API were written based on the API that I used. But Corezoid doesn't care which API you use, you can independently register the mapping of incoming and outgoing data, so you can have any of your own parameters.



I suggest not just using Corezoid as a constructor to create processes, but using a ready-made template process.



And most importantly, Corezoid can work with any frontend that supports webhook / callback mode. So this process will work with other client interaction systems (Slack, Telegram, SiteHeart, SMS, etc.). You can connect at least Twitter Direct Message API, and the same process will work through Twitter.



I plan to gradually modify the functionality of the bot, for example, in the near future I will add: text recognition; optimization of work with desktop clients; order for several addresses and more. But, as an alternative channel, the bot can be used now.



Prequel



I work in PrivatBank and moderate the business logic of Privat24 using Corezoid. I am not a developer and have no idea about the code.



Initially, Corezoid was developed as a system exclusively for solving work issues of the bank - managing escalations. During operation, it was transformed into a system for managing the state of objects and processes, and then it became clear that Corezoid is perfect for being the backend for front-office systems, including for instant messengers.



There aren't many backend platforms. Recently on Habré, I stumbled upon this article , where the guys started a good conversation about designers for Telegram bots. Today I continued this conversation and showed a flexible platform with dashboards out of the box. Enthusiasts will now be able to call themselves a taxi right in the Telegram.



Click here if you want to use my template. Or here , if you want to familiarize yourself with the documentation of Corezoid and figure out how to collect other bots.

Source: https://habr.com/ru/post/263875/



All Articles