Module: Tramway::Bots::Telegram::Info
- Included in:
- Custom::Scenario
- Defined in:
- lib/tramway/bots/telegram/info.rb
Instance Method Summary collapse
- #channel_from(channel, bot_record) ⇒ Object
- #chat_from(message_chat, bot_record) ⇒ Object
- #user_from(sender) ⇒ Object
Instance Method Details
#channel_from(channel, bot_record) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/tramway/bots/telegram/info.rb', line 43 def channel_from(channel, bot_record) channel_record = Tramway::Bots::Telegram::Channel.find_or_create_by! telegram_channel_id: channel.id channel_record.update! title: channel.title, bot_id: bot_record.id, project_id: Project.find_by(title: 'PurpleMagic').id channel_record.reload end |
#chat_from(message_chat, bot_record) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tramway/bots/telegram/info.rb', line 27 def chat_from(, bot_record) chat = Tramway::Bots::Telegram::Chat.find_or_create_by! telegram_chat_id: .id, bot_id: bot_record.id chat.update! title: .title, bot_id: bot_record.id, chat_type: .type, project_id: Project.find_by(title: 'PurpleMagic').id, options: (%i[ all_members_are_administrators can_set_sticker_set description first_name invite_link last_name permissions photo pinned_message slow_mode_delay sticker_set_name username ].reduce({}) do |hash, attribute| hash.merge! attribute => .send(attribute) end) chat.reload end |
#user_from(sender) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tramway/bots/telegram/info.rb', line 4 def user_from(sender) user = Tramway::Bots::Telegram::User.find_by telegram_id: sender.id params = { username: sender.username, first_name: sender.first_name, last_name: sender.last_name, project_id: Project.find_by(title: 'PurpleMagic').id, options: { can_join_groups: sender.can_join_groups, can_read_all_group_messages: sender., language_code: sender.language_code, supports_inline_queries: sender.supports_inline_queries, is_bot: sender.is_bot } } if user.present? user.update! params user.reload else Tramway::Bots::Telegram::User.create! telegram_id: sender.id, **params end end |