Class: Message
- Inherits:
-
Object
- Object
- Message
- Defined in:
- lib/telegram/message.rb
Overview
Is a representation of Telegrams Message object
Instance Attribute Summary collapse
-
#chat ⇒ Object
readonly
Returns the value of attribute chat.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
- #contains_command?(command) ⇒ Boolean
-
#initialize(message_id:, from: nil, chat:, text:) ⇒ Message
constructor
A new instance of Message.
- #reply(text, opts = {}) ⇒ Object
Constructor Details
#initialize(message_id:, from: nil, chat:, text:) ⇒ Message
Returns a new instance of Message.
16 17 18 19 20 21 |
# File 'lib/telegram/message.rb', line 16 def initialize(message_id:, from:nil, chat:, text:) = @from = from @chat = chat @text = text end |
Instance Attribute Details
#chat ⇒ Object (readonly)
Returns the value of attribute chat.
5 6 7 |
# File 'lib/telegram/message.rb', line 5 def chat @chat end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
5 6 7 |
# File 'lib/telegram/message.rb', line 5 def text @text end |
Class Method Details
.from_hash(message) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/telegram/message.rb', line 7 def self.from_hash() return nil unless .is_a? Hash chat = Chat.from_hash ['chat'] from = User.from_hash ['from'] Message.new(message_id: ['message_id'], from: from, chat: chat, text: ['text']) end |
Instance Method Details
#contains_command?(command) ⇒ Boolean
23 24 25 26 27 28 29 30 31 |
# File 'lib/telegram/message.rb', line 23 def contains_command?(command) if command.is_a?(Symbol) && text.split(' ').first.eql?("/#{command}") true elsif text.start_with?(command.to_s) true else false end end |
#reply(text, opts = {}) ⇒ Object
33 34 35 |
# File 'lib/telegram/message.rb', line 33 def reply(text, opts = {}) chat.reply text, opts.merge(reply_to_message_id: ) end |