Skip to content

Commit

Permalink
Merge pull request #60 from southbridgeio/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
vladislav-yashin authored Jul 2, 2021
2 parents 3d08b7f + f06be2b commit fc727a5
Show file tree
Hide file tree
Showing 59 changed files with 447 additions and 1,105 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.5.0

* Use supergroup chats
* Refactor telegram commands
* Support persistent commands
* Update tdlib, remove proxy support

# 0.4.1

* Fix tdlib proxy
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ gem 'sidekiq-rate-limiter', '0.1.3', require: 'sidekiq-rate-limiter/server'
gem 'telegram-bot-ruby', '>= 0.11', '< 1.0'
gem 'slack-ruby-bot'
gem 'celluloid-io'
gem 'tdlib-ruby', '2.2.0'
gem 'tdlib-ruby', '3.0.2'
gem 'tdlib-schema', '~> 1.7.0'
gem 'jwt'
gem 'filelock'
gem 'patron'
Expand Down
15 changes: 0 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,6 @@ Telegram support includes:
* Common client commands that utilize [tdlib-ruby](https://github.com/centosadmin/tdlib-ruby)
* [Telegram Login](https://core.telegram.org/widgets/login) to connect Redmine and Telegram accounts


### Proxy

You can set proxy pool on plugin settings page. Proxies are gonna be monitored for availability, and first working proxy will be taken for every request.

Proxy format is same to curl:

```bash
http://user:[email protected]:3128
socks5://user:[email protected]:9050
```

Only SOCKS5 and HTTP proxies are supported.
Note that tdlib supports only SOCKS5 proxies, so you should add at least one SOCKS5 proxy if you want tdlib to be proxied.

### Tdlib
In order to use tdlib client you need compiled [TDLib](https://github.com/tdlib/td).

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/redmine_telegram_setup_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def bot_init
bot = RedmineBots::Telegram.init_bot
bot.api.setWebhook(url: web_hook_url)

redirect_to plugin_settings_path('redmine_bots'), notice: t('redmine_chat_telegram.bot.authorize.success')
redirect_to plugin_settings_path('redmine_bots'), notice: t('redmine_2chat.bot.authorize.success')
end

def bot_deinit
token = Setting.plugin_redmine_bots['telegram_bot_token']
bot = Telegram::Bot::Client.new(token)
bot.api.setWebhook(url: '')
redirect_to plugin_settings_path('redmine_bots'), notice: t('redmine_chat_telegram.bot.deauthorize.success')
redirect_to plugin_settings_path('redmine_bots'), notice: t('redmine_2chat.bot.deauthorize.success')
end

private
Expand Down
16 changes: 0 additions & 16 deletions app/controllers/telegram_login_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@ def check_auth
handle_auth_result(auth, user)
end

def send_sign_in_link
user = session[:otp_user_id] ? User.find(session[:otp_user_id]) : User.current
message = RedmineBots::Telegram::Bot::SendSignInLink.(user, context: context, params: params.to_unsafe_h.slice(:autologin, :back_url))
session[:sign_in_message_id] = message.dig('result', 'message_id') if message
render plain: 'SUCCESS', status: :ok
end

def check_jwt
user = User.find_by_id(session[:otp_user_id]) || User.current
auth = RedmineBots::Telegram::Bot::AuthenticateByToken.(user, params[:token],
context: context,
sign_in_message_id: session[:sign_in_message_id])

handle_auth_result(auth, user)
end

private

def context
Expand Down
53 changes: 0 additions & 53 deletions app/controllers/telegram_proxies_controller.rb

This file was deleted.

41 changes: 11 additions & 30 deletions app/views/settings/redmine_bots/_telegram.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
<th><%= t 'redmine_bots.requirements.telegram.description' %></th>
</tr>
</thead>
<tr>
<td>TDlib</td>
<td>
<% if tdlib_path = (TD::Api::Dl.find_lib rescue nil) %>
<%= t 'redmine_bots.requirements.yes' %>
<% else %>
<%= t 'redmine_bots.requirements.no' %>
<% end %>
</td>
<td><%= tdlib_path || t('redmine_bots.requirements.telegram.tdlib_installation').html_safe %></td>
</tr>
<!-- <tr>-->
<!-- <td>TDlib</td>-->
<!-- <td>-->
<%# if tdlib_path = (TD::Api::Dl.find_lib rescue nil) %>
<%#= t 'redmine_bots.requirements.yes' %>
<%# else %>
<%#= t 'redmine_bots.requirements.no' %>
<%# end %>
<!-- </td>-->
<!-- <td><%#= tdlib_path || t('redmine_bots.requirements.telegram.tdlib_installation').html_safe %></td>-->
<!-- </tr>-->
</table>

<p>
Expand All @@ -54,25 +54,6 @@
<a target="_blank" href ="https://my.telegram.org/apps">API ID and API Hash can be obtained here</a>
</p>

<hr>

<h3><%= t 'redmine_bots.settings.telegram.proxy_settings' %></h3>

<p>
<label>
<%= t 'redmine_bots.settings.telegram.tdlib_use_proxy' %>
</label>
<%= check_box_tag 'settings[tdlib_use_proxy]', '1', @settings['tdlib_use_proxy'] %>
<p>
<label>
<%= t 'redmine_bots.settings.telegram.bot_use_proxy' %>
</label>
<%= check_box_tag 'settings[bot_use_proxy]', '1', @settings['bot_use_proxy'] %>
</p>

<%= link_to t('redmine_bots.settings.telegram.proxy_list'), telegram_proxies_path, remote: true %>


<hr>

<div style="display: flex; align-items: center;">
Expand Down
18 changes: 0 additions & 18 deletions app/views/telegram_login/_widget.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
<script async src="https://telegram.org/js/telegram-widget.js?4" data-telegram-login="<%= Setting.plugin_redmine_bots['telegram_bot_name'] %>" data-size="large" data-auth-url="<%= Setting.protocol %>://<%= Setting.host_name %>/telegram/check_auth?<%= params.to_unsafe_h.slice(:autologin, :back_url).merge(context: context).to_query %>" data-request-access="write"></script>
<% current_user = @user || User.current %>
<% telegram_account =
case context
when 'account_connection'
current_user.telegram_account
when '2fa_connection'
current_user.telegram_connection
end
%>
<br>

<% if current_user.logged? && telegram_account.present? %>
<%= link_to send_telegram_sign_in_link_path(params.to_unsafe_h.slice(:autologin, :back_url)), method: :post, remote: true do %>
<%= t('redmine_bots.telegram.bot.login.send_to_telegram') %>
<% end %> (<%= t('redmine_bots.telegram.bot.login.widget_not_visible') %>)
<% else %>
<%= t('redmine_bots.telegram.bot.login.write_to_bot', bot: Setting.plugin_redmine_bots['telegram_bot_name']) %>
<% end %>
11 changes: 0 additions & 11 deletions app/views/telegram_proxies/_item.html.erb

This file was deleted.

16 changes: 0 additions & 16 deletions app/views/telegram_proxies/_modal.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/telegram_proxies/destroy.js.erb

This file was deleted.

2 changes: 0 additions & 2 deletions app/views/telegram_proxies/index.js.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/telegram_proxies/new.js.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/telegram_proxies/update.js.erb

This file was deleted.

11 changes: 11 additions & 0 deletions app/workers/async_bot_handler_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AsyncBotHandlerWorker
include Sidekiq::Worker

sidekiq_options queue: :telegram

def perform(method, args)
RedmineBots::Telegram.set_locale

RedmineBots::Telegram.bot.send(method, **args.symbolize_keys)
end
end
10 changes: 5 additions & 5 deletions app/workers/telegram_accounts_refresh_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class TelegramAccountsRefreshWorker

def perform
TelegramAccount.where.not(telegram_id: nil).find_each do |account|
RedmineBots::Telegram::Tdlib::GetUser.(account.telegram_id).then do |user|
ActiveRecord::Base.connection_pool.with_connection do
account.update_attributes(user.to_h.slice(*%w[username first_name last_name]))
end
end.wait
new_data = RedmineBots::Telegram.bot.get_chat(chat_id: account.telegram_id)
account.update(**new_data['result'].slice('username', 'first_name', 'last_name').symbolize_keys)
sleep 1
rescue => e
logger.warn("Error during telegram accounts refresh: #{e.message}")
end
end
end
22 changes: 1 addition & 21 deletions app/workers/telegram_handler_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,7 @@ class TelegramHandlerWorker
include Sidekiq::Worker
sidekiq_options queue: :telegram

TYPES = %w(inline_query
chosen_inline_result
callback_query
edited_message
message
channel_post
edited_channel_post)

def perform(params)
update = Telegram::Bot::Types::Update.new(params)
message = TYPES.reduce(nil) { |m, t| m || update.public_send(t) }

if message.present?
RedmineBots::Telegram.update_manager.handle_message(message)
else
logger.fatal "Can't find message: #{params.to_json}"
end
end

def logger
@logger ||= Logger.new(Rails.root.join('log/redmine_bots',
'telegram-handler.log'))
RedmineBots::Telegram.bot.handle_update(params)
end
end
7 changes: 0 additions & 7 deletions app/workers/telegram_proxy_monitoring_worker.rb

This file was deleted.

2 changes: 1 addition & 1 deletion config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ru:
telegram:
phone_number: "Номер телефона"
phone_number_hint: "В формате: 78005553535"
phone_code: "Код телеграмма"
phone_code: "Код из Telegram"
authorize_button_code: "Получить код авторизации"
authorize_client: "Авторизовать клиент Telegram"
authorize_hint: "Чтобы авторизировать Telegram, нажмите кнопку ниже. Текущая авторизация сбросится."
Expand Down
2 changes: 0 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

get 'login' => 'telegram_login#index', as: 'telegram_login'
get 'check_auth' => 'telegram_login#check_auth'
get 'check_jwt' => 'telegram_login#check_jwt'
post 'send_sign_in_link' => 'telegram_login#send_sign_in_link', as: 'send_telegram_sign_in_link'
end

scope :telegram_proxies do
Expand Down
9 changes: 3 additions & 6 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
Dir.glob(File.dirname(__FILE__) + paths).each do |file|
require_dependency file
end
Faraday::Adapter.register_middleware redmine_bots: RedmineBots::Telegram::Bot::FaradayAdapter

Telegram::Bot.configure do |config|
config.adapter = :redmine_bots
end
end

Rails.application.config.eager_load_paths += Dir.glob("#{Rails.application.config.root}/plugins/redmine_bots/{lib,app/workers,app/models,app/controllers,lib/redmine_bots/telegram/{patches/*_patch,hooks/*_hook}}")
Expand All @@ -34,7 +29,7 @@
name 'Redmine Bots'
url 'https://github.com/southbridgeio/redmine_bots'
description 'This is a platform for building Redmine bots'
version '0.4.1'
version '0.5.0'
author 'Southbridge'
author_url 'https://github.com/southbridgeio'

Expand All @@ -51,3 +46,5 @@

permission :view_telegram_account_info, {}
end

RedmineBots::Telegram.init
Loading

0 comments on commit fc727a5

Please sign in to comment.