Class: TeleNotify::TelegramUser
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- TeleNotify::TelegramUser
- Defined in:
- lib/tele_notify/telegram_user.rb
Constant Summary collapse
- @@next_update_id =
0
Class Method Summary collapse
- .active_url ⇒ Object
- .configure_dev_url(url) ⇒ Object
- .configure_home_url(url) ⇒ Object
- .configure_token(token) ⇒ Object
- .send_message_to_all(text) ⇒ Object
Instance Method Summary collapse
Class Method Details
.active_url ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/tele_notify/telegram_user.rb', line 19 def self.active_url if Rails.env.production? @@home_url else @@dev_url end end |
.configure_dev_url(url) ⇒ Object
15 16 17 |
# File 'lib/tele_notify/telegram_user.rb', line 15 def self.configure_dev_url(url) @@dev_url = url end |
.configure_home_url(url) ⇒ Object
11 12 13 |
# File 'lib/tele_notify/telegram_user.rb', line 11 def self.configure_home_url(url) @@home_url = url end |
.configure_token(token) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tele_notify/telegram_user.rb', line 28 def self.configure_token(token) if token =~ /^[0-9]+:[\w-]+$/ #hacker proof @@token = token @@url = "https://api.telegram.org/bot" + token + "/" @@callback_url = active_url + "/" + @@token RestClient.post(@@url + "setWebhook", { url: @@callback_url }) else raise "Invalid token! Please add a valid Telegram token in config/initializers/tele_notify.rb or see https://github.com/ppati000/tele_notify for further instructions." end end |
.send_message_to_all(text) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/tele_notify/telegram_user.rb', line 39 def self.(text) success = true TeleNotify::TelegramUser.all.each do |user| success = false if !user.(text) end success end |
Instance Method Details
#send_message(text) ⇒ Object
48 49 50 51 |
# File 'lib/tele_notify/telegram_user.rb', line 48 def (text) response = JSON.parse(RestClient.post(@@url + "sendMessage", chat_id: self.telegram_id, text: text), { symbolize_names: true }) response[:ok] end |