Class: YATelegramBot::TelegramAPI::Message
- Inherits:
-
Hash
- Object
- Hash
- YATelegramBot::TelegramAPI::Message
- Defined in:
- lib/ya_telegram_bot/telegram_api/message.rb
Overview
represents incoming messages
Constant Summary collapse
- TYPES =
[:text, :audio, :photo, :document, :video, :voice, :contact, :location].freeze
Instance Method Summary collapse
-
#initialize(hash_message, bot = nil) ⇒ Message
constructor
A new instance of Message.
- #method_missing(m, *args) ⇒ Object
-
#reply(params = {}) ⇒ Object
send reply to this message via bot from #initialize.
-
#type ⇒ Symbol
Type of a message (see Message::TYPES).
Constructor Details
#initialize(hash_message, bot = nil) ⇒ Message
Returns a new instance of Message.
17 18 19 20 |
# File 'lib/ya_telegram_bot/telegram_api/message.rb', line 17 def initialize(, bot = nil) @bot = bot merge! hash_for_merging() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
25 26 27 28 |
# File 'lib/ya_telegram_bot/telegram_api/message.rb', line 25 def method_missing(m, *args) return self[m] if self[m] && args.empty? super end |
Instance Method Details
#reply(params = {}) ⇒ Object
send reply to this message via bot from #initialize
params values:
-
:text [String]
-
:as_plain_message [Boolean] default: true. If it’s true, method won’t set :reply_to parameter
TODO: what about files?
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ya_telegram_bot/telegram_api/message.rb', line 56 def reply(params = {}) fail InitWithoutBot unless @bot params[:chat] = self[:chat]['id'] params[:as_plain_message] = true unless params.key? :as_plain_message params[:reply_to] = self[:id] unless params[:as_plain_message] param.delete :as_plain_message @bot.send_text params end |
#type ⇒ Symbol
Returns type of a message (see Message::TYPES).
41 42 43 |
# File 'lib/ya_telegram_bot/telegram_api/message.rb', line 41 def type TYPES.find { |t| self[t] } end |