Skip to content

Commit

Permalink
Bot send issue link after create chat and after /link command
Browse files Browse the repository at this point in the history
  • Loading branch information
arturtr committed Mar 24, 2016
1 parent 48f4465 commit a49eb39
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
name 'Redmine Chat Telegram plugin'
url 'https://github.com/centosadmin/redmine_chat_telegram'
description 'This is a plugin for Redmine which adds Telegram Group Chat to Redmine Issue'
version '0.2.0'
version '0.3.0'
author 'Centos-admin.ru'
author_url 'http://centos-admin.ru'

Expand Down
48 changes: 31 additions & 17 deletions lib/tasks/chat_telegram.rake
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,37 @@ namespace :chat_telegram do

bot.get_updates(fail_silently: false) do |message|
begin
if message.text.present? and message.chat.type == 'group'

chat_title = message.chat.title
issue_id = chat_title.match(/#(\d+)/)[1]
telegram_id = message.message_id
sent_at = message.date
message_text = message.text

from_id = message.from.id
from_first_name = message.from.first_name
from_last_name = message.from.last_name
from_username = message.from.username

TelegramMessage.create issue_id: issue_id,
telegram_id: telegram_id, sent_at: sent_at, message: message_text,
from_id: from_id, from_first_name: from_first_name,
from_last_name: from_last_name, from_username: from_username
chat_title = message.chat.title
issue_id = chat_title.match(/#(\d+)/)[1]
issue_url = if Setting['protocol'] == 'https'
URI::HTTPS.build({ host: Setting['host_name'], path: "/issues/#{issue_id}" }).to_s
else
URI::HTTP.build({ host: Setting['host_name'], path: "/issues/#{issue_id}" }).to_s
end

if message.group_chat_created
bot.send_message(chat_id: message.chat.id, text: "Hello, everybody! This is a chat for issue: #{issue_url}")
elsif message.text.present? and message.chat.type == 'group'

if message.text == '/link'
bot.send_message(chat_id: message.chat.id, text: "Link to issue: #{issue_url}")
else


telegram_id = message.message_id
sent_at = message.date
message_text = message.text

from_id = message.from.id
from_first_name = message.from.first_name
from_last_name = message.from.last_name
from_username = message.from.username

TelegramMessage.create issue_id: issue_id,
telegram_id: telegram_id, sent_at: sent_at, message: message_text,
from_id: from_id, from_first_name: from_first_name,
from_last_name: from_last_name, from_username: from_username
end
end

rescue Exception => e
Expand Down

0 comments on commit a49eb39

Please sign in to comment.