Skip to content

Commit 3ebb394

Browse files
committed
added simple notification
1 parent c024c02 commit 3ebb394

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

app/controllers/streams_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def save_and_redirect
106106
redirect_to new_stream_path
107107
when @stream.published?
108108
Rails.logger.info("pushing to youtube")
109+
@stream.notify_team!
109110
stream_to_youtube
110111
redirect_to profile_stream_path(current_user.username)
111112
else

app/models/slack.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Slack
2+
class << self
3+
def notify!(emoji, message)
4+
connection = Faraday.new(url: ENV['SLACK_WEBHOOK_URL'])
5+
response = connection.post('', payload: {
6+
"icon_emoji" => emoji,
7+
'text' => "#{message} (cc <!here>)"
8+
}.to_json)
9+
end
10+
end
11+
end

app/models/stream.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ def broadcasting?
2424
broadcasting == true
2525
end
2626

27+
def notify_team!
28+
user_link = "<https://coderwall.com/#{user.username}|#{user.username}>"
29+
stream_link = "<https://coderwall.com/#{user.username}/live|View Stream>"
30+
message = "#{user_link} just started live streaming. #{stream_link}"
31+
Slack.notify!(':movie_camera:', message)
32+
end
33+
2734
def self.any_broadcasting?
2835
Rails.cache.fetch('any-streams-broadcasting', expires_in: 5.seconds) do
2936
broadcasting.any?

0 commit comments

Comments
 (0)