Class: Chat

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram/chat.rb

Overview

Is a representation of Telegrams Chat object

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, type:, title: nil, username: nil, first_name: nil, last_name: nil) ⇒ Chat

Returns a new instance of Chat.



13
14
15
16
17
18
19
20
# File 'lib/telegram/chat.rb', line 13

def initialize(id:, type:, title: nil, username: nil, first_name: nil, last_name: nil)
  @id = id
  @type = type
  @title = title
  @username = username
  @first_name = first_name
  @last_name = last_name
end

Instance Attribute Details

#first_nameObject (readonly)

Returns the value of attribute first_name.



5
6
7
# File 'lib/telegram/chat.rb', line 5

def first_name
  @first_name
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/telegram/chat.rb', line 5

def id
  @id
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



5
6
7
# File 'lib/telegram/chat.rb', line 5

def last_name
  @last_name
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/telegram/chat.rb', line 5

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/telegram/chat.rb', line 5

def type
  @type
end

#usernameObject (readonly)

Returns the value of attribute username.



5
6
7
# File 'lib/telegram/chat.rb', line 5

def username
  @username
end

Class Method Details

.from_hash(chat) ⇒ Object



7
8
9
10
11
# File 'lib/telegram/chat.rb', line 7

def self.from_hash(chat)
  return nil unless chat.is_a? Hash

  Chat.new(id: chat['id'], type: chat['type'], title: chat['title'], username: chat['username'], first_name: chat['first_name'], last_name: chat['last_name'])
end

Instance Method Details

#reply(text, opts = {}) ⇒ Object



22
23
24
# File 'lib/telegram/chat.rb', line 22

def reply(text, opts = {})
  Telegram.sendMessage opts.merge(chat_id: id, text: text)
end