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 218 forks source link

Add pattern matching support for Telegram types #229

Closed smaximov closed 3 years ago

smaximov commented 3 years ago

This PR adds support for pattern-matching Telegram types.

Some silly example:

update = Telegram::Bot::Api::Update.new(payload)

include Telegram::Bot::Api::Types

case update
in Update(message: Message(text: text, from: User(id: telegram_id, is_bot: false)))
  bot.api.send_message(chat_id: telegram_id, text: text.reverse)
in Update(message: Message(text: text, from: User(id: telegram_id, is_bot: true)))
  bot.api.send_message(chat_id: telegram_id, text: 'No bots allowed!')
else
  # unsupported update type
end
atipugin commented 3 years ago

@smaximov looks good, thanks! Merged.