package messages import ( "context" "log/slog" "github.com/go-telegram/bot" "github.com/go-telegram/bot/models" ) var ( log *slog.Logger ) // RegisterMessageReactionHandler // Register a match function for an specific emoji to control reactions from users on messages // quick reaction emojis: // "❤", "🔥", "👍", "👎", "🥰", "👏", "😁" // those are default emojis for telegram client func RegisterMessageReactionHandler(ctx context.Context, llog *slog.Logger, b *bot.Bot){ log = llog heartHandler := matchReaction("❤") fireHandler := matchReaction("🔥") thumbsUpHandler := matchReaction("👍") thumbsDownHandler := matchReaction("👎") loveHandler := matchReaction("🥰") clapHandler := matchReaction("👏") laughtHandler := matchReaction("😁") b.RegisterHandlerMatchFunc( fireHandler, handler) b.RegisterHandlerMatchFunc( heartHandler, handler) b.RegisterHandlerMatchFunc( thumbsUpHandler, handler) b.RegisterHandlerMatchFunc(thumbsDownHandler, handler) b.RegisterHandlerMatchFunc(loveHandler, handler) b.RegisterHandlerMatchFunc(laughtHandler, handler) b.RegisterHandlerMatchFunc(clapHandler, handler) } func matchReaction(emoji string)func(*models.Update)bool{ return func (update *models.Update)bool{ if update.MessageReaction != nil && len(update.MessageReaction.NewReaction) > 0{ switch reaction := update.MessageReaction.NewReaction[0].Type; reaction { case models.ReactionTypeTypeEmoji: log.Info("emoji message reaction encounter", "reactions", update.MessageReaction.NewReaction) if update.MessageReaction.NewReaction[0].ReactionTypeEmoji.Emoji == emoji{ return true } } }else{ log.Info("not the same character") return false } log.Info("not a reaction") return false } } func handler(ctx context.Context, b *bot.Bot, update *models.Update){ log.Info("message from reaction") }