Class: Diligence::Types::Message
- Inherits:
-
Object
- Object
- Diligence::Types::Message
- Defined in:
- lib/diligence/types/message.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #has_attachments? ⇒ Boolean
-
#initialize(raw, api_client: nil) ⇒ Message
constructor
A new instance of Message.
- #reply(text) ⇒ Object
- #text ⇒ Object
Constructor Details
#initialize(raw, api_client: nil) ⇒ Message
Returns a new instance of Message.
10 11 12 13 14 15 16 |
# File 'lib/diligence/types/message.rb', line 10 def initialize(raw, api_client: nil) @raw = raw @api_client = api_client @id = raw.fetch('message_id') @created_at = Time.at(raw.fetch('date')).to_datetime end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
8 9 10 |
# File 'lib/diligence/types/message.rb', line 8 def content @content end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
8 9 10 |
# File 'lib/diligence/types/message.rb', line 8 def created_at @created_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/diligence/types/message.rb', line 8 def id @id end |
Instance Method Details
#has_attachments? ⇒ Boolean
22 23 24 25 |
# File 'lib/diligence/types/message.rb', line 22 def = %w[photo video document audio voice video_note sticker animation] .any? { |key| @raw.key?(key) } end |
#reply(text) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/diligence/types/message.rb', line 27 def reply(text) raise 'API client not set' unless @api_client chat_id = @raw.dig('chat', 'id') @api_client.(chat_id: chat_id, text: text) end |
#text ⇒ Object
18 19 20 |
# File 'lib/diligence/types/message.rb', line 18 def text @raw['text'] end |