Skip to content

Commit

Permalink
Telegram bot initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sulzbach committed Apr 30, 2018
1 parent b4db37d commit 20a3135
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
37 changes: 37 additions & 0 deletions alerts/telegram.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package alerts

import (
"log"

"gopkg.in/telegram-bot-api.v4"
)

type TelegramConfig struct {
Enabled bool `json:"enabled"`
Api string `json:"api"`
Chat int64 `json:"chat"`
}

type TelegramBot struct {
config *TelegramConfig
bot *tgbotapi.BotAPI
halt bool
lastFail error
}

func NewTelegramBot(cfg *TelegramConfig) *TelegramBot {
u := &TelegramBot{config: cfg}
u.bot, u.lastFail = tgbotapi.NewBotAPI(cfg.Api)
if u.lastFail != nil {
log.Panic(u.lastFail)
}
u.bot.Debug = true
return u
}

func (u *TelegramBot) SendMessage(text string) bool {
msg := tgbotapi.NewMessage(u.config.Chat, text)
// msg.ReplyToMessageID = 11
u.bot.Send(msg)
return true
}
6 changes: 6 additions & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"coin": "eth",
"name": "main",

"telegram": {
"enabled": false,
"api": "BOT_SECRET_KEY",
"chat": CHAT_ID
},

"proxy": {
"enabled": true,
"listen": "0.0.0.0:8888",
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/yvasiyarov/gorelic"

"github.com/sammy007/open-ethereum-pool/alerts"
"github.com/sammy007/open-ethereum-pool/api"
"github.com/sammy007/open-ethereum-pool/payouts"
"github.com/sammy007/open-ethereum-pool/proxy"
Expand All @@ -21,6 +22,7 @@ import (

var cfg proxy.Config
var backend *storage.RedisClient
var bot *alerts.TelegramBot

func startProxy() {
s := proxy.NewProxy(&cfg, backend)
Expand Down Expand Up @@ -80,6 +82,10 @@ func main() {
log.Printf("Running with %v threads", cfg.Threads)
}

if cfg.Telegram.Enabled {
bot := alerts.NewTelegramBot(&cfg.Telegram)
}

startNewrelic()

backend = storage.NewRedisClient(&cfg.Redis, cfg.Coin)
Expand Down
2 changes: 2 additions & 0 deletions proxy/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package proxy

import (
"github.com/sammy007/open-ethereum-pool/alerts"
"github.com/sammy007/open-ethereum-pool/api"
"github.com/sammy007/open-ethereum-pool/payouts"
"github.com/sammy007/open-ethereum-pool/policy"
Expand All @@ -21,6 +22,7 @@ type Config struct {

BlockUnlocker payouts.UnlockerConfig `json:"unlocker"`
Payouts payouts.PayoutsConfig `json:"payouts"`
Telegram alerts.TelegramConfig `json:"telegram"`

NewrelicName string `json:"newrelicName"`
NewrelicKey string `json:"newrelicKey"`
Expand Down

1 comment on commit 20a3135

@itsmylife44
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If It working ?

Please sign in to comment.