class Xasin::Telegram::Chat
Attributes
casual_name[R]
chat_id[R]
chat_obj[R]
on_telegram_event[R]
str_id[R]
Public Class Methods
new(handler, chat_info)
click to toggle source
Initialize a chat object. Call this to generate a new chat object. It will always have to be called with a Chat
object, as returned by a message's “chat” field or the getChat function
# File lib/xasin/telegram/Chat.rb, line 18 def initialize(handler, chat_info) @handler = handler; @chat_id = chat_info[:id]; @str_id = chat_info[:username] || chat_info[:title] @casual_name = @str_id; @chat_obj = chat_info; @on_telegram_event = [] end
Public Instance Methods
on_command(command, **options, &block)
click to toggle source
Add a command callback. Equivalent to {Handler#on_command}, but will only be called on commands issued in this chat.
# File lib/xasin/telegram/Chat.rb, line 54 def on_command(command, **options, &block) raise ArgumentError, 'Block must be given!' unless block_given? options[:block] = block options[:command] = command out_evt = OnCommand.new(options); @on_telegram_event << out_evt out_evt end
on_message(regexp = nil, &block)
click to toggle source
Add a new message callback. Similar to the Handler's function, but only applies to this chat's messages. Especially nice for one-on-one bots. @see Handler#on_message
# File lib/xasin/telegram/Chat.rb, line 42 def on_message(regexp = nil, &block) raise ArgumentError, 'Block must be given!' unless block_given? out_evt = OnMessage.new({ block: block, regexp: regexp }); @on_telegram_event << out_evt out_evt end
send_message(text, **options)
click to toggle source
Send a message to this chat. @see Handler#send_message
# File lib/xasin/telegram/Chat.rb, line 34 def send_message(text, **options) @handler.send_message(self, text, **options); end
tg_mention()
click to toggle source
to_i()
click to toggle source
# File lib/xasin/telegram/Chat.rb, line 78 def to_i @chat_id end
to_s()
click to toggle source
# File lib/xasin/telegram/Chat.rb, line 82 def to_s @casual_name end