rockneurotiko / ex_gram

Telegram Bot API low level API and framework
182 stars 26 forks source link

Version 0.52.0 breaks Callback Query handlers with MaybeInaccessibleMessage structs #153

Closed dgarciah98 closed 8 months ago

dgarciah98 commented 8 months ago

Right now, after updating to version 0.52.0, I'm having difficulties dealing with callback queries due to MaybeInaccessibleMessage being received as the message in a CallbackQuery model.

In my case, I was using the message from the callback for retrieving a inline keyboard which I use as buttons for a menu, modify its buttons, and sending them back by editing the message from where the callback was made. Right now this is the message object I'm receiving, where none of this fields can be seen. This is taken from the bot context:

callback_query: %ExGram.Model.CallbackQuery{
      id: # redacted,
      from: %ExGram.Model.User{
        # redacted
      },
      message: %ExGram.Model.MaybeInaccessibleMessage{
        type: nil,
        offset: nil,
        length: nil,
        url: nil,
        user: nil,
        language: nil,
        custom_emoji_id: nil
      },
      inline_message_id: nil,
      chat_instance: # redacted,
      data: "close",
      game_short_name: nil
    }
}

Downgrading to version 0.51.1 still behaves like before, though the difference is that instead of receiving a defined struct (as it could be ExGram.Model.Message), the message is just a map, however it still shows all the contents of the message, here is an example of the context in this case:

callback_query: %{
      data: "close",
      id: #redacted,
      message: %{
        date: 1710366809,
        text: # redacted,
        from: %{
          id: # redacted,
          first_name: "",
          is_bot: true,
          username: ""
        },
        reply_markup: %{
          inline_keyboard: [
            # redacted
          ]
        },
        message_id: # redacted,
        has_protected_content: true,
        chat: %{
          # redacted
        }
      },
      from: %{
        # redacted
      },
      chat_instance: # redacted
    },
    shipping_query: nil,
    pre_checkout_query: nil,
    poll: nil,
    poll_answer: nil,
    my_chat_member: nil,
    chat_member: nil,
    chat_join_request: nil,
    chat_boost: nil,
    removed_chat_boost: nil
  }

As I understand from reading the Telegram Bot API docs, MaybeInaccessibleMessage is supposed to be a supertype of both Message and InaccessibleMessage, therefore is there any way that I could convert the message struct into the desired type, or is there any other solution to deal with this?

rockneurotiko commented 8 months ago

Oh, this is definitely because of the PR #135, I'll take a look, sorry for the problems and thanks for reporting it!

rockneurotiko commented 8 months ago

The problem ultimately was that I didn't realize that the API had new generic types, and since there is specific dispatch I had to add some custom logic to decide which subtype it is.

With the PR #154 this is fixed, can you try?

dgarciah98 commented 8 months ago

Yup! Now looks like it works properly and callback queries are behaving like usual, here is what the model looks like now:

callback_query: %ExGram.Model.CallbackQuery{
      id: # redacted,
      from: %ExGram.Model.User{
        # redacted
      },
      message: %ExGram.Model.Message{
        message_id: 56,
        message_thread_id: nil,
        from: %ExGram.Model.User{
          id: # redacted,
          is_bot: true,
          first_name: # redacted,
          last_name: nil,
          username: # redacted,
          language_code: nil,
          is_premium: nil,
          added_to_attachment_menu: nil,
          can_join_groups: nil,
          can_read_all_group_messages: nil,
          supports_inline_queries: nil
        },
        sender_chat: nil,
        sender_boost_count: nil,
        date: 1710436126,
        chat: %ExGram.Model.Chat{
          # redacted
        },
        forward_origin: nil,
        is_topic_message: nil,
        is_automatic_forward: nil,
        reply_to_message: nil,
        external_reply: nil,
        quote: nil,
        reply_to_story: nil,
        via_bot: nil,
        edit_date: nil,
        has_protected_content: true,
        media_group_id: nil,
        author_signature: nil,
        text: # redacted,
        entities: nil,
        link_preview_options: nil,
        animation: nil,
        audio: nil,
        document: nil,
        photo: nil,
        sticker: nil,
        story: nil,
        video: nil,
        video_note: nil,
        voice: nil,
        caption: nil,
        caption_entities: nil,
        has_media_spoiler: nil,
        ...
      },
      inline_message_id: nil,
      chat_instance: # redacted,
      data: "close",
      game_short_name: nil
    }

I'd say this could be closed since everything is back to normal. Muchas gracias Rock!

rockneurotiko commented 8 months ago

Released 0.52.1 with the fix. Thanks again for the reporting! 🧡