Class: Telegram::TelegramMessage
- Inherits:
-
Object
- Object
- Telegram::TelegramMessage
- Defined in:
- lib/telegram/models.rb
Overview
Telegram Message Model
Instance Attribute Summary collapse
-
#client ⇒ Client
readonly
Root client instance.
-
#content_type ⇒ String
readonly
Content type.
-
#id ⇒ Integer
readonly
Message identifier.
-
#raw ⇒ String
readonly
Raw string of the text.
- #raw_target ⇒ String readonly
- #target ⇒ TelegramChat, TelegramContact readonly
-
#time ⇒ Time
readonly
Time message received.
-
#user ⇒ TelegramContact
readonly
The contact who sent this message.
Instance Method Summary collapse
-
#initialize(client, event) ⇒ TelegramMessage
constructor
Create a new tgmessage instance.
- #members ⇒ Object
-
#reply(type, content, target = nil, &callback) ⇒ Object
Reply a message to the chat.
- #reply_user(type, content, &callback) ⇒ Object abstract
-
#to_s ⇒ String
Convert TelegramMessage instance to the string format.
Constructor Details
#initialize(client, event) ⇒ TelegramMessage
Create a new tgmessage instance
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/telegram/models.rb', line 290 def initialize(client, event) @event = event @id = event.id @raw = event..text @time = event.time @content_type = event..type @raw_sender = event..raw_from @raw_receiver = event..raw_to @user = @sender = event..from @receiver = event..to @target = begin case @receiver.type when 'user' @sender when 'chat', 'encr_chat' @receiver end rescue NoMethodError @sender end end |
Instance Attribute Details
#client ⇒ Client (readonly)
Returns Root client instance.
260 261 262 |
# File 'lib/telegram/models.rb', line 260 def client @client end |
#content_type ⇒ String (readonly)
Returns Content type.
278 279 280 |
# File 'lib/telegram/models.rb', line 278 def content_type @content_type end |
#id ⇒ Integer (readonly)
Returns Message identifier.
266 267 268 |
# File 'lib/telegram/models.rb', line 266 def id @id end |
#raw ⇒ String (readonly)
Returns Raw string of the text.
263 264 265 |
# File 'lib/telegram/models.rb', line 263 def raw @raw end |
#raw_target ⇒ String (readonly)
275 276 277 |
# File 'lib/telegram/models.rb', line 275 def raw_target @raw_target end |
#target ⇒ TelegramChat, TelegramContact (readonly)
282 283 284 |
# File 'lib/telegram/models.rb', line 282 def target @target end |
#time ⇒ Time (readonly)
Returns Time message received.
269 270 271 |
# File 'lib/telegram/models.rb', line 269 def time @time end |
#user ⇒ TelegramContact (readonly)
Returns The contact who sent this message.
272 273 274 |
# File 'lib/telegram/models.rb', line 272 def user @user end |
Instance Method Details
#members ⇒ Object
353 354 355 356 357 358 359 360 361 362 |
# File 'lib/telegram/models.rb', line 353 def members contact_list = [] if @target.class == TelegramContact contact_list << @target else contact_list = @target.members end contact_list end |
#reply(type, content, target = nil, &callback) ⇒ Object
Reply a message to the chat
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/telegram/models.rb', line 334 def reply(type, content, target=nil, &callback) target = @target if target.nil? case type when :text target.(content, self, &callback) when :image option = nil content, option = content if content.class == Array if content.include?('http') target.method(:send_image_url).call(content, option, self, &callback) else target.method(:send_image).call(content, self, &callback) end when :video target.send_video(content, self, &callback) end end |
#reply_user(type, content, &callback) ⇒ Object
This method is abstract.
Reply a message to the sender (peer to peer)
322 323 324 |
# File 'lib/telegram/models.rb', line 322 def reply_user(type, content, &callback) end |
#to_s ⇒ String
Convert Telegram::TelegramMessage instance to the string format
367 368 369 |
# File 'lib/telegram/models.rb', line 367 def to_s "<TelegramMessage id=#{@id} raw=#{@raw} time=#{@time} user=#{@user} target=#{@target} raw_target=#{@raw_target}>" end |