From cb97e5e7a39577cf871447d74c7469ebe3ae79be Mon Sep 17 00:00:00 2001 From: nevrfl Date: Tue, 1 Oct 2024 13:49:43 +0300 Subject: [PATCH] add photo attachment to create issue from telegram --- CHANGELOG.md | 4 ++++ lib/redmine_bots/telegram/bot.rb | 4 ++++ lib/redmine_bots/telegram/bot/user_action.rb | 18 +++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 080e6fe..eedba69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.5.5 + +* Add functionality for processing photos from telegram + # 0.5.4 * Fix set bot permissions diff --git a/lib/redmine_bots/telegram/bot.rb b/lib/redmine_bots/telegram/bot.rb index e24bfc3..c2e6aa9 100644 --- a/lib/redmine_bots/telegram/bot.rb +++ b/lib/redmine_bots/telegram/bot.rb @@ -56,6 +56,10 @@ def promote_chat_member(chat_id:, **params) handle_errors { throttle.apply(chat_id) { api.promote_chat_member(chat_id: chat_id, **params) } } end + def get_file(chat_id:, file_id:) + handle_errors { throttle.apply(chat_id) { api.get_file(file_id: file_id) } } + end + def set_webhook webhook_url = "https://#{Setting.host_name}/telegram/api/web_hook/#{webhook_secret}" api.set_webhook(url: webhook_url) diff --git a/lib/redmine_bots/telegram/bot/user_action.rb b/lib/redmine_bots/telegram/bot/user_action.rb index 2a5b119..7d68c42 100644 --- a/lib/redmine_bots/telegram/bot/user_action.rb +++ b/lib/redmine_bots/telegram/bot/user_action.rb @@ -39,7 +39,23 @@ def callback_query? end def text - message? ? message.text.to_s : '' + if message? && !message.media_group_id + if has_photo? + message.caption.to_s + else + message.text.to_s + end + else + '' + end + end + + def photo + message.photo.max_by { |photo| photo.file_size } + end + + def has_photo? + message.photo.present? && !message.media_group_id end def command?