How to effectively deliver real-time updates to your customers when you don’t have a mobile app
It is a common case when you want to send relevant real-time updates to your customers. There are many examples of such approach in social apps e.g. incoming messages, friend requests, status changes etc. The most popular solution for this is a mobile app with embedded push-notifications. However the case I am going to tell about is different. During search for rental accommodation in Prague(Czech Republic) I found that receiving information about new listings as soon as they become available gives you a significant competitive advantage as landlords usually don’t cherry-pick tenants and seem to work on a first-come first-served basis. This advantage can become really huge if you hunt for something with a high quality/price ratio.
Unfortunately after some market research I didn’t find a tool that can send me such real time updates. All tools available on the market can at most send you updates once in a while, usually no more than once per day, which was too rare for me.
The task I formulated was ”Create a service for sending real-time updates with relevant real-estate listings to subscribed users”. Being a mobile developer I could of course make a mobile app for that, implement push-notifications there and offer it to users. But I aimed to build something as simple as possible which preferably won’t create an overhead with UI design, stores listings and marketing campaigns. I found that a Telegram-bot is the best solution at this stage. The benefits were clear — as Telegram is already used by many people you don’t need to bother potential users with installing one more app on their phone, your updates are delivered the same way as other telegram messages so no need to reinvent the wheel with your own push-notifications, (almost) no need to think about UI/UX as all interactions going through Telegram interface which is already familiar to users, no store listing/approving/publishing hustle.
Getting the data
First of all you need to make sure you have all relevant data. I wanted to get updates for listings posited on https://www.bezrealitky.cz/ — popular local website used by people who want to rent apartments without using estate agents services. Luckily they provide a convenient GraphQL API which I used to retrieve the data about new listings.
Storing the data
In order to send new listings you need to know which listings are considered new for the particular user those that the user haven’t received before. So you need to implement some persistent storage for your data. Running a Telegram bot already requires you to have a cloud service for handling the bot events. As you already need to deploy the bot service somewhere it becomes natural to deploy storage to the same infrastructure. There are many cloud providers you can use for this task. In my case I set up a MongoDB instance inside a docker container deployed to DigitalOcean droplet as a persistent storage and another docker container deployed on the same machine for handling the bot events. Docker Compose comes very handy to bind these containers together. Another popular solution for the same problem is using AWS EC2 for service deployment and DynamoDB as a storage.
Building Telegram bot
I have used Python for building the bot service. Of course you can always work with Telegram Bot API directly but there are a few libraries that can help you to build your bot faster and simpler. I used aiogram which is a simple and fully asynchronous framework for Telegram Bot API written in Python 3.7 with asyncio and aiohttp. As I used MongoDb for persistence I have also used mongoengine as an ORM solution.
Here is the implementation I came up with:
I skipped handlers for a few steps in user-flow like setting-up different filters but those handlers are similar to select_language and subscribe methods so I assume you got the idea.
Basically this is it! Once you run the bot service new users can start subscribing and getting updates. Publishing a new version is also as simple as deploying a new code and restarting bot service and can be done within 5 minutes.
The end product you can check out here.