Closed pd5200 closed 5 months ago
update.EditedMessage
sent by Telegram server. While telegram server sent a message, exactly one field will be defined. update.Message / update.EditedMessage, but not both.
You edit original update.Message, but check update.EditedMessage in matchFunc2
but why it can work in func defaultHandler(ctx context.Context, b bot.Bot, update models.Update) { log.Println("🌹 default handler", update.EditedMessage) }
b.RegisterHandlerMatchFunc(handle.MatchfilterFunc(handle.IsPrivate, handle.IsCallbackQuery, handle.IsAuthAdmin), handle.CallbackQueryHandle(rCallback)) //no work
b.RegisterHandlerMatchFunc(handle.MatchfilterFunc(handle.IsPrivate, handle.IsReply, handle.IsAuthAdmin), handle.ReplyHandle(rReply)) //work
b.RegisterHandlerMatchFunc(handle.MatchfilterFunc(handle.IsPrivate, handle.IsNotReply, handle.IsAuthAdmin), handle.NotReplyHandle(rText)) //work
I do it like this.
"github.com/go-telegram-bot-api/telegram-bot-api/v5"
If not using pointers, is it possible? Like this? It will work? var updates tgbotapi.UpdatesChannel = bot.GetUpdatesChan(u)
package main
import ( "context" "fmt" "github.com/go-telegram/bot" "github.com/go-telegram/bot/models" "log" "os" "os/signal" )
// Send any text message to the bot after the bot has been started
func main() { ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel()
}
func matchFunc(update models.Update) bool { if update.Message == nil { return false } //time.Sleep(5 time.Second) fmt.Println("✅✅✅hello matchFunc1") return update.Message.Text == "hello" }
func matchFunc2(update models.Update) bool { fmt.Println("❇️❇️❇️❇️:matchFunc2", update.EditedMessage) if update.EditedMessage == nil { return false } //time.Sleep(5 time.Second) fmt.Println("❇️❇❇️❇hello matchFunc2") return true }
func helloHandler(ctx context.Context, b bot.Bot, update models.Update) { //time.Sleep(1 time.Second) log.Println("🔥hello handler:" + update.Message.Text) } func helloHandler2(ctx context.Context, b bot.Bot, update models.Update) { //time.Sleep(1 time.Second) log.Println("🔥🔥hello update.EditedMessage:", update.EditedMessage) } func defaultHandler(ctx context.Context, b bot.Bot, update models.Update) { log.Println("🌹 default handler", update.EditedMessage) }
/////////// it dont work
When I use this to edit a message that has already been sent, the helloHandler2 never triggers. Moving the code to defaultHandler can correctly print out the message, proving that it works. But why doesn't helloHandler2 work?