atipugin / telegram-bot-ruby

Ruby wrapper for Telegram's Bot API
https://core.telegram.org/bots/api
Do What The F*ck You Want To Public License
1.35k stars 217 forks source link

Message.text is nil even thought the schema says it can not be #303

Closed thebravoman closed 3 months ago

thebravoman commented 6 months ago

When sending a message that is just an attached photo the Message.text is nil

Telegram::Bot::Client.run(@token) do |bot|
  bot.listen do |telegram_message|
    case telegram_message
    when Telegram::Bot::Types::Message
      Rails.logger.info "telegram_message.text == nil: #{telegram_message.text == nil}"
    end
  end
end

results in

2024-02-28T06:58:35.323603+00:00 app[worker_telegram_bot.1]: I, [2024-02-28T06:57:35.707711 #2]  INFO -- : telegram_message.text == nil: true

How come the attribute is of type

module Telegram
  module Bot
    module Types
      class Message < Base
...
        attribute? :text, Types::String 
      end
    end
   end
end

but the message.text is nil?

atipugin commented 6 months ago

Hi @thebravoman,

In dry-struct attribute? means attribute is optional.

thebravoman commented 6 months ago

Ah, makes sense.

On Wed, 28 Feb 2024, 10:13 Alexander Tipugin, @.***> wrote:

Hi @thebravoman https://github.com/thebravoman,

In dry-struct attribute? means attribute is optional https://dry-rb.org/gems/dry-struct/1.6/recipes/#tolerance-to-missing-keys .

— Reply to this email directly, view it on GitHub https://github.com/atipugin/telegram-bot-ruby/issues/303#issuecomment-1968443345, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKAGBKP4CBS5L7MMTQ34U3YV3RK7AVCNFSM6AAAAABD5O2RLGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRYGQ2DGMZUGU . You are receiving this because you were mentioned.Message ID: @.***>

AlexWayfer commented 6 months ago

And it's also optional in the official documentation, we have checks for this: https://core.telegram.org/bots/api#message

image

I think, we can close this issue.

github-actions[bot] commented 4 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.