tucnak / telebot

Telebot is a Telegram bot framework in Go.
MIT License
3.77k stars 440 forks source link

Here is some update for processing message reaction events #678

Open AesmaDiv opened 2 months ago

AesmaDiv commented 2 months ago

Adding to file update.go:

...
type Emoji struct {
    Type  string
    Emoji string
}
type MessageReactionUpdated struct {
    Chat         *Chat   //The chat containing the message the user reacted to
    Message_id   int     //Unique identifier of the message inside the chat
    User         *User   //Optional. The user that changed the reaction, if the user isn't anonymous
    Actor_chat   *Chat   //Optional. The chat on behalf of which the reaction was changed, if the user is anonymous
    Date         int     //Date of the change in Unix time
    Old_reaction []Emoji //Array of ReactionType    Previous list of reaction types that were set by the user
    New_reaction []Emoji //Array of ReactionType    New list of reaction types that have been set by the user
}
type Update struct {
    ...
    MessageReaction   *MessageReactionUpdated `json:"message_reaction,omitempty"`
}
func (b *Bot) ProcessUpdate(u Update) {
        ...
        if u.MessageReaction != nil {
        b.handle(OnReaction, c)
        return
    }
}
...

Adding to file telebot.go

const (
    ...
    OnReaction     = "\areaction"
)

Im my main.go i use:

pref := tele.Settings{
    Token: token,
    Poller: &tb.LongPoller{
        Timeout: 1 * time.Second,
        AllowedUpdates: []string{
            "message",
            "edited_message",
            "inline_query",
            "callback_query",
            "message_reaction",
        },
    },
}
bot, err := tele.NewBot(pref)
bot.Handle(OnReaction, func(c Context) {
        ...
})