Class: Kogno::Telegram::ChatActivity
- Inherits:
-
Object
- Object
- Kogno::Telegram::ChatActivity
- Defined in:
- lib/core/lib/telegram/chat_activity.rb
Instance Method Summary collapse
- #chat ⇒ Object
- #chat_id ⇒ Object
- #chat_membership_status ⇒ Object
- #chat_perms ⇒ Object
- #chat_title ⇒ Object
- #chat_type ⇒ Object
- #get_context(user, notification, notification_group, chat = nil) ⇒ Object
- #get_kgn_id ⇒ Object
- #handle_event(debug = false) ⇒ Object
-
#initialize(data) ⇒ ChatActivity
constructor
A new instance of ChatActivity.
- #inviter_user_id ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(data) ⇒ ChatActivity
Returns a new instance of ChatActivity.
5 6 7 |
# File 'lib/core/lib/telegram/chat_activity.rb', line 5 def initialize(data) @data = data end |
Instance Method Details
#chat ⇒ Object
13 14 15 |
# File 'lib/core/lib/telegram/chat_activity.rb', line 13 def chat @data[:chat] end |
#chat_id ⇒ Object
17 18 19 |
# File 'lib/core/lib/telegram/chat_activity.rb', line 17 def chat_id @data[:chat][:id] end |
#chat_membership_status ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/core/lib/telegram/chat_activity.rb', line 53 def chat_membership_status if ["member","administrator"].include?(@data[:new_chat_member][:status]) return true elsif ["left","kicked"].include?(@data[:new_chat_member][:status]) return false end end |
#chat_perms ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/core/lib/telegram/chat_activity.rb', line 37 def chat_perms perms = @data[:new_chat_member] { can_be_edited: perms[:can_be_edited], can_manage_chat: perms[:can_be_edited], can_change_info: perms[:can_be_edited], can_post_messages: perms[:can_be_edited], can_edit_messages: perms[:can_be_edited], can_delete_messages: perms[:can_be_edited], can_invite_users: perms[:can_be_edited], can_restrict_members: perms[:can_be_edited], can_promote_members: perms[:can_be_edited], can_manage_voice_chats: perms[:can_be_edited] } end |
#chat_title ⇒ Object
21 22 23 |
# File 'lib/core/lib/telegram/chat_activity.rb', line 21 def chat_title @data[:chat][:title] end |
#chat_type ⇒ Object
25 26 27 |
# File 'lib/core/lib/telegram/chat_activity.rb', line 25 def chat_type @data[:chat][:type] end |
#get_context(user, notification, notification_group, chat = nil) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/core/lib/telegram/chat_activity.rb', line 61 def get_context(user,notification, notification_group,chat=nil) # Here you can use different contexts by self.post_id context_class = Context::router(Kogno::Application.config.routes.chat_activity)[:class] context_route = :main context = context_class.new(user,self,notification,context_route, notification_group, chat) return(context) end |
#get_kgn_id ⇒ Object
33 34 35 |
# File 'lib/core/lib/telegram/chat_activity.rb', line 33 def get_kgn_id nil end |
#handle_event(debug = false) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/core/lib/telegram/chat_activity.rb', line 69 def handle_event(debug=false) begin user = User.find_or_create_by_psid(self.inviter_user_id, :telegram) self.set_nlp(user.locale) I18n.locale = user.locale unless user.locale.nil? notification = Notification.new(user,self) chat = TelegramChatGroup.find_or_create({ chat_id: self.chat_id, title: self.chat_title, kind: self.chat_type, inviter_user_id: user.id, membership: self.chat_membership_status }) notification = Notification.new(user,self) notification_group = Notification.new(chat,self) context = get_context(user,notification, notification_group, chat) context.run_for_chat_activity_only notification.send notification_group.send if Kogno::Application.config.store_log_in_database user.(self, :chat_activity_received) user.log_response(notification) end rescue StandardError => e error_token = Digest::MD5.hexdigest("#{Time.now}#{rand(1000)}") # This helps to identify the error that arrives to Slack in order to search it in logs/http.log logger.write e., :red logger.write "Error Token: #{error_token}", :red logger.write "Backtrace:\n\t#{e.backtrace.join("\n\t")}", :red ErrorHandler.notify_by_slack(Kogno::Application.config.app_name,e, error_token) if Kogno::Application.config.error_notifier.slack[:enable] rescue false end end |
#inviter_user_id ⇒ Object
29 30 31 |
# File 'lib/core/lib/telegram/chat_activity.rb', line 29 def inviter_user_id @data[:from][:id] end |
#type ⇒ Object
9 10 11 |
# File 'lib/core/lib/telegram/chat_activity.rb', line 9 def type :chat_activity end |