Class: TelegramMeetupBot::Messenger

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram_meetup_bot/messenger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Messenger

Returns a new instance of Messenger.



5
6
7
8
9
# File 'lib/telegram_meetup_bot/messenger.rb', line 5

def initialize(args)
  @api = args.fetch(:api)
  @chat_id = args.fetch(:chat_id)
  @message_id = args[:message_id]
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



3
4
5
# File 'lib/telegram_meetup_bot/messenger.rb', line 3

def api
  @api
end

#chat_idObject (readonly)

Returns the value of attribute chat_id.



3
4
5
# File 'lib/telegram_meetup_bot/messenger.rb', line 3

def chat_id
  @chat_id
end

#message_idObject (readonly)

Returns the value of attribute message_id.



3
4
5
# File 'lib/telegram_meetup_bot/messenger.rb', line 3

def message_id
  @message_id
end

Instance Method Details

#edit_text(text, markup = nil) ⇒ Object



18
19
20
21
22
23
# File 'lib/telegram_meetup_bot/messenger.rb', line 18

def edit_text(text, markup = nil)
  return if chat_id.nil? || message_id.nil?

  api.edit_message_text(chat_id: chat_id, message_id: message_id,
    text: text, reply_markup: markup) rescue nil
end

#send_text(text, markup = nil) ⇒ Object



11
12
13
14
15
16
# File 'lib/telegram_meetup_bot/messenger.rb', line 11

def send_text(text, markup = nil)
  return if chat_id.nil?

  api.send_message(chat_id: chat_id,text: text,
    reply_markup: markup) rescue nil
end