Summary:
This is a real-life case study about how I built a Telegram bot with Python for a startup, diving into asynchronous programming and learning a ton along the way. The bot was used as a prototype for validating a startup's hypothesis.
Tools, I leaned on: BigQuery, Heroku, and the patience of my senior software-engineer mentor.
I have a passion for helping startups. Once, I worked with a company, that wanted to build a platform, that used users’ input of zip code to show social, demographic, and economic data about this area. Of course, there must be more interesting data and insights in the future, but this task was pretty interesting for me. After retrieving all the open data, and long hours of cleaning and transforming it, I finally had about 10 datasets that I put in the BigQuery.
The pivotal task was presenting this data to non-technical stakeholders. My solution: a Telegram bot as a functional prototype for the envisioned platform. This interactive bot allowed stakeholders to understand and explore our data, offering a hands-on approach to hypothesis testing.
The realization of this task was not so hard at first sight. First of all, I did some research about connecting the bot with BigQuery and learned how to create SQL queries inside the bot.
At this time I never used asynchronous programming and thought that it was something that was far away from my experience (you know, how it feels when you a junior in any field). And of course, this time I came to the understanding that I can’t build the working system without it.
So I found some examples of the async python bots on Github and started my journey. First of all, I made a simple user input + bot answer combination and when it worked, I started to add the queries in my main function that should run every query and return the information.
It leads me to this long read as an answer to user input of the zip code:
postcode_bot:
Here are what I found for Garden Suburb and 2019:
Total population for 2019 is: 17132;
Predicted male population for 2019 is: 8098;
Predicted female population for 2019 is: 8673;
Predicted number of:
children (0-12): 15.51 %; teens (13-19): 7.24 %; adults (20-39): 26.28 %; mid-age adults (40-59): 27.49 %; seniors (60+): 23.48 %;
The following data is for 2021-2022:
The difference of house price in Barnet from may 2021 to may 2022: 11.4 % ;
Median household income for your postcode: £44394.20;
The number of households with:
1 person : 27.71 %; 2 people : 30.25 %; 3 people : 15.97 %; 4 people : 15.61 %; 5 people : 7.26 %; 6 people : 2.5 %; 7 people : 0.54 %; 8+ people : 0.18 %;
Working households in Barnet:
The number of the working households: 56.59 %;
The number of the mixed (working+workless) households: 31.01 %;
The number of the workless households: 12.4 %;
1 Household includes at least one person aged 16 to 64
The number of people, who lived in:
owned outright residence: 42.4 %; owned with a mortgage or loan residence: 29.43 %; part owned and part rented residence: 0.2 %; social rented from local authority residence: 1.19 %; other social rented residence: 4.13 %; rented from private landlord or agency residence: 19.42 %; private rented as an employer of a household member residence: 0.14 %; private rented as a relative or friend of household member residence: 0.67 %; other private rented residence: 0.24 %; rent free residence: 2.18 %;
Social grade for this area:
Higher and intermidiate managerial, administrative personal: 22 %;
Supervisory or clerical and junior managerial, administrative or professional: 44 %;
Skilled manual workers: 14 %;
Semi and unskilled manual workers, casual or lowest grade workers, pensioners and others who depend on the state for their income: 20 %;
Social grade for this ward:
Higher and intermidiate managerial, administrative personal: 53 %;
Supervisory or clerical and junior managerial, administrative or professional: 30 %;
Skilled manual workers: 7 %;
Semi and unskilled manual workers, casual or lowest grade workers, pensioners and others who depend on the state for their income: 10 %;
Qualification level in the area. Percentage of people with:
Degree level or above: 48 %;
2+ A-levels or equivalent: 13 %;
Apprenticeship: Professional education: 2 %;
5+ GCSEs or equivalent: 7 %;
1-4 GCSEs or equivalent: 5 %;
No academic or professional qualifications: 6 %;
Other Qualification: Vocational / Work-related Qualifications, Foreign Qualifications / Qualifications gained outside the UK: 19 %;
Qualification level in the ward. Percentage of people with:
Degree level or above: 57 %;
2+ A-levels or equivalent: 9 %;
Apprenticeship: Professional education: 1 %;
5+ GCSEs or equivalent: 10 %;
1-4 GCSEs or equivalent: 5 %;
No academic or professional qualifications: 8 %;
Other Qualification: Vocational / Work-related Qualifications, Foreign Qualifications / Qualificationsgained outside the UK: 9 %;
As you can see, it is a wall of text. Useful, but not exactly user-friendly.
That’s when I decided to add some visuals. I had to untangle my code to make it happen and spent five days rewriting everything. Moving from Tableau to generating visuals directly in the bot was tough but super satisfying.
Here’s what the bot looks like now:
Currently the bot is not online, as it was deployed with Heroku and now this company doesn’t have a free plan. I already decided what I’ll use instead of it, but I didn’t redeploy the bot yet.
Looking back, this project was a massive learning curve for me. It pushed me to explore new areas of programming and think about data in a more user-friendly way. The best part? Seeing non-techy people interact with the bot and have those ‘aha’ moments.
In the future, I plan to redeploy the bot, further refining its functionality and exploring new data insights.