Module: Kanal::Plugins::UserSystem::Helpers::AutoCreator
- Includes:
- Models
- Defined in:
- lib/kanal/plugins/user_system/helpers/auto_creator.rb
Overview
Serves as a storage of methods to enable automatic user creation used by UserSystem
Class Method Summary collapse
-
.enable_telegram(core) ⇒ Object
Enables automatic creation of telegram user with telegram_chat_id property during consuming of input by router.
Class Method Details
.enable_telegram(core) ⇒ Object
Enables automatic creation of telegram user with telegram_chat_id property during consuming of input by router
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/kanal/plugins/user_system/helpers/auto_creator.rb', line 19 def self.enable_telegram(core) core.hooks.attach :input_before_router do |input| tg_chat_id = input.tg_chat_id tg_chat_id_property = "telegram_chat_id" return if tg_chat_id.nil? user = KanalUser.find_all_by_property(property_name: tg_chat_id_property, property_value: tg_chat_id).first unless user username = input.tg_username username ||= "TEMP_USERNAME_#{tg_chat_id}" user = KanalUser.create(username: username) user.create_or_update_property(tg_chat_id_property, tg_chat_id) end input.user = user end end |