Skip to content

Commit

Permalink
Merge pull request #1 from vkopitsa/feature/add-support-account
Browse files Browse the repository at this point in the history
[accounts]: add support
  • Loading branch information
vkopitsa authored Jul 16, 2022
2 parents 1b77fda + 2d4a77e commit d6bb567
Show file tree
Hide file tree
Showing 19 changed files with 777 additions and 569 deletions.
3 changes: 3 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ MONO_TOKENS=
TELEGRAM_ADMINS=
TELEGRAM_CHATS=

# More info https://github.com/rs/zerolog#leveled-logging
LOG_LEVEL=info

# Project vars
PREFIX_IMAGE=monopersonalbot_img_
PREFIX_CONTAINER=monopersonalbot_
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: Create Release

env:
RELNAME: mono_personal_tgbot
GOARCH: amd64

jobs:
build:
name: Create Release
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18.x

- uses: actions/checkout@v3

- uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.OS }}-go-${{ env.cache-name }}-
${{ runner.OS }}-go-
${{ runner.OS }}-
- name: Build artifacts
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} go build -ldflags "-s -w" -o ./release/${RELNAME}-linux-${GOARCH} *.go
CGO_ENABLED=0 GOOS=darwin GOARCH=${GOARCH} go build -ldflags "-s -w" -o ./release/${RELNAME}-darwin-${GOARCH} *.go
CGO_ENABLED=0 GOOS=windows GOARCH=${GOARCH} go build -ldflags "-s -w" -o ./release/${RELNAME}-windows-${GOARCH}.exe *.go
zip --junk-paths ./release/${RELNAME}-linux-${GOARCH}.zip ./release/${RELNAME}-linux-${GOARCH}
zip --junk-paths ./release/${RELNAME}-darwin-${GOARCH}.zip ./release/${RELNAME}-darwin-${GOARCH}
zip --junk-paths ./release/${RELNAME}-windows-${GOARCH}.zip ./release/${RELNAME}-windows-${GOARCH}.exe
- name: Release
uses: docker://antonyurchenko/git-release:latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ALLOW_EMPTY_CHANGELOG: true
DRAFT_RELEASE: true
CHANGELOG_FILE: none
with:
args: release/*.zip
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on: [push, pull_request]

name: Test

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18.x
- uses: actions/checkout@v3

- uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.OS }}-go-${{ env.cache-name }}-
${{ runner.OS }}-go-
${{ runner.OS }}-
- name: Verify dependencies
run: go mod verify

- name: Run Gosec
uses: securego/gosec@master
with:
args: '-exclude=G104 ./...'

- name: Run tests
run: go test -race -vet=off ./...
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# builder
FROM golang:alpine as builder
FROM golang:1.18-alpine as builder

WORKDIR /

Expand Down
22 changes: 7 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# Monobank personal telegram bot
[![GitHub release](https://img.shields.io/github/release/vkopitsa/mono_personal_tgbot.svg)]()
[![Test](https://github.com/vkopitsa/mono_personal_tgbot/actions/workflows/test.yml/badge.svg)](https://github.com/vkopitsa/mono_personal_tgbot/actions/workflows/test.yml)
![Download](https://img.shields.io/github/downloads/vkopitsa/mono_personal_tgbot/total.svg)
[![license](https://img.shields.io/github/license/vkopitsa/mono_personal_tgbot.svg)]()

A simple telegram bot, written in Go with the [telegram-bot-api](https://github.com/go-telegram-bot-api/telegram-bot-api 'telegram-bot-api') library.

### Report
![mono_personal_tgbot](Resources/screenshot0.png)
![mono_personal_tgbot](Resources/screencast.gif)

### WebHook
![mono_personal_tgbot](Resources/screenshot1.png)

### Balance
![mono_personal_tgbot](Resources/screenshot2.png)
![mono_personal_tgbot](Resources/screenshot.png)

## Usage

Expand All @@ -23,14 +19,14 @@ Run `mono_personal_tgbot` execution file in your terminal with following env var
`TELEGRAM_TOKEN` | [How to get telegram bot token](https://core.telegram.org/bots#3-how-do-i-create-a-bot)
`TELEGRAM_ADMINS` | ids of the trusted user, example: `1234567,1234567`
`TELEGRAM_CHATS` | ids of the trusted chats, example: `-1234567,-1234567`
`MONO_TOKENS` | list of the tokens and it is `number`. [How to get monobank token](https://api.monobank.ua/)
`MONO_TOKENS` | [How to get monobank token](https://api.monobank.ua/)

### Telegram commands

Command | Description
------------------------ | -----------------------------------------------------------
`/balance[_n]` | Get `UAH` balance of the default client or first one or by number. example: `/balance`, `/balance_1`
`/report` | Get a report for the period of the default client or first one or by number. example: `/report`, `/report_1`
`/balance` | Get a balance of the clients.
`/report` | Get a report for the period of the clients.
`/get_webhook[_n]` | Get a status about setup webhook of the default client or first one or by number. example: `/get_webhook`, `/get_webhook_1`
`/set_webhook[_n]` | Set webhook url to monobank api of the default client or first one or by number. example: `/set_webhook`, `/set_webhook_1`

Expand All @@ -42,11 +38,7 @@ Rename `.env.dev` file to `.env` and edit.
# docker-compose up -d

## Download
[v0.4 release, Linux](https://github.com/vkopitsa/mono_personal_tgbot/releases/download/v0.4/mono_personal_tgbot-linux-amd64)

[v0.4 release, MacOS](https://github.com/vkopitsa/mono_personal_tgbot/releases/download/v0.4/mono_personal_tgbot-darwin-amd64)

[v0.4 release, Windows](https://github.com/vkopitsa/mono_personal_tgbot/releases/download/v0.4/mono_personal_tgbot-windows-amd64.exe)
[Windows, Linux, MacOS](https://github.com/vkopitsa/mono_personal_tgbot/releases)

## Compatibility
The bot is only available for Windows, Linux, MacOS.
Expand Down
Binary file added Resources/screencast.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Resources/screenshot0.png
Binary file not shown.
Binary file removed Resources/screenshot1.png
Binary file not shown.
Binary file removed Resources/screenshot2.png
Binary file not shown.
24 changes: 19 additions & 5 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@ package main

import (
"os"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/rs/zerolog/pkgerrors"
)

func main() {
bot := New(
os.Getenv("TELEGRAM_TOKEN"),
os.Getenv("TELEGRAM_ADMINS"),
os.Getenv("TELEGRAM_CHATS"),
os.Getenv("MONO_TOKENS"),
)

// default level is info, unless debug flag is present
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if envLogLevel, ok := os.LookupEnv("LOG_LEVEL"); ok {
zerologLevel, err := zerolog.ParseLevel(envLogLevel)
if err == nil {
zerolog.SetGlobalLevel(zerologLevel)
}
}

zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack

// init clients
err := bot.InitMonoClients()
err := bot.InitMonoClients(os.Getenv("MONO_TOKENS"))
if err != nil {
panic(err)
log.Panic().Err(err)
}

go bot.TelegramStart()
go bot.TelegramStart(os.Getenv("TELEGRAM_TOKEN"))
go bot.ProcessingStart()

// run http server
Expand Down
Loading

0 comments on commit d6bb567

Please sign in to comment.