Bots in the city of Innopolis
A tale about how to quickly create some useful services for managing the city through bots in Telegram.
Less than 3 months ago, Innopolis officially opened in the Republic of Tatarstan - the first Russian city that appeared in the 21st century.
Its feature is the economy based on high-tech industries and, above all, IT: the key points of attraction to the city are Innopolis University - siliconrus.com/2015/09/innopolis-student/ and the special economic zone of the same name: innopolis.ru/ sez / investoru
The long-term master plan of the city is designed for 155 thousand inhabitants in 15 years, and today about 400 students and a couple of hundred permanent residents live in it.

Like all startups, a startup city begins with several hundred follower residents, to whom the city hall pays special attention. Such a small number has its advantages: for example, all residents of the city, as well as those who make decisions on the development of Innopolis, are at the distance of one “tap” in Telegram. This method of communication was not chosen by chance, but just for efficiency and receiving feedback from city residents without intermediaries.
Today, a common chat in Telegram unites almost all residents and key employees of the city tjournal.ru/p/innopolis-telegram. It started as a flood, but over time it began to be used as the main service: informing, collecting complaints and suggestions from residents, finding fellow travelers, communicating with like-minded people, all this happens through Telegram. At the same time, the matter does not end only in chats: the city-stratap Innopolis requires an agile approach in creating services for its residents. And where there is agile, there is MVP, in other words, the minimum benefit to the end user, which can be created by the service with minimal time for the first release. Telegram bots are best suited to implement MVP.
Concierge Service Bot
Anyone on the planet Earth can call at 4 a.m. (or any time of the day) Innopolis Concierge Service at 8-800-222-22-87 and find out about transportation schedules, job openings in the city, where to buy medicine - about anything. Well, or complain! It is clear that for the most part residents are asking typical questions, and this can be turned into an automated service. And in order for each resident to be aware of all the changes, the service must not only provide information upon request, but also be able to announce relevant information independently.
Project developer Yuri Chernushenko solved this problem:
The best analogy for bots would be chat concierge services.
Knowing the name of the bot, users create a chat with him in their client program. The bot can provide interest in quick access to frequently asked questions, redirect messages to the operator and initiate communication by making announcements.
The advantages of this approach include:
• No need to install additional applications, and business - to develop and maintain them;
• Communication with users can be automated by means of a set of prepared answers, thereby reducing the load on the call center;
• Users will be able to receive information to frequent requests in one click
• Business receives all statistics of user requests;
• The ability to process natural languages (Natural Language Processing), allows you to automate user communication in a free form and predict their behavior.
The first time the idea of automating the concierge service appeared during the Yandex Tolstoy Camp, then we tried to make an analogue of Magic (http://www.getmagicnow.com/) and Luka (https://luka.ai/). At that moment, it seemed that instant messengers would move in a closed way and would not open their APIs for working with them and accessing data, so we looked at the good old SMS messages. There were workarounds and unofficial libraries for the same WhatsApp and Telegram, but it was risky to build your decisions based on this approach. Then, unexpectedly, Messenger Facebook and, then, Telegram opened their APIs and, I think, these platforms will allow you to create many interesting applications.
What the bot can do.
The bot consists of two parts: user and operator.
Users can set text commands, use buttons for quick access to information or ask questions in free form, which are redirected to the operator.
The operator can update the messages hidden behind each button (mainly schedules), and make announcements to users.
This is simple functionality, in part it even exists in Telegram itself (broadcast list, for example), but the ability to work with a large number of users, save this information and provide prepared answers makes the bot option more convenient.
What's next
In the concierge bot project, it’s interesting to add functionality related to geolocation, since knowing the location of the Innopolis resident, you can understand a lot about the context of the situation. Also, when the database of user requests is large enough, you can try to connect NLP engines (http://wit.ai/ or tech.yandex.ru/tomita ) to automate communication with the operator.
Bot hack to increase the group limit
Imagine a city square. And you can go out on it and say something important or just flame it, enthuse the townspeople with a new idea or discuss the burning one. On the one hand, the city with the speed of instant messaging thought is fine, but on the other hand, it also has its own “curse”. The limit of one group in Telegram is 200 people. And those wishing to communicate in the “square” are approaching 400, what should I do? Namely: a gate forwarding messages between groups.
One of CrazyPit developers talks about the project:
As part of the Innopolis University summer school, we decided to work with telegram bots. For three weeks, they made a prototype framework on Scala using Akka to create telegram bots and wrote several useful bots on the framework.
We managed to make APIs that allow us to write bots in “10 lines” and work asynchronously using Akka, as well as the ability to run several bots in one process. We plan to add various strategies for parallelizing the work of bots, more complex functions that make it easier to work with the API and DSL to set the bot's behavior based on sequential questions and answers.
Framework repository: github.com/CrazyPit/botspot
A bot that is already working hard is a bot that unites groups that do not fit the 200-person limit. Although there is information that this limit will be expanded in the fall, we have solved this problem now. The bot listens to 2 or more group chats and forwards all messages from one to another.
Of the complex and useful projects on this framework that we have done is a Broadcasting bot. Firstly, it allows you to bypass the restriction on 100 people in newsletters, secondly, it allows you to create various user groups for newsletters through a convenient interface, and thirdly, it allows you to find all the important information for a person in one chat with the bot. This service can be used to inform inside the university, city or any organization.
Bot "Fellow traveler"
The developer himself is best told about the project - Ilya Shimchik :
The idea was born out of the need to get less spam in Telegram chat. There is a group chat where people find a companion and leave requests to the driver. And this is not the most convenient solution, since periodically the search for travel companions falls into a terrible flame. Therefore, the idea came up to simplify the process of finding fellow travelers and, at the same time, reduce the amount of spam.
The procedure for creating a bot is not complicated: the steps to create are simple and have already been described more than once ; the most correct way is to start from the official website: core.telegram.org/bots .
The Telegram API has two ways to interact with the backend bot: via webhook and through polling. I chose the first option, as it is faster and easier. Then everything is simple: we write backend, create a list of bot commands, do message handlers, create an interface and voila - everything works.
It is worth noting that webhooks only work on the https protocol and a self-signed certificate is not suitable, the Telegram API will not allow you to hang a webhook address with a self-signed certificate. There is a temporary solution for this - use ngrok (link) to test your bot directly from the local computer.
As a result, the first version of the bot is now working. A list of nearby features has already been accumulated that will be added to the bot, such as a notification about the trip, taking into account the remaining free places in the car, adding a comment field to the trip.
I want to develop this idea to a full-fledged service for finding fellow travelers, not only in Innopolis, but also in Kazan. I also plan to teach the bot to understand free speech so that the trip can be created, for example, with the following sentence: “I’m going from my home to my grandmother in a week, there is a place for 3 companions, do not smoke in the car!”
In conclusion, perhaps it’s worth saying a few laudatory words to Telegram: a fast and secure IM service that is easily picked up by the audience and through bots provides affordable tools for this audience to have essential services. Firstly, it allows you to evolutionarily develop the audience and its needs in an understandable direction, based on the confirmed hypotheses of the value of the service. Secondly, the service development process itself does not require a huge number of man-hours.
By introducing bots, this already good service has created an excellent tool for transforming itself from the IM protocol into a flexible platform for services. Moreover, the bot buttons inside the applications allow you to make a simple interactive interface for anything without any extra cost.
Bravo and respect, Paul! I think it would be interesting for the developers in Innopolis, and just the residents of the city, to chat with the creator of Telegram and find out his vision of the future messenger.

PS As for Innopolis, it may be the first city to use the Telegram platform as a unified system for authorizing residents for all the city’s digital services. Moreover, there were already posts on habr about the possibility of authorizing users through Telegram habrahabr.ru/post/264301 (the most interesting about deep linking in the comments).
PPS If you are interested in participating in the creation of these or other services - always in touch with Telegram: telegram.me/ior_um


