Giter VIP home page Giter VIP logo

moskommunalbot's Introduction

MosKommunalBot

A telegram bot calculating communal expenses for hot, cold water, for water disposing, and for electricity in Moscow.

Requirements

  • JDK17 - OpenJDK HotSpot, for example.
  • Postgres database - See src/main/sql/create-tables.sql script to create mandatory tables. Put connection URL in dburl system property.
  • Token taken from BotFather bot. Put the token into token system property.

Scenario

  • User selects "new calculation"
  • bot: enter cold water last meter readings
  • user: enters
  • bot: enter hot water current meter readings
  • user: enters
  • bit: repeats the same questions for hot water and electricity
  • bot: parses the pages from links below, finds prices, for current date and calculates payment amounts.
  • bot: send a message to user in following format:
Cold water:
- the price sets from 01.07.2020
- amount to pay: 3456 RUB (123L × 123 RUB/L)
Hot water:
- the price sets from 01.08.2020
- amount to pay: 3456 RUB (123L × 123 RUB/L)
Water disposal:
- the price sets from 01.09.2020
- amount to pay: 3456 RUB (345L × 123 RUB/L)
Electricity:
- the price sets from 01.10.2020
- amount to pay: 3456 RUB (123KW × 123 RUB/KW)

The prices are from

Where the bot lives?

It hosts on https://heroku.com and available here https://t.me/moskommunalbot

moskommunalbot's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar va1m avatar

Watchers

 avatar  avatar

moskommunalbot's Issues

Integrate with database

To store interaction contexts and settings.
Use the tables:

  • IC
  • USER_SETTINGS

Read connection settings from system environment variable DATABASE_URL.

Use native jdbc connections without ORM and without a connection pool.

Bot skeleton

Make the project run as a telegram bot. Prepare it to register it in telegram with name and tokens. Pass the data from outside via program arguments.

Implement /setlandlord command

Positive scenario

  1. Stop current interaction process by removing it from the storage
  2. Respond to user with question "Please, enter landlord username to send calculations to, for example @myLandlord".
  3. Read the landlord user name, check if he is being subscribed to the bot, if so, store it in the user settings storage (UserSettingsDao).
  4. Respond to user with a "successful" message.

Negative scenario

  1. Are the same as in Positive scenario
  2. Read the landlord user name, check if he is being subscribed to the bot, if he is not then throw UnknownUserNameException with the message "The user name is not subscribed on me. Please, invite him to subscribe and then I will be able to notify him about your calculations".
  3. Respond to user with the error message.

Configure logger

Add required dependencies and configuration files.
Log files for past days should be archived in zip files or to files with higher compression if possible.
Maximum 30 log files are allowed.

Abort process

Allow user to abort current interaction process and start new one by sending /new command

Save last meter readings and reuse them in next calculation

Goal

  • Save InteractionContext to PostgreSQL database to INTERACTION_CONTEXT table to persist it between the application restarts. A single one for each chat.
  • Use finished latest calculation to "prefill" next one according to the following scenarios:

Positive scenario

  1. User starts a new calculation
  2. Bot reads last meter readings from the table. If it has "current" readings then bot asks user "Do you want to use this readings from last calculation in this new calculation?" Also bot shows two buttons: Yes/No.
  3. User taps Yes button
  4. Bot uses the readings in the calculation and skips requests to enter this data.

Negative scenario

  1. The same as in positive scenario
  2. Bot reads last meter readings from the DB and doesn't find saved data for the chat.
  3. Bot asks for the readings interactively as currently.

Migrate to JDK17

Requires to update pom.xml, Procfile, and /.github/workflows/codeql-analysis.yml files

Cold water price provider

Implement cold water price provider.
Use Moscow open data API (https://apidata.mos.ru/Docs)

Requests example:

POST https://apidata.mos.ru/v1/datasets?api_key=[key]&foreign=true&$filter=DepartmentId eq 181 and substringof('tariffs',Keywords) eq true

["Id"]
POST https://apidata.mos.ru/v1/datasets/61922/rows?api_key=[key]filter=Cells/TariffItem_en eq 'Heating system'

Make the bot interactive

Make it following the scenario:

  • User selects "new calculation"
  • bot: enter cold water last meter readings
  • user: enters
  • bot: enter hot water current meter readings
  • user: enters
  • bit: repeats the same questions for hot water and electricity
  • bot: parses the pages from links below, finds prices,
    for current date and calculates payment amounts.
  • bot: send a message to user in following format:
Cold water:
- the price sets from 01.07.2020
- amount to pay: 3456 RUB (123L × 123 RUB/L)
Hot water:
- the price sets from 01.08.2020
- amount to pay: 3456 RUB (123L × 123 RUB/L)
Water disposal:
- the price sets from 01.09.2020
- amount to pay: 3456 RUB (345L × 123 RUB/L)
Electricity:
- the price sets from 01.10.2020
- amount to pay: 3456 RUB (123KW × 123 RUB/KW)

Implement simple prices providers

  • Price[] ColdWaterPricesProvider()
  • Price[] HotWaterPricesProvider()
  • Price[] ElectricityPricesProvider()

They should return Price[] array with single entry with hardcoded price for current duration

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.