From b2d9bd0312ddc1dc80ecff5287f2ce36764fc974 Mon Sep 17 00:00:00 2001 From: David Chang Date: Sat, 5 Dec 2020 14:20:27 +0800 Subject: [PATCH 1/9] feature: add telegram bot notifier --- README.md | 3 + go.mod | 1 + go.sum | 3 + pkg/cmd/run.go | 15 ++++ pkg/notifier/telegramnotifier/telegram.go | 88 +++++++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 pkg/notifier/telegramnotifier/telegram.go diff --git a/README.md b/README.md index df9dbac99..3f78b66f6 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,9 @@ Add your dotenv file: ``` SLACK_TOKEN= +TELEGRAM_BOT_TOKEN= +TELEGRAM_INIT_TOKEN= + BINANCE_API_KEY= BINANCE_API_SECRET= diff --git a/go.mod b/go.mod index 9139ff4d9..60e112549 100644 --- a/go.mod +++ b/go.mod @@ -43,6 +43,7 @@ require ( golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c // indirect golang.org/x/time v0.0.0-20191024005414-555d28b269f0 gonum.org/v1/gonum v0.8.1 + gopkg.in/tucnak/telebot.v2 v2.3.5 gopkg.in/yaml.v2 v2.3.0 // indirect gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c ) diff --git a/go.sum b/go.sum index 5e03dd20f..cfae5b9bb 100644 --- a/go.sum +++ b/go.sum @@ -276,6 +276,7 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= @@ -443,6 +444,8 @@ gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/tucnak/telebot.v2 v2.3.5 h1:TdMJTlG8kvepsvZdy/gPeYEBdwKdwFFjH1AQTua9BOU= +gopkg.in/tucnak/telebot.v2 v2.3.5/go.mod h1:BgaIIx50PSRS9pG59JH+geT82cfvoJU/IaI5TJdN3v8= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index f3dbbc898..330cf518c 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -22,6 +22,7 @@ import ( "github.com/c9s/bbgo/pkg/bbgo" "github.com/c9s/bbgo/pkg/cmd/cmdutil" "github.com/c9s/bbgo/pkg/notifier/slacknotifier" + "github.com/c9s/bbgo/pkg/notifier/telegramnotifier" "github.com/c9s/bbgo/pkg/slack/slacklog" "github.com/c9s/bbgo/pkg/types" ) @@ -121,6 +122,20 @@ func runConfig(basectx context.Context, userConfig *bbgo.Config) error { } } + // for telegram + telegramBotToken := viper.GetString("telegram-bot-token") + telegramInitToken := viper.GetString("telegram-init-token") + if len(telegramBotToken) > 0 && len(telegramInitToken) > 0 { + + log.Infof("adding telegram notifier") + var notifier = telegramnotifier.New(telegramBotToken, telegramInitToken) + + // start telegram bot + go notifier.Bot.Start() + + notification.AddNotifier(notifier) + } + environ.Notifiability = notification if userConfig.Notifications != nil { diff --git a/pkg/notifier/telegramnotifier/telegram.go b/pkg/notifier/telegramnotifier/telegram.go new file mode 100644 index 000000000..1fa8e34bd --- /dev/null +++ b/pkg/notifier/telegramnotifier/telegram.go @@ -0,0 +1,88 @@ +package telegramnotifier + +import ( + "fmt" + "time" + + log "github.com/sirupsen/logrus" + tb "gopkg.in/tucnak/telebot.v2" +) + +type Notifier struct { + Bot *tb.Bot + chatUser *tb.User + channel string +} + +type NotifyOption func(notifier *Notifier) + +// start bot daemon +func New(botToken, initToken string, options ...NotifyOption) *Notifier { + bot, err := tb.NewBot(tb.Settings{ + // You can also set custom API URL. + // If field is empty it equals to "https://api.telegram.org". + // URL: "http://195.129.111.17:8012", + + Token: botToken, + Poller: &tb.LongPoller{Timeout: 10 * time.Second}, + }) + + if err != nil { + panic(err) + } + + chatUser := &tb.User{} + + // init check initToken and then set sender id + bot.Handle("/init", func(m *tb.Message) { + if m.Text == initToken { + bot.Send(m.Sender, "Bot initialized") + chatUser = m.Sender + } else { + bot.Send(m.Sender, "Error: bot intialize failed. Init token not match!") + } + }) + + bot.Handle("/bbgo", func(m *tb.Message) { + if m.Sender == chatUser { + bot.Send(chatUser, "bbgo!") + } else { + log.Warningf("Incorrect user tried to access bot! sender id: %s", m.Sender) + } + }) + + notifier := &Notifier{ + chatUser: chatUser, + Bot: bot, + } + + for _, o := range options { + o(notifier) + } + + return notifier +} + +func (n *Notifier) Notify(format string, args ...interface{}) { + n.NotifyTo(n.channel, format, args...) +} + +func (n *Notifier) NotifyTo(channel, format string, args ...interface{}) { + var telegramArgsOffset = -1 + + var nonTelegramArgs = args + if telegramArgsOffset > -1 { + nonTelegramArgs = args[:telegramArgsOffset] + } + + log.Infof(format, nonTelegramArgs...) + + _, err := n.Bot.Send(n.chatUser, fmt.Sprintf(format, nonTelegramArgs...)) + if err != nil { + log.WithError(err). + WithField("chatUser", n.chatUser). + Errorf("telegram error: %s", err.Error()) + } + + return +} From c72ef2b31c57b324ba26f2df957fa61310e2c5c0 Mon Sep 17 00:00:00 2001 From: David Chang Date: Sat, 5 Dec 2020 14:25:19 +0800 Subject: [PATCH 2/9] fix: add missing root cmd flags --- pkg/cmd/root.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index 96e5906e3..d1b73eef8 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -39,6 +39,9 @@ func init() { RootCmd.PersistentFlags().String("slack-channel", "dev-bbgo", "slack trading channel") RootCmd.PersistentFlags().String("slack-error-channel", "bbgo-error", "slack error channel") + RootCmd.PersistentFlags().String("telegram-bot-token", "", "telegram bot token from bot father") + RootCmd.PersistentFlags().String("telegram-init-token", "", "telegram init token") + RootCmd.PersistentFlags().String("binance-api-key", "", "binance api key") RootCmd.PersistentFlags().String("binance-api-secret", "", "binance api secret") @@ -54,18 +57,18 @@ func Execute() { // setup the config paths for looking up the config file /* - viper.AddConfigPath("config") - viper.AddConfigPath("$HOME/.bbgo") - viper.AddConfigPath("/etc/bbgo") + viper.AddConfigPath("config") + viper.AddConfigPath("$HOME/.bbgo") + viper.AddConfigPath("/etc/bbgo") - // set the config file name and format for loading the config file. - viper.SetConfigName("bbgo") - viper.SetConfigType("yaml") + // set the config file name and format for loading the config file. + viper.SetConfigName("bbgo") + viper.SetConfigType("yaml") - err := viper.ReadInConfig() - if err != nil { - log.WithError(err).Fatal("failed to load config file") - } + err := viper.ReadInConfig() + if err != nil { + log.WithError(err).Fatal("failed to load config file") + } */ // Once the flags are defined, we can bind config keys with flags. From 7caf986d115d6aa4d5e863a0b0d596fbf0c44d0d Mon Sep 17 00:00:00 2001 From: David Chang Date: Sat, 5 Dec 2020 14:28:48 +0800 Subject: [PATCH 3/9] fix: change warning type from user to username --- pkg/notifier/telegramnotifier/telegram.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/notifier/telegramnotifier/telegram.go b/pkg/notifier/telegramnotifier/telegram.go index 1fa8e34bd..cbec6525c 100644 --- a/pkg/notifier/telegramnotifier/telegram.go +++ b/pkg/notifier/telegramnotifier/telegram.go @@ -47,7 +47,7 @@ func New(botToken, initToken string, options ...NotifyOption) *Notifier { if m.Sender == chatUser { bot.Send(chatUser, "bbgo!") } else { - log.Warningf("Incorrect user tried to access bot! sender id: %s", m.Sender) + log.Warningf("Incorrect user tried to access bot! sender id: %s", m.Sender.Username) } }) From f9124aa907c054b2467d832e8301c4565e3537b3 Mon Sep 17 00:00:00 2001 From: David Chang Date: Sun, 6 Dec 2020 12:11:27 +0800 Subject: [PATCH 4/9] fix: telegram bot send message to correct user --- pkg/notifier/telegramnotifier/telegram.go | 25 +++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/pkg/notifier/telegramnotifier/telegram.go b/pkg/notifier/telegramnotifier/telegram.go index cbec6525c..62790a8b0 100644 --- a/pkg/notifier/telegramnotifier/telegram.go +++ b/pkg/notifier/telegramnotifier/telegram.go @@ -33,21 +33,34 @@ func New(botToken, initToken string, options ...NotifyOption) *Notifier { chatUser := &tb.User{} + bot.Handle("/help", func(m *tb.Message) { + helpMsg := ` +help - print help message +init - initialize telegram bot with initToken. ex. /init my-token +hi - print welcome message to authorized user +` + bot.Send(m.Sender, helpMsg) + }) + // init check initToken and then set sender id bot.Handle("/init", func(m *tb.Message) { - if m.Text == initToken { - bot.Send(m.Sender, "Bot initialized") + log.Info("Receive message: ", m) //debug + if m.Payload == initToken { chatUser = m.Sender + bot.Send(m.Sender, "Bot initialized") } else { bot.Send(m.Sender, "Error: bot intialize failed. Init token not match!") } }) - bot.Handle("/bbgo", func(m *tb.Message) { - if m.Sender == chatUser { - bot.Send(chatUser, "bbgo!") + bot.Handle("/hi", func(m *tb.Message) { + if m.Sender.ID == chatUser.ID { + bot.Send(chatUser, + fmt.Sprintf("Welcome! user: %s, ID: %s"), + chatUser.Username, + chatUser.ID) } else { - log.Warningf("Incorrect user tried to access bot! sender id: %s", m.Sender.Username) + log.Warningf("Incorrect user tried to access bot! sender id: %s", m.Sender) } }) From a55cd02e21a7ea6aeb89aecea86c8fd9ec626a3c Mon Sep 17 00:00:00 2001 From: David Chang Date: Sun, 6 Dec 2020 12:34:43 +0800 Subject: [PATCH 5/9] feature: add info command --- pkg/notifier/telegramnotifier/telegram.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/notifier/telegramnotifier/telegram.go b/pkg/notifier/telegramnotifier/telegram.go index 62790a8b0..23058b818 100644 --- a/pkg/notifier/telegramnotifier/telegram.go +++ b/pkg/notifier/telegramnotifier/telegram.go @@ -37,7 +37,7 @@ func New(botToken, initToken string, options ...NotifyOption) *Notifier { helpMsg := ` help - print help message init - initialize telegram bot with initToken. ex. /init my-token -hi - print welcome message to authorized user +info - print information about current chat ` bot.Send(m.Sender, helpMsg) }) @@ -53,12 +53,13 @@ hi - print welcome message to authorized user } }) - bot.Handle("/hi", func(m *tb.Message) { + bot.Handle("/info", func(m *tb.Message) { if m.Sender.ID == chatUser.ID { bot.Send(chatUser, - fmt.Sprintf("Welcome! user: %s, ID: %s"), - chatUser.Username, - chatUser.ID) + fmt.Sprintf("Welcome! your username: %s, user ID: %s", + chatUser.Username, + chatUser.ID, + )) } else { log.Warningf("Incorrect user tried to access bot! sender id: %s", m.Sender) } @@ -81,6 +82,11 @@ func (n *Notifier) Notify(format string, args ...interface{}) { } func (n *Notifier) NotifyTo(channel, format string, args ...interface{}) { + if n.chatUser.ID == 0 { + log.Warningf("Telegram bot not initialized. Skip notification") + return + } + var telegramArgsOffset = -1 var nonTelegramArgs = args From 9e4602cf6620a8413e6e79ffef0560f88bada830 Mon Sep 17 00:00:00 2001 From: David Chang Date: Sun, 6 Dec 2020 13:02:21 +0800 Subject: [PATCH 6/9] fix: allow upadte telegram chat user with bot command --- pkg/notifier/telegramnotifier/telegram.go | 31 ++++++++++++----------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/pkg/notifier/telegramnotifier/telegram.go b/pkg/notifier/telegramnotifier/telegram.go index 23058b818..a4a23e222 100644 --- a/pkg/notifier/telegramnotifier/telegram.go +++ b/pkg/notifier/telegramnotifier/telegram.go @@ -18,6 +18,16 @@ type NotifyOption func(notifier *Notifier) // start bot daemon func New(botToken, initToken string, options ...NotifyOption) *Notifier { + + notifier := &Notifier{ + chatUser: &tb.User{}, + Bot: &tb.Bot{}, + } + + for _, o := range options { + o(notifier) + } + bot, err := tb.NewBot(tb.Settings{ // You can also set custom API URL. // If field is empty it equals to "https://api.telegram.org". @@ -31,8 +41,6 @@ func New(botToken, initToken string, options ...NotifyOption) *Notifier { panic(err) } - chatUser := &tb.User{} - bot.Handle("/help", func(m *tb.Message) { helpMsg := ` help - print help message @@ -46,7 +54,7 @@ info - print information about current chat bot.Handle("/init", func(m *tb.Message) { log.Info("Receive message: ", m) //debug if m.Payload == initToken { - chatUser = m.Sender + notifier.chatUser = m.Sender bot.Send(m.Sender, "Bot initialized") } else { bot.Send(m.Sender, "Error: bot intialize failed. Init token not match!") @@ -54,25 +62,18 @@ info - print information about current chat }) bot.Handle("/info", func(m *tb.Message) { - if m.Sender.ID == chatUser.ID { - bot.Send(chatUser, + if m.Sender.ID == notifier.chatUser.ID { + bot.Send(notifier.chatUser, fmt.Sprintf("Welcome! your username: %s, user ID: %s", - chatUser.Username, - chatUser.ID, + notifier.chatUser.Username, + notifier.chatUser.ID, )) } else { log.Warningf("Incorrect user tried to access bot! sender id: %s", m.Sender) } }) - notifier := &Notifier{ - chatUser: chatUser, - Bot: bot, - } - - for _, o := range options { - o(notifier) - } + notifier.Bot = bot return notifier } From 7b8ddf03b5b099b0a006d1436094cfb6af989604 Mon Sep 17 00:00:00 2001 From: David Chang Date: Sun, 6 Dec 2020 13:26:34 +0800 Subject: [PATCH 7/9] chore: add readme about configure telegram bot --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 3f78b66f6..40e1b9eec 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,21 @@ streambook := types.NewStreamBook(symbol) streambook.BindStream(stream) ``` +## Telegram Integration + +- In telegram: @botFather +- /newbot +- input bot display name. ex. `bbgo_bot` +- input bot username. This should be global unique. ex. `PeqFqJxP_bbgo_bot` +- Botfather return bot token. Keep bot token safe +- Set `TELEGRAM_BOT_TOKEN` in `.env.local` +- Set `TELEGRAM_INIT_TOKEN` in `.env.local`. Generate your own init token. ex. 92463901, or kx2UX@eM +- Run bbgo +- In telegram: search your bot `PeqFqJxP_bbgo_bot` +- /start +- /init 92463901 +- done! your session will route to telegram + ## Support ### By contributing pull requests From 58aadd9f455f8e3695feb3a2acff879b3f97ce6e Mon Sep 17 00:00:00 2001 From: David Chang Date: Sun, 6 Dec 2020 13:47:52 +0800 Subject: [PATCH 8/9] fix: use correct format for log --- pkg/notifier/telegramnotifier/telegram.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/notifier/telegramnotifier/telegram.go b/pkg/notifier/telegramnotifier/telegram.go index a4a23e222..72d656c4a 100644 --- a/pkg/notifier/telegramnotifier/telegram.go +++ b/pkg/notifier/telegramnotifier/telegram.go @@ -64,12 +64,12 @@ info - print information about current chat bot.Handle("/info", func(m *tb.Message) { if m.Sender.ID == notifier.chatUser.ID { bot.Send(notifier.chatUser, - fmt.Sprintf("Welcome! your username: %s, user ID: %s", + fmt.Sprintf("Welcome! your username: %s, user ID: %d", notifier.chatUser.Username, notifier.chatUser.ID, )) } else { - log.Warningf("Incorrect user tried to access bot! sender id: %s", m.Sender) + log.Warningf("Incorrect user tried to access bot! sender username: %s id: %d", m.Sender.Username, m.Sender.ID) } }) From 9f92fcf2e4d3e2c751cdcc636fabd7c4d6f0205b Mon Sep 17 00:00:00 2001 From: David Chang Date: Sun, 6 Dec 2020 13:59:47 +0800 Subject: [PATCH 9/9] chore: rename telegram init to telegram auth --- README.md | 6 +++--- pkg/cmd/root.go | 2 +- pkg/cmd/run.go | 6 +++--- pkg/notifier/telegramnotifier/telegram.go | 16 ++++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 40e1b9eec..8b67905b1 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Add your dotenv file: SLACK_TOKEN= TELEGRAM_BOT_TOKEN= -TELEGRAM_INIT_TOKEN= +TELEGRAM_AUTH_TOKEN= BINANCE_API_KEY= BINANCE_API_SECRET= @@ -221,11 +221,11 @@ streambook.BindStream(stream) - input bot username. This should be global unique. ex. `PeqFqJxP_bbgo_bot` - Botfather return bot token. Keep bot token safe - Set `TELEGRAM_BOT_TOKEN` in `.env.local` -- Set `TELEGRAM_INIT_TOKEN` in `.env.local`. Generate your own init token. ex. 92463901, or kx2UX@eM +- Set `TELEGRAM_AUTH_TOKEN` in `.env.local`. Generate your own auth token. ex. 92463901, or kx2UX@eM - Run bbgo - In telegram: search your bot `PeqFqJxP_bbgo_bot` - /start -- /init 92463901 +- /auth 92463901 - done! your session will route to telegram ## Support diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index d1b73eef8..1736f5080 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -40,7 +40,7 @@ func init() { RootCmd.PersistentFlags().String("slack-error-channel", "bbgo-error", "slack error channel") RootCmd.PersistentFlags().String("telegram-bot-token", "", "telegram bot token from bot father") - RootCmd.PersistentFlags().String("telegram-init-token", "", "telegram init token") + RootCmd.PersistentFlags().String("telegram-auth-token", "", "telegram auth token") RootCmd.PersistentFlags().String("binance-api-key", "", "binance api key") RootCmd.PersistentFlags().String("binance-api-secret", "", "binance api secret") diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index 330cf518c..e7e10aae8 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -124,11 +124,11 @@ func runConfig(basectx context.Context, userConfig *bbgo.Config) error { // for telegram telegramBotToken := viper.GetString("telegram-bot-token") - telegramInitToken := viper.GetString("telegram-init-token") - if len(telegramBotToken) > 0 && len(telegramInitToken) > 0 { + telegramAuthToken := viper.GetString("telegram-auth-token") + if len(telegramBotToken) > 0 && len(telegramAuthToken) > 0 { log.Infof("adding telegram notifier") - var notifier = telegramnotifier.New(telegramBotToken, telegramInitToken) + var notifier = telegramnotifier.New(telegramBotToken, telegramAuthToken) // start telegram bot go notifier.Bot.Start() diff --git a/pkg/notifier/telegramnotifier/telegram.go b/pkg/notifier/telegramnotifier/telegram.go index 72d656c4a..2009685bb 100644 --- a/pkg/notifier/telegramnotifier/telegram.go +++ b/pkg/notifier/telegramnotifier/telegram.go @@ -17,7 +17,7 @@ type Notifier struct { type NotifyOption func(notifier *Notifier) // start bot daemon -func New(botToken, initToken string, options ...NotifyOption) *Notifier { +func New(botToken, authToken string, options ...NotifyOption) *Notifier { notifier := &Notifier{ chatUser: &tb.User{}, @@ -44,20 +44,20 @@ func New(botToken, initToken string, options ...NotifyOption) *Notifier { bot.Handle("/help", func(m *tb.Message) { helpMsg := ` help - print help message -init - initialize telegram bot with initToken. ex. /init my-token +auth - authorize current telegram user to access telegram bot with authToken. ex. /auth my-token info - print information about current chat ` bot.Send(m.Sender, helpMsg) }) - // init check initToken and then set sender id - bot.Handle("/init", func(m *tb.Message) { + // auth check authToken and then set sender id + bot.Handle("/auth", func(m *tb.Message) { log.Info("Receive message: ", m) //debug - if m.Payload == initToken { + if m.Payload == authToken { notifier.chatUser = m.Sender - bot.Send(m.Sender, "Bot initialized") + bot.Send(m.Sender, "User authorized") } else { - bot.Send(m.Sender, "Error: bot intialize failed. Init token not match!") + bot.Send(m.Sender, "Error: User authorization failed. Auth token does not match!") } }) @@ -84,7 +84,7 @@ func (n *Notifier) Notify(format string, args ...interface{}) { func (n *Notifier) NotifyTo(channel, format string, args ...interface{}) { if n.chatUser.ID == 0 { - log.Warningf("Telegram bot not initialized. Skip notification") + log.Warningf("Telegram bot has no authenticated user. Skip notification") return }