mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +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=
|
||||
|
||||
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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user