Service fetches data from Data endpoints and saves it to DataRepository. Store of this repository have third different implementations: SqlStore, MemStore and MergedStore (which uses both of them). Bot fetches data from store by user request received from Telegram. It also has optional API that makes accessible some metrics to CLI. Prometheus uses this CLI to fetch metrics and show them in Grafana. CLI - Prometheus - Grafana chain is not implemented yet.
To run the project follow the steps below:
git clone osinniy/cryptobot
cd cryptobot
To configure bot create bot.yml
as shown below. Set variables to your own:
secrets:
# Your bot token. How to obtain your token: https://core.telegram.org/bots/features#botfather
botToken: 0000000000:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# CMC api key: https://pro.coinmarketcap.com/account
cmcApiKey: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
It's also recommended setting up a webhook. To proceed go to example config and fill webhook config as shown there. Full list of variables and their default values you can also find here: configs/example/bot.yml.
To run the project, you need to have Docker installed on your machine.
First, move config to configs/release
folder:
mkdir configs/release
mv bot.yml configs/release/bot.yml
Then run the build. If you use webhook, pass your IP as shown below. Certificates will be generated during the build with your IP.
make ip=0.0.0.0 # Or simply make if webhook is disabled
After process is finished, you will have osinniy/cryptobot image. Now you can run the project. Webhook users should also pass port they set in config so docker can expose it:
make run port=8443 # Or simply make run if webhook is disabled
If you don't want to use Docker, you can build the project manually. It requires Go 1.19 installed.
cd build && make
After that you need to run migrations. We use goose for them. In order to install it, use command:
go install github.com/pressly/goose/v3/cmd/goose@latest
It might be necessary to add GOBIN to your PATH:
echo 'export PATH="$PATH:$(go env GOPATH)/bin"' >> ~/.bash_profile
source ~/.bash_profile
And then execute migrations. You must be in root project folder:
goose -dir sql sqlite3 cryptobot.sqlite up
And now you can run the binary:
./cryptobot
To see available options, use ./cryptobot --help
For tests use:
make test
Note that you need to have goose installed and GOBIN added to path to be able to run tests:
go install github.com/pressly/goose/v3/cmd/goose@latest
echo 'export PATH="$PATH:$(go env GOPATH)/bin"' >> ~/.bash_profile
source ~/.bash_profile