/cryptobot

Sexy telegram bot that helps you to be on the same wavelength with crypto market

Primary LanguageGo

Cryptobot

Coverage

Project Schema

Cryptobot basically consists of three parts: Service, Store and Bot.

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.

Run

To run the project follow the steps below:

1. Clone the project

git clone osinniy/cryptobot
cd cryptobot

2. Configure

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.

3. Build & run

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

Manual build

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

Test

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