mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
fix: telegram bot send message to correct user
This commit is contained in:
parent
7caf986d11
commit
f9124aa907
|
@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user