mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
chore: rename telegram init to telegram auth
This commit is contained in:
parent
58aadd9f45
commit
9f92fcf2e4
|
@ -41,7 +41,7 @@ Add your dotenv file:
|
||||||
SLACK_TOKEN=
|
SLACK_TOKEN=
|
||||||
|
|
||||||
TELEGRAM_BOT_TOKEN=
|
TELEGRAM_BOT_TOKEN=
|
||||||
TELEGRAM_INIT_TOKEN=
|
TELEGRAM_AUTH_TOKEN=
|
||||||
|
|
||||||
BINANCE_API_KEY=
|
BINANCE_API_KEY=
|
||||||
BINANCE_API_SECRET=
|
BINANCE_API_SECRET=
|
||||||
|
@ -221,11 +221,11 @@ streambook.BindStream(stream)
|
||||||
- input bot username. This should be global unique. ex. `PeqFqJxP_bbgo_bot`
|
- input bot username. This should be global unique. ex. `PeqFqJxP_bbgo_bot`
|
||||||
- Botfather return bot token. Keep bot token safe
|
- Botfather return bot token. Keep bot token safe
|
||||||
- Set `TELEGRAM_BOT_TOKEN` in `.env.local`
|
- 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
|
- Run bbgo
|
||||||
- In telegram: search your bot `PeqFqJxP_bbgo_bot`
|
- In telegram: search your bot `PeqFqJxP_bbgo_bot`
|
||||||
- /start
|
- /start
|
||||||
- /init 92463901
|
- /auth 92463901
|
||||||
- done! your session will route to telegram
|
- done! your session will route to telegram
|
||||||
|
|
||||||
## Support
|
## Support
|
||||||
|
|
|
@ -40,7 +40,7 @@ func init() {
|
||||||
RootCmd.PersistentFlags().String("slack-error-channel", "bbgo-error", "slack error 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-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-key", "", "binance api key")
|
||||||
RootCmd.PersistentFlags().String("binance-api-secret", "", "binance api secret")
|
RootCmd.PersistentFlags().String("binance-api-secret", "", "binance api secret")
|
||||||
|
|
|
@ -124,11 +124,11 @@ func runConfig(basectx context.Context, userConfig *bbgo.Config) error {
|
||||||
|
|
||||||
// for telegram
|
// for telegram
|
||||||
telegramBotToken := viper.GetString("telegram-bot-token")
|
telegramBotToken := viper.GetString("telegram-bot-token")
|
||||||
telegramInitToken := viper.GetString("telegram-init-token")
|
telegramAuthToken := viper.GetString("telegram-auth-token")
|
||||||
if len(telegramBotToken) > 0 && len(telegramInitToken) > 0 {
|
if len(telegramBotToken) > 0 && len(telegramAuthToken) > 0 {
|
||||||
|
|
||||||
log.Infof("adding telegram notifier")
|
log.Infof("adding telegram notifier")
|
||||||
var notifier = telegramnotifier.New(telegramBotToken, telegramInitToken)
|
var notifier = telegramnotifier.New(telegramBotToken, telegramAuthToken)
|
||||||
|
|
||||||
// start telegram bot
|
// start telegram bot
|
||||||
go notifier.Bot.Start()
|
go notifier.Bot.Start()
|
||||||
|
|
|
@ -17,7 +17,7 @@ type Notifier struct {
|
||||||
type NotifyOption func(notifier *Notifier)
|
type NotifyOption func(notifier *Notifier)
|
||||||
|
|
||||||
// start bot daemon
|
// start bot daemon
|
||||||
func New(botToken, initToken string, options ...NotifyOption) *Notifier {
|
func New(botToken, authToken string, options ...NotifyOption) *Notifier {
|
||||||
|
|
||||||
notifier := &Notifier{
|
notifier := &Notifier{
|
||||||
chatUser: &tb.User{},
|
chatUser: &tb.User{},
|
||||||
|
@ -44,20 +44,20 @@ func New(botToken, initToken string, options ...NotifyOption) *Notifier {
|
||||||
bot.Handle("/help", func(m *tb.Message) {
|
bot.Handle("/help", func(m *tb.Message) {
|
||||||
helpMsg := `
|
helpMsg := `
|
||||||
help - print help message
|
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
|
info - print information about current chat
|
||||||
`
|
`
|
||||||
bot.Send(m.Sender, helpMsg)
|
bot.Send(m.Sender, helpMsg)
|
||||||
})
|
})
|
||||||
|
|
||||||
// init check initToken and then set sender id
|
// auth check authToken and then set sender id
|
||||||
bot.Handle("/init", func(m *tb.Message) {
|
bot.Handle("/auth", func(m *tb.Message) {
|
||||||
log.Info("Receive message: ", m) //debug
|
log.Info("Receive message: ", m) //debug
|
||||||
if m.Payload == initToken {
|
if m.Payload == authToken {
|
||||||
notifier.chatUser = m.Sender
|
notifier.chatUser = m.Sender
|
||||||
bot.Send(m.Sender, "Bot initialized")
|
bot.Send(m.Sender, "User authorized")
|
||||||
} else {
|
} 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{}) {
|
func (n *Notifier) NotifyTo(channel, format string, args ...interface{}) {
|
||||||
if n.chatUser.ID == 0 {
|
if n.chatUser.ID == 0 {
|
||||||
log.Warningf("Telegram bot not initialized. Skip notification")
|
log.Warningf("Telegram bot has no authenticated user. Skip notification")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user