forked from arkhitech/redmine_update_reminder
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from southbridgeio/develop
Release 1.5.0
- Loading branch information
Showing
33 changed files
with
480 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class TelegramGroupMessageSender | ||
include Sidekiq::Worker | ||
|
||
sidekiq_options queue: :telegram, | ||
rate: { | ||
name: 'telegram_group_rate_limit', | ||
limit: 20, | ||
period: 60 | ||
} | ||
|
||
def perform(chat_id, message, issue_id, journal_id) | ||
chat = TelegramGroupChat.find_by(id: chat_id) || return | ||
|
||
Intouch.handle_group_upgrade(chat) do |group| | ||
next unless group.tid.present? | ||
|
||
RedmineBots::Telegram::Bot::MessageSender.call(message: message, | ||
chat_id: -group.tid, | ||
parse_mode: 'HTML', | ||
**Intouch::Preview::KeyboardMarkup.build_hash(issue_id, journal_id)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,14 @@ | ||
class TelegramMessageSender | ||
include Sidekiq::Worker | ||
|
||
sidekiq_options queue: :telegram, | ||
rate: { | ||
name: 'telegram_rate_limit', | ||
limit: 15, | ||
limit: 1, | ||
period: 1 | ||
} | ||
|
||
TELEGRAM_MESSAGE_SENDER_LOG = Logger.new(Rails.root.join('log/intouch', 'telegram-message-sender.log')) | ||
TELEGRAM_MESSAGE_SENDER_ERRORS_LOG = Logger.new(Rails.root.join('log/intouch', 'telegram-message-sender-errors.log')) | ||
|
||
def perform(telegram_account_id, message) | ||
token = Intouch.bot_token | ||
bot = Telegram::Bot::Client.new(token) | ||
|
||
begin | ||
bot.api.send_message(chat_id: telegram_account_id, | ||
text: message, | ||
disable_web_page_preview: true, | ||
parse_mode: 'Markdown') | ||
TELEGRAM_MESSAGE_SENDER_LOG.info "telegram_account_id: #{telegram_account_id}\tmessage: #{message}" | ||
|
||
rescue => e | ||
|
||
TELEGRAM_MESSAGE_SENDER_ERRORS_LOG.info "MESSAGE: #{message}" | ||
|
||
telegram_account = (telegram_account_id > 0) ? | ||
TelegramAccount.find_by(telegram_id: telegram_account_id) : | ||
TelegramGroupChat.find_by(tid: telegram_account_id.abs) | ||
|
||
if e.message.include? 'Bot was kicked' | ||
TELEGRAM_MESSAGE_SENDER_ERRORS_LOG.info "Bot was kicked from chat." | ||
|
||
elsif e.message.include?('429') || e.message.include?('retry later') | ||
|
||
TELEGRAM_MESSAGE_SENDER_ERRORS_LOG.error "429 retry later error. retry to send after 5 seconds\ntelegram_account_id: #{telegram_account_id}\tmessage: #{message}" | ||
TelegramMessageSender.perform_in(5.seconds, telegram_account_id, message) | ||
|
||
else | ||
|
||
TELEGRAM_MESSAGE_SENDER_ERRORS_LOG.error "#{e.class}: #{e.message}" | ||
TELEGRAM_MESSAGE_SENDER_ERRORS_LOG.debug "#{telegram_account.inspect}" | ||
|
||
end | ||
|
||
end | ||
def perform(telegram_account_id, message, params = {}) | ||
RedmineBots::Telegram::Bot::MessageSender.call(chat_id: telegram_account_id, message: message, **params.transform_keys(&:to_sym)) | ||
end | ||
end |
Oops, something went wrong.