Telegram Bot Documentation

The telegram bot creates the interface that the user will interact with and is also in charge of integrating the different services (as can be seen in the Structure of the application section.

When asked for the most popular torrents of a category, on a specific date, this application will first of all ask the database service to see if we have a record, if yes then we just fetch it and return that to the user. If no record exists then the data is fetched from the Torrent service (only if the requested date it today, if not an error message is displayed to the user), after obtaining this data it is sent over to the database service so that it can be saved. Finally it is displayed to the user.

Required Authentication

The bot module needs to authenticate with the Telegram API by using an API key, which is provided when signing up as Telegram developer.

Bot Functions Documentation

The bot_helper module contains “helper” functions for the telegram bot. Basically these are all the functions that bot uses, but the main bot file bot_main only contains the code for setting up the proper callbacks: when a user inputs a comment via telegram, bot_main will ensure that the proper function from this file get invoked.

bot_helper.get_dates_in_record(limit=15) → List[source]

Here we do a request to the database service and get a list of the dates it has in record.

Parameters:limit – the maximum amount of records we want to fetch
Returns:the list of records that the database service has
bot_helper.get_information_for_category_on_date(category: str, date='today') → str[source]

Get the information we have on a specific date for a specific category. This information is asked to the database service, and if the date is today and no information is found for the specified category then we ask the torrent service for that category information. Once we get it we then proceed to send it to the database service for storage.

This method is what the user calls if he/she wants to know the top torrents for a specifc category for a specific date.

Note that if the user asks for a date which we don’t have in the database then a message saying so is displayed to the user.

Parameters:
  • category – the category we want to get information about
  • date – the date we want to get information about
Returns:

the actual string of information to display to the user. This is either an error message or a message with all the top torrents for a specific category for a specific date.

bot_helper.get_record_of_categories_on_date(dt: str) → List[source]

Here we do a request to the database service and ask, for a specific date, which categories do we have records on

Parameters:dt – the date in YYYY-MM-DD format
Returns:a list of categories for which we have a record for the specified date
bot_helper.get_supported_categories() → List[source]

We do a request to the torrent service to see which categories are supported

Returns:the list of supported categories
bot_helper.join_list_into_message(lst: List[str], joiner='-') → str[source]

Helper function that converts a list into a bulleted list

Parameters:
  • lst – the list of strings that we want to convert into bullets
  • joiner – the character that will be used to denote a bullet
Returns:

A bulleted list