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.
15 16 17 18 |
# File 'lib/ya_telegram_bot/telegram_api/message.rb', line 15 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
23 24 25 26 |
# File 'lib/ya_telegram_bot/telegram_api/message.rb', line 23 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 set, method won’t set :reply_to parameter
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ya_telegram_bot/telegram_api/message.rb', line 52 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).
39 40 41 |
# File 'lib/ya_telegram_bot/telegram_api/message.rb', line 39 def type TYPES.find { |t| self[t] } end |