Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in MessageReactionCount Struct #744

Open
TheFiordi opened this issue Oct 3, 2024 · 0 comments
Open

Error in MessageReactionCount Struct #744

TheFiordi opened this issue Oct 3, 2024 · 0 comments

Comments

@TheFiordi
Copy link

Hello,

While using the library, I encountered the following error:
elebot: json: cannot unmarshal array into Go struct field MessageReactionCount.Result.message_reaction_count.reactions of type telebot.ReactionCount

After investigating, I found that the output of b.Raw("getUpdates", params) in getUpdates() is as follows:

{
  "ok": true,
  "result": [
    {
      "update_id": XXXXX995,
      "message_reaction_count": {
        "chat": {
          "id": XXXXXX,
          "title": "XXXXXXXXXXX",
          "type": "channel"
        },
        "message_id": XXXXX,
        "date": XXXXX,
        "reactions": [
          {
            "type": {
              "type": "emoji",
              "emoji": "❤"
            },
            "total_count": 1
          }
        ]
      }
    }
]
}

As you can see, the reactions field is returned as a list. However, in the library, MessageReactionCount is defined with Reactions as a single ReactionCount, not a slice:

type MessageReactionCount struct {
	// The chat containing the message.
	Chat *Chat `json:"chat"`

	// Unique message identifier inside the chat.
	MessageID int `json:"message_id"`

	// Date of the change in Unix time.
	DateUnixtime int64 `json:"date"`

	// List of reactions that are present on the message.
	Reactions *ReactionCount `json:"reactions"`
}

This mismatch caused the error mentioned above, and the lastUpdateId in Poll() was not incremented, leading to repeated errors and failed updates.

I resolved the issue by modifying the MessageReactionCount struct as follows:

type MessageReactionCount struct {
	// The chat containing the message.
	Chat *Chat `json:"chat"`

	// Unique message identifier inside the chat.
	MessageID int `json:"message_id"`

	// Date of the change in Unix time.
	DateUnixtime int64 `json:"date"`

	// List of reactions that are present on the message.
	Reactions *[]ReactionCount `json:"reactions"` //<- changed to slice
}

With this change, the error is resolved. I suggest updating the MessageReactionCount struct so that Reactions is a slice. If this approach sounds good, I’d be happy to open a PR with the fix.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant