Skip to content

Commit

Permalink
Merge pull request #31 from slovensko-digital/support-custom-channel
Browse files Browse the repository at this point in the history
support custom slack channel
  • Loading branch information
celuchmarek authored Oct 11, 2024
2 parents d43251a + 22dd4b5 commit 6ca197d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Notifikácie pre chat www.slack.com a www.discourse.org fórum z Úradu pre vere

Build docker obrazu pomocou `docker build -t my_uvobot .`. Pri spustení kontajnera je potrebné mať nastavené env `RAILS_ENV=production`.

Slack a Discourse integrácie sa nastavujú cez `UVOBOT_SLACK_WEBHOOK` a `DISCOURSE_URL`, `DISCOURSE_API_KEY`, `DISCOURSE_USER` a `DISCOURSE_TARGET_CATEGORY`. Intregrácie, pre ktoré nie sú nastavené envs, sa nevykonajú a uvobot vypíše nájdené výsledky iba do konzoly.
Slack integrácie sa nastavujú cez `UVOBOT_SLACK_WEBHOOK`, kde môže byť viacero URL oddelených čiarkou `,`. Default channel je `#general`, bodkočiarkou `;` za každou URL je možné nastaviť iný channel bez hashtagu `#`. Napr. `https://example.com/my-hook;my-custom-channel,https://example2.com/my-other-hook;my-other-custom-channel`.

Discourse cez `DISCOURSE_URL`, `DISCOURSE_API_KEY`, `DISCOURSE_USER` a `DISCOURSE_TARGET_CATEGORY`. Intregrácie, pre ktoré nie sú nastavené envs, sa nevykonajú a uvobot vypíše nájdené výsledky iba do konzoly.

Čas spustenia `15:00` je možné upraviť v `config/clock.rb`.
5 changes: 3 additions & 2 deletions lib/tasks/uvobot.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ namespace :uvobot do
notifiers = []

if ENV['UVOBOT_SLACK_WEBHOOK']
ENV.fetch('UVOBOT_SLACK_WEBHOOK').split(',').each do |url|
notifiers << Uvobot::Notifications::SlackNotifier.new(url)
ENV.fetch('UVOBOT_SLACK_WEBHOOK').split(',').each do |value|
url, channel = value.split(';')
notifiers << Uvobot::Notifications::SlackNotifier.new(url, channel)
end
end

Expand Down
5 changes: 3 additions & 2 deletions lib/uvobot/notifications/slack_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
module Uvobot
module Notifications
class SlackNotifier < Notifier
def initialize(slack_webhook, http_client = HTTParty)
def initialize(slack_webhook, channel, http_client = HTTParty)
@slack_webhook = slack_webhook
@channel = channel ? channel : 'general'
@http_client = http_client
end

Expand Down Expand Up @@ -35,7 +36,7 @@ def send_message(text)
def payload(text)
{
text: text,
channel: '#general',
channel: "##{@channel}",
username: 'uvobot',
icon_emoji: ':mag_right:'
}.to_json
Expand Down
2 changes: 1 addition & 1 deletion spec/uvobot/notifications/slack_notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe Uvobot::Notifications::SlackNotifier do
let(:curl_double) { double }
let(:notifier) { Uvobot::Notifications::SlackNotifier.new('slack.com', curl_double) }
let(:notifier) { Uvobot::Notifications::SlackNotifier.new('slack.com', 'general', curl_double) }

describe '.new_issue_not_published' do
it 'sends correct payload to slack' do
Expand Down

0 comments on commit 6ca197d

Please sign in to comment.