Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/report_callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def delete_notification(report)
end

def notify_to_chat(report)
DiscordNotifier.with(report: report).first_report.notify_now if report.first?
ChatNotifier.message(<<~TEXT, webhook_url: ENV['DISCORD_REPORT_WEBHOOK_URL'])
#{report.user.login_name}さんが#{I18n.l report.reported_on}の日報を公開しました。
タイトル:「#{report.title}」
Expand Down
17 changes: 17 additions & 0 deletions app/notifiers/discord_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,21 @@ def product_review_not_completed(params = {})
webhook_url: webhook_url
)
end

def first_report(params = {})
params.merge!(@params)
webhook_url = params[:webhook_url] || Rails.application.secrets[:webhook][:introduction]
report = params[:report]
body = <<~TEXT.chomp
🎉 #{report.user.login_name}さんがはじめての日報を書きました!
タイトル:「#{report.title}」
URL: #{Rails.application.routes.url_helpers.report_url(report)}
TEXT

notification(
body: body,
name: 'ピヨルド',
webhook_url: webhook_url
)
end
end
1 change: 1 addition & 0 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ shared:
admin: <%= ENV['DISCORD_ADMIN_WEBHOOK_URL'] || 'https://discord.com/api/webhooks/0123456789/admin' %>
mentor: <%= ENV['DISCORD_MENTOR_WEBHOOK_URL'] || 'https://discord.com/api/webhooks/0123456789/mentor' %>
all: <%= ENV['DISCORD_ALL_WEBHOOK_URL'] || 'https://discord.com/api/webhooks/0123456789/all' %>
introduction: <%= ENV['DISCORD_INTRODUCTION_WEBHOOK_URL'] || 'https://discord.com/api/webhooks/0123456789/introduction' %>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

stripe:
public_key: pk_test_Je8A9BUHRC8oqsqx8wtfbKwg
secret_key: sk_test_XLP1Ajz1JvT9jUt5uKGvL0Wd
Expand Down
28 changes: 28 additions & 0 deletions test/notifiers/discord_notifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,32 @@ class DiscordNotifierTest < ActiveSupport::TestCase
DiscordNotifier.with(params).hibernated.notify_later
end
end

test '.first_report' do
params = {
report: reports(:report10),
webhook_url: 'https://discord.com/api/webhooks/0123456789/xxxxxxxx'
}

body = <<~TEXT.chomp
🎉 hajimeさんがはじめての日報を書きました!
タイトル:「初日報です」
URL: http://localhost:3000/reports/819157022
TEXT
expected = {
body: body,
name: 'ピヨルド',
webhook_url: 'https://discord.com/api/webhooks/0123456789/xxxxxxxx'
}

assert_notifications_sent 2, **expected do
DiscordNotifier.first_report(params).notify_now
DiscordNotifier.with(params).first_report.notify_now
end

assert_notifications_enqueued 2, **expected do
DiscordNotifier.first_report(params).notify_later
DiscordNotifier.with(params).first_report.notify_later
end
end
end