Module: Tramway::Bots::Telegram::MessagesManager
- Included in:
- Custom::Notify::File, Custom::Notify::Text, Custom::Scenario
- Defined in:
- lib/tramway/bots/telegram/messages_manager.rb
Instance Method Summary collapse
- #log_message(message, user, chat, bot) ⇒ Object
-
#message_to_chat(bot_api, chat_id, message_obj, **options) ⇒ Object
:reek:FeatureEnvy { enabled: false }.
-
#message_to_user(bot_api, message_obj, chat_id) ⇒ Object
:reek:FeatureEnvy { enabled: true }.
- #send_file(bot_api, chat_id, message_obj) ⇒ Object
Instance Method Details
#log_message(message, user, chat, bot) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/tramway/bots/telegram/messages_manager.rb', line 4 def (, user, chat, bot) file_path = "#{Rails.root}/lib/tasks/bot_telegram/bot_message_attributes.yml" = YAML.load_file(file_path)['telegram_message']['attributes'] = Tramway::Bots::Telegram::Message.find_or_create_by( telegram_message_id: ., bot_id: bot.id, user_id: user.id, chat_id: chat.id ) .update! text: .try(:text), project_id: Project.find_by(title: 'PurpleMagic').id, options: (.reduce({}) do |hash, attribute| hash.merge! attribute => .send(attribute) end) end |
#message_to_chat(bot_api, chat_id, message_obj, **options) ⇒ Object
:reek:FeatureEnvy { enabled: false }
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tramway/bots/telegram/messages_manager.rb', line 25 def (bot_api, chat_id, , **) case .class.to_s when 'String' send_string bot_api, chat_id, , ** when 'Tramway::Bots::Telegram::Custom::Message' bot_api. chat_id: chat_id, **..merge() send_file bot_api, chat_id, if .file.present? else raise .class.to_s end rescue StandardError => error Airbrake.notify error end |
#message_to_user(bot_api, message_obj, chat_id) ⇒ Object
:reek:FeatureEnvy { enabled: true }
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tramway/bots/telegram/messages_manager.rb', line 40 def (bot_api, , chat_id) case .class.to_s when 'String' send_string bot_api, chat_id, when 'Tramway::Bots::Telegram::Scenario::Step' send_scenario_step bot_api, chat_id, when 'Tramway::Bots::Telegram::Custom::Message' bot_api. chat_id: chat_id, **. end rescue StandardError => error Airbrake.notify error end |
#send_file(bot_api, chat_id, message_obj) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/tramway/bots/telegram/messages_manager.rb', line 53 def send_file(bot_api, chat_id, ) mime_type = case .file.file.file[-3..].downcase when 'jpg', 'png' [:photo, 'image/jpeg'] when 'mp3' [:voice, 'audio/mpeg'] end params = { chat_id: chat_id, mime_type[0] => Faraday::UploadIO.new(.file.file.file, mime_type[1]) } if .reply_markup.present? params.merge!( reply_markup: Telegram::Bot::Types::ReplyKeyboardMarkup.new(**.reply_markup), parse_mode: :markdown ) end bot_api.public_send "send_#{mime_type[0]}", **params end |