Class: Mutx::Support::TelegramSender

Inherits:
Object
  • Object
show all
Defined in:
lib/mutx/support/telegram_sender.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token = nil, chat_id) ⇒ TelegramSender

Returns a new instance of TelegramSender.



7
8
9
10
# File 'lib/mutx/support/telegram_sender.rb', line 7

def initialize token=nil, chat_id
  @token = token || Configuration.telegram_token
  @chat_id = chat_id
end

Class Method Details

.run_clientObject



32
33
34
35
36
# File 'lib/mutx/support/telegram_sender.rb', line 32

def self.run_client
  Telegram::Bot::Client.run(Configuration.telegram_token) do |bot|
    yield bot
  end
end

.send_message(chat_id, message, parse_mode = nil) ⇒ Object

Send a message to the given group

Parameters:

  • chat_id (Fixnum)

    the id of the telegram group

  • message (String)

    the message to be sent

  • type (String)

    of message [Markdown, HTML]



26
27
28
29
30
# File 'lib/mutx/support/telegram_sender.rb', line 26

def self.send_message chat_id, message, parse_mode=nil
  Telegram::Bot::Client.run(Configuration.telegram_token) do |bot|
    bot.api.send_message(chat_id: chat_id, text: message, parse_mode:parse_mode)
  end
end

Instance Method Details

#send_message(message) ⇒ Object

Send a message to the given group

Parameters:

  • chat_id (Fixnum)

    the id of the telegram group

  • message (String)

    the message to be sent

  • type (String)

    of message [Markdown, HTML]



16
17
18
19
20
# File 'lib/mutx/support/telegram_sender.rb', line 16

def send_message message
  Telegram::Bot::Client.run(@token) do |bot|
    bot.api.send_message(chat_id: @chat_id, text: message)
  end
end