WORK IN PROCESS...
Some info in readme could be outdated
A service-bot with users, variables, and calculation history support to solve equations in text format, to help with calculations in chats. With an open API for interacting with other services and registering via telegram.
- mvthbot MVP
- Equation solving
- Reverse Polish notation conversion
- Variables support
- REST API (using Fiber)
- Middleware (logging, parsing, etc.)
- Auth (using JWT)
- OpenAPI (using swaggo/swag)
- Telegram bot (using tucnak/telebot)
- Broadcasting
- Middleware (logging, parsing etc.)
- Commands set
- error handling (using emperror.dev/emperror)
- logging (using uber.org/zap)
- Database
- PostgreSQL (using github.com/jackc/pgx)
- Migrations (using golang-migrate)
- Configuration (using env variables, spf13/viper and spf13/cobra)
- Graceful shutdown (using sync/errgroup and context)
- Deploy (using Docker and Makefile)
- Equation solving
- mvthbot 1.0
- Proper testing
- Tests refactoring
- Coverage increase
- Load testing
- Readme update
- Swagger docs update
- Proper testing
📦 mvthbot
├─ api/ # OpenApi, etc.
├─ assets/ # Files for github
├─ bin/ # For output binaries
├─ cmd/
│  └─ mvthbot/ # Setups and runs functions
├─ configs/ # Configuration files
├─ db/
│  ├─ migration/ # Migration sql scripts
│  └─ scripts/ # Help sql scripts
├─ deployments/ # Docker files, etc.
├─ docs/ # Some documentation
├─ internal/
│  ├─ app/ # App setup functions for: gracefull shutdown, etc.
│  ├─ auth/ # JWT auth
│  ├─ bot/ # Telegram bot module
│  ├─ converting/ # Converting to Reverse polish notation
│  ├─ fixing/ # Fixing small misspells in equations
│  ├─ lexemes/ # Lexemes for equation parsing
│  ├─ logging/ # zap.Logger setup
│  ├─ misc/ # Helth API handler
│  ├─ solving/ # Base equations solving
│  ├─ user/ # User working logic
│  └─ utils/ # Some helping functions
├─ logs/ # Folder for log files
└─ scripts/ # Some helping bash scripts
©generated by Project Tree Generator
- Golang (version 1.18+)
- Docker (version
unknown) - PostgreSQL (version ~14.5)
- Go migrate
Install the Golang and GO environment
https://golang.org/doc/install
Install Postgresql (if you want to run locally)
Install go migrate
$ curl -L https://github.com/golang-migrate/migrate/releases/download/v4.14.1/migrate.linux-amd64.tar.gz | tar xvz
Clone repository
git clone git@github.com:ChernichenkoStephan/mvthbot.git (go get)
go get . && make build
./scripts/go.test.sh
- Setup environment variables
- Run DB
./scripts/db.start.sh - Setup DB
make createdb && make migrateset - Run with
./scripts/go.run.sh
| Flag | Short | Description |
|---|---|---|
| log | l | log dir path |
| config | c | config file path |
| token | t | bot token |
| port | p | api listen port |
Example in folder
| Name | Description |
|---|---|
| SECRET | Seed for API password generatioEnvironmentn |
| BOT_TOKEN | Token for telegram bot |
| DB_USER | PostgreSQL user name |
| DB_NAME | PostgreSQL database name |
| Type | Path | Variables | Description |
|---|---|---|---|
| POST | api/v1/auth/login/ | none | getting JWT to access |
| POST | api/v1/auth/logout/ | none | dismissing JWT |
User ID defines from JWT cookie
| Type | Path | Variables | Description |
|---|---|---|---|
| POST | api/v1/solve/:equation/ | :equation equation to solve coded in LF | returns result, no variable created |
| POST | api/v1/solve/ | none | returns result of equations in body |
| Type | Path | Variables | Description |
|---|---|---|---|
| POST | api/v1/variables/:name/:equation | :name user variable name to set :equation equation to solve | setting variable to result of equation |
| POST | api/v1/variables | none | Setting user variables to results of equations in body, returns results list |
| GET | api/v1/variables/:name | :name variable name | returns value of user variable |
| GET | api/v1/variables | none | returns values of user variables from body |
| DELETE | api/v1/variables/:name | :name | deleting user variable with name |
| DELETE | api/v1/variables | none | deletes all user variables for user, optional names ion body |
| Type | Path | Variables | Description |
|---|---|---|---|
| GET | api/v1/auth/history | none | getting all history of equations for user |
| DELETE | api/v1/auth/history | none | clearing user history |
[POST] api/v1/auth/login/
{
"username": "default",
"password": "password"
}
[POST] api/v1/auth/logout/
with JWT Cookie
[POST] api/v1/solve/2%2B2/
Empty
[POST] api/v1/solve/
{
"equations": ["2+2", "1+2+a"]
}
[POST] api/v1/variables/a/"2+2"
Empty
[POST] api/v1/variables
{
"statements": [
{
"names": ["a"],
"equation": "2+2"
},
{
"names": ["b"],
"equation": "1+2+a"
},
{
"names": ["c", "d"],
"equation": "b"
},
}
[GET] api/v1/variables/a
Empty
[GET] api/v1/variables
{
"names": ["a", "b"]
}
[DELETE] api/v1/variables/a
Empty
[POST] api/v1/variables
{
"names": ["a", "b"]
}
[DELETE] api/v1/variables
Empty
Optional
{
"names": ["a", "b"]
}
[GET] api/v1/history
Empty
[DELETE] api/v1/history
Empty
-
/sSolve command.Simple solve:
/s 1+2 **Output:** 3Solve with user variables set:
/s a = 2 + 2 **Output:** a = 4 /s a = b = 1+1 **Output:** a = b = 2 /s a = b **Output (b == 3):** a = b = 3Multiple solve:
/s a = 2+2 b = 3 + 3 c = 1 + 1 **Output:** a = 4 b = 6 c = 6 -
/gGet user variable value command;Simple
/g a **Output (a == 4):** 4Multiple
/g a b c **Output (a == 4, b == 2, c == 1):** a = 4 b = 2 c = 1 -
/getallGet all user variables values command;/getall **Output** a = 1 b = 2 c = 3 -
/dDelete user variable command.Simple
/d a **Output variants:** Success Fault <Not found>Multiple
/d a b c **Output variants:** Success Fault <Not found> -
/delallDelete all user variables command.**Output variants:** Success Fault <Not found> -
/histDelete user variable command.Output sample:
**Output:** 1+2 a = 2+2 4-1 a = b = 2+3 -
/clearClears user history and variables**Output variants:** Success Fault <Not found> -
/passwordReturns password for accessing through REST API**Output:** eifjkvncqe;dow -
/genpasswordRevokes or generates password for accessing through REST API**Output:** eifjkvncqe;dow
