Side Projects: Telegram Food Bot using the Zomato API

19 Oct 2019 | 4 minute read.

In work, we use Telegram as a main communication platform and being in a central business district, there are many food places to choose from that will end up in endless discussions on where to go out to eat for lunch outs and dinner catch-ups. When looking at fun APIs to use in a project I stumbled across Zomato’s API, so, as a side project, I decided to make a Telegram bot that narrows restaurant options and stop groups from being indecisive in choosing where to eat.

What is Zomato?

Zomato is a restaurant aggregator and food delivery service startup company founded in India. It is now known today for its Zomato Gold product which allows for discounts and buy-1 take-1 deals in certain restaurants. The company localized into many countries, including here in the Philippines.

What is Telegram and Telegram Bots?

Telegram is a cross-platform instant messaging app similar to WhatsApp and Viber, it is very popular due to its feature of end-to-end encryption in all conversations, customer stickers and chatbots (particularly the Werewolf, Uno and Quizarium chatbots) to name a few. In the industry, we mainly focus on Facebook’s Messenger Platform as a way for us to showcase services and improve a brand’s social presence but in the Telegram environment, anyone can make their own chatbot without creating a Facebook page and having the trouble of applying for a Facebook API Key. Telegram allows for developer creativity, in which developers can have a bot for every occasion and problems they deem they need to solve or another ‘side project’ that will never get pushed to production.

How will the chatbot work?

Looking at the given endpoints of Zomato (check it out here for the full documentation), I planned to make it interactive as possible, here are the available endpoints from the documentation.

Request Endpoint Description
Common
GET /categories Get the list of Categories
GET /cities Get city details
GET /collections Get Zomato collections in a city
GET /cuisines Get the list of all cuisines in a city
GET /establishments Get a list of restaurant types in a city
GET /geocode Get location details based on coordinates
Location
GET /location_details Get Zomato location details
GET /locations Search for Locations
Restaurant
GET /dailymenu Get the daily menu of a restaurant
GET /restaurant Get restaurant details
GET /reviews Get restaurant reviews
GET /search Search for restaurants

In order for an accurate search through the bot, we need to get three crucial points of information from the user first. First, where are they located (/location), next is the type of establishment they want to eat at (/establishments) and lastly the type of cuisine they would like to eat (/cuisines). After that, we search for the relevant restaurants through the search endpoint (/search) and display them to the user.

The chatbot's process flow
The chatbot's process flow

Implementation and Technology Used

For this project, I used Node.js and NPM packages Telebot and zomato.js, a little RegEx knowledge is also useful here. These API wrappers make it easier for us to develop and abstracts the complexity making us focus on the experience of the chatbot and its implementation. I heavily used Telegram’s inlineKeyboard feature which allows for buttons to be pressed by the user which triggers the next part of the flow. Essentially, we call Zomato’s API based on different event handlers in the bot.

For the implementation, I created three different telegram commands as access to the bot’s services.

Command Description
/start Start a conversation with the bot.
/location Tell the bot your location. Usage /location <keyword>.
/search A quick search for a restaurant. Usage /search <keyword>, works best if you have already set a location with the /location command.

The bot’s flow is heavily reliant on the ‘callbackQuery’ event and parsing of that data to store for later usage in a case syntax. The bot does not use a database but instead uses a 2D array to store data unique per chat or conversation using Telegram’s chat_id as a unique identifier. As another kicker, I deployed the chatbot to Heroku in a free dyno, sending an HTTP request to the main URL every five minutes to avoid the chatbot from sleeping.

The chatbot in action

Going through the main flow

About Get started Set location Set establishment Set cuisine Show resto Set resto Show map View Rating View highlights

The quick search takes into consideration the set location through the /location <KEYWORD> command using the bot and immediately going to the quick search may not yield the best results.

For this example, I put BGC Stopover Pavillion as my location so it takes into account that location when I search for a restaurant.

Quick search Quick search select

Possible Improvements

The possible improvements and features that can be added to the bot are as follows:

  1. Having the user control to control to sort via the cost and rating.
  2. Having the user control how many restaurants in the search the bot will display as the results.
  3. Having the user choose what payment method they want and displaying restaurants that only have that payment method.
  4. Have suggested restaurants to try based on the user’s location via the /location_details endpoint.
  5. Have a proper database to store the chat data.
  6. Make the chatbot less reliant on inlineKeyboards but on a ReplyKeyboardMarkup to have a real conversation experience with the bot and to show which user did what if the chatbot is in the group chat.
  7. And other general performance updates (having a database instead of an array to store data).

Conclusion

Telegram is one of the best channels for developers starting out with chatbots. It has a low barrier to entry and its usage can go to very simple to incredibly complex. It can be used for implementing games, implementing services through APIs such as a bot like this, a weather bot and even a bot that just sends jokes, web scraping to even handling payments with its integration with Stripe and other payment methods. It allows developers to have fun and just do that side project that you always wanted to do as a break from the usual jobs. Zomato’s API is just begging to be integrated into other apps, its huge repository of restaurant information across the globe can be used in not only chatbots but in websites and can be integrated with other services as well.

Making this chatbot was fun, doing something for ourselves once in a while that we can use in real life (me and my Management Trainee friends use this chatbot) without any pressure from deadlines is the ultimate goal of any side project. Sometimes we need that as developers, our own creation, a safe programming space, where we can just goof off and do what we want and where we have total control and learn new technologies at the same time.


Share this article:


Related Articles:

Making Earthquake PH: Working with Tweets and Maps

Date: 15 Jan 2020

The recent disaster in Batangas becuase of the Taal Volcano caused a spew of scientific terms and overflow of science...


UAAP Real Time Sentiment Analysis of Fan Tweets

Date: 30 Aug 2019

It is UAAP season once again and this year’s season 82 is hosted by Ateneo it is a good time...


Implementing Dark Mode to Your Jekyll Site

Date: 08 Jul 2019

Jekyll is a static site generator powered by Ruby, that can use both HTML and Markdown for markup and Liquid...