/CocktailBot

Bot for searching cocktails by their names, ingredients and tags 🍹

Primary LanguageJavaMIT LicenseMIT

Bot logo

Cocktail Telegram bot

Status Platform License
Link

Bot for searching cocktails by their names, ingredients and tags.


NOTE! Only Russian language is supported.

How bot works

The bot suggest you to choose search method:

  • by name ( e.g ΠΌΠ°Ρ€Π³Π°Ρ€ΠΈΡ‚Π° ):
    Bot will search cocktail by its name ( levenshtein distance is used for fuzzy search )
  • by ingredients ( e.g. Π΄ΠΆΠΈΠ½, содовая):
    Bot will search cocktail by ingredients, separated by comma
  • by tags ( e.g. ΡˆΠΎΡ‚Ρ‹, цитрусовыС):
    Bot will search cocktail by tags, separated by comma

How database works

One-to-many relationship ( cocktail - ingredient, cocktail - tag ).
There are 3 tables:

cocktail

Example:

id name ingredient_names tag_names recipe
1 Π΄Π°ΠΉΠΊΠΈΡ€ΠΈ Π±Π΅Π»Ρ‹ΠΉ Ρ€ΠΎΠΌ,сахарный сироп,Π»Π°ΠΉΠΌΠΎΠ²Ρ‹ΠΉ сок,Π»Π΅Π΄ Π² ΠΊΡƒΠ±ΠΈΠΊΠ°Ρ… ΠΊΡ€Π΅ΠΏΠΊΠΈΠ΅/кислыС/цитрусовыС/Π½Π° Ρ€ΠΎΠΌΠ΅/классика 1. НалСй Π² ΡˆΠ΅ΠΉΠΊΠ΅Ρ€ Π»Π°ΠΉΠΌΠΎΠ²Ρ‹ΠΉ сок 30 ΠΌΠ», сахарный сироп 15 ΠΌΠ» ΠΈ Π±Π΅Π»Ρ‹ΠΉ Ρ€ΠΎΠΌ 60 ΠΌΠ» 2. Наполни ΡˆΠ΅ΠΉΠΊΠ΅Ρ€ ΠΊΡƒΠ±ΠΈΠΊΠ°ΠΌΠΈ льда ΠΈ Π²Π·Π±Π΅ΠΉ 3. ΠŸΠ΅Ρ€Π΅Π»Π΅ΠΉ Ρ‡Π΅Ρ€Π΅Π· стрСйнСр Π² ΠΎΡ…Π»Π°ΠΆΠ΄Π΅Π½Π½ΠΎΠ΅ шампанскоС Π±Π»ΡŽΠ΄Ρ†Π΅

NOTE! See temporary workaround for details.

ingredient

Example:

id name amount unit πŸ”‘ cocktail_id πŸ”‘ cocktail_name
1 Π±Π΅Π»Ρ‹ΠΉ Ρ€ΠΎΠΌ 60 ΠΌΠ» 1 Π΄Π°ΠΉΠΊΠΈΡ€ΠΈ
2 сахарный сироп 15 ΠΌΠ» 1 Π΄Π°ΠΉΠΊΠΈΡ€ΠΈ

tag

Example:

id name πŸ”‘ cocktail_id πŸ”‘ cocktail_name
1 ΠΊΡ€Π΅ΠΏΠΊΠΈΠ΅ 1 Π΄Π°ΠΉΠΊΠΈΡ€ΠΈ
2 классика 1 Π΄Π°ΠΉΠΊΠΈΡ€ΠΈ

Parser

Parser will parse one url, which contains all cocktails. Then all cocktail data will be parsed and saved to database.

Getting Started

Prerequisites

  • Java 11 or higher

Installing

Simple clone this repository :)

Configuring

Database

Configure application.properties
spring.datasource.url - url to your PostgreSQL database
spring.datasource.username - database username
spring.datasource.password - database password

Also, you need to install fuzzystrmatch extension to PostgreSQL database:
simple execute query: CREATE EXTENSION fuzzystrmatch;

Parser

Configure parser.properties
NOTE! Only one site is supported, so there is no need to configure parser manually.
domain - main url
fullCocktailLink - url, which contains all cocktails.

Bot

Configure bot.properties
token - your Telegram bot token
username - your Telegram bot username

Usage

Run program

cd into cloned repo and run program by
mvn spring-boot:run

Update database

There is REST controller with updateCocktailDb mapping for database update.
So you can run curl <ip>:<port>/updateCocktailDb to update db.

Built using

Workarounds

This project is still under development, so there are some temporary workarounds, which should be fixed in the future.

Redundant columns for tags and ingredients

There are columns tag_names and ingredient_names in the cocktail table, while there are separate tables for tags and ingredients.

By this way I am able to search cocktails by substring with multiple ingredients or tags.

Way to fix:
Select cocktail from ingredient table or tag table, that contains all ingredients or tags from user input (use substring search for each element)