Send an email to the user when a recording is done processing

Had to add an email attribute to users to store their email to send the
notification. Will only send it for user rooms since they are the only
ones we know who to notify.
This commit is contained in:
Leonardo Crauss Daronco 2016-12-08 18:33:19 -02:00
parent 09c30bb5bd
commit e94f3d7a10
12 changed files with 161 additions and 7 deletions

View File

@ -170,9 +170,13 @@ class BbbController < ApplicationController
rec_info = rec_info[:recordings].first
RecordingCreatedJob.perform_later(token, parse_recording_for_view(rec_info))
# send an email to the owner of this recording, if defined
owner = User.find_by(encrypted_id: token)
RecordingReadyEmailJob.perform_later(owner) if owner.present?
# TODO: remove the webhook now that the meeting and recording are done
# remove only if the meeting is not running, otherwise the hook is needed
# if ENV['GREENLIGHT_USE_WEBHOOKS']
# if Rails.configuration.use_webhooks
# webhook_remove("#{base_url}/callback")
# end
else

View File

@ -0,0 +1,25 @@
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2016 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
class RecordingReadyEmailJob < ApplicationJob
queue_as :default
def perform(user)
if user.email.present?
NotificationMailer.recording_ready_email(user).deliver
end
end
end

View File

@ -77,13 +77,12 @@ module BbbApi
"meta_#{BbbApi::META_LISTED}": false,
"meta_#{BbbApi::META_TOKEN}": meeting_token
}
meeting_options.merge!(
{ "meta_#{BbbApi::META_HOOK_URL}": options[:hook_url] }
) if options[:hook_url]
if ENV['GREENLIGHT_USE_WEBHOOKS']
if Rails.configuration.use_webhooks
webhook_register(options[:hook_url], meeting_id)
else
meeting_options.merge!(
{ "meta_#{BbbApi::META_HOOK_URL}": options[:hook_url] }
) if options[:hook_url]
end
# Create the meeting

View File

@ -0,0 +1,25 @@
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2016 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
class NotificationMailer < ActionMailer::Base
default from: Rails.configuration.smtp_from
def recording_ready_email(user)
@user = user
@room_url = resource_url(resource: "rooms", id: user.encrypted_id)
mail(to: user.email, subject: t('.subject'))
end
end

View File

@ -21,6 +21,7 @@ class User < ApplicationRecord
def self.from_omniauth(auth_hash)
user = find_or_initialize_by(uid: auth_hash['uid'], provider: auth_hash['provider'])
user.username = self.send("#{auth_hash['provider']}_username", auth_hash) rescue nil
user.email = self.send("#{auth_hash['provider']}_email", auth_hash) rescue nil
user.name = auth_hash['info']['name']
user.save!
user
@ -30,10 +31,18 @@ class User < ApplicationRecord
auth_hash['info']['nickname']
end
def self.twitter_email(auth_hash)
auth_hash['info']['email']
end
def self.google_username(auth_hash)
auth_hash['info']['email'].split('@').first
end
def self.google_email(auth_hash)
auth_hash['info']['email']
end
def room_url
"/rooms/#{encrypted_id}"
end

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<p><%= t('.hi', name: @user.name) %></p>
<p><%= t('.phrase1') %></p>
<p><%= t('.phrase2', url: @room_url) %></p>
</body>
</html>

View File

@ -37,5 +37,36 @@ module Greenlight
# BigBlueButton
config.bigbluebutton_endpoint = ENV['BIGBLUEBUTTON_ENDPOINT']
config.bigbluebutton_secret = ENV['BIGBLUEBUTTON_SECRET']
# GreenLight
config.use_webhooks = ENV['GREENLIGHT_USE_WEBHOOKS']
config.smtp_from = ENV['SMTP_FROM']
config.smtp_server = ENV['SMTP_SERVER']
config.smtp_domain = ENV['SMTP_DOMAIN']
config.smtp_port = ENV['SMTP_PORT'] || 587
config.smtp_username = ENV['SMTP_USERNAME']
config.smtp_password = ENV['SMTP_PASSWORD']
config.smtp_auth = ENV['SMTP_AUTH'] || "login"
config.smtp_starttls_auto = ENV['SMTP_STARTTLS_AUTO'].nil? ? true : ENV['SMTP_STARTTLS_AUTO']
config.smtp_tls = ENV['SMTP_TLS'].nil? ? false : ENV['SMTP_TLS']
# SMTP
config.action_mailer.default_url_options = { host: ENV['GREENLIGHT_DOMAIN'] }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:address => config.smtp_server,
:domain => config.smtp_domain,
:port => config.smtp_port,
:user_name => config.smtp_username,
:password => config.smtp_password,
:authentication => config.smtp_auth,
:enable_starttls_auto => config.smtp_starttls_auto,
:tls => config.smtp_tls
}
config.action_mailer.default_options = {
from: config.smtp_from
}
end
end

View File

@ -82,6 +82,12 @@ en-US:
subject: "%{user} invited you to a meeting"
my_room: my room
no: No
notification_mailer:
recording_ready_email:
hi: "Hi, %{name}"
phrase1: "One of your recordings has just been made available."
phrase2: "Access the following website to view it and publish to other users: %{url}"
subject: "Your recording is ready!"
oauth_signup: Signup for customized sessions
past_recordings: Past Recordings
footer_html: "%{greenlight_link} build %{version}, Powered by %{bbb_link}"

View File

@ -0,0 +1,22 @@
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2016 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
class AddEmailToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :email, :string
add_index :users, :email, unique: true
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20161108224701) do
ActiveRecord::Schema.define(version: 20161208185458) do
create_table "users", force: :cascade do |t|
t.string "provider", null: false
@ -20,6 +20,8 @@ ActiveRecord::Schema.define(version: 20161108224701) do
t.datetime "updated_at", null: false
t.string "username"
t.string "encrypted_id", null: false
t.string "email"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["encrypted_id"], name: "index_users_on_encrypted_id", unique: true
t.index ["provider", "uid"], name: "index_users_on_provider_and_uid", unique: true
t.index ["provider"], name: "index_users_on_provider"

View File

@ -17,6 +17,20 @@ BIGBLUEBUTTON_SECRET=8cd8ef52e8e101574e400365b55e11a6
# the application when recordings are done).
GREENLIGHT_USE_WEBHOOKS=false
# The web site domain, needed for emails mostly
GREENLIGHT_DOMAIN=localhost
# SMTP configurations
SMTP_FROM=email@gmail.com
SMTP_SERVER=smtp.gmail.com
SMTP_DOMAIN=gmail.com
SMTP_PORT=587
SMTP_USERNAME=email@gmail.com
SMTP_PASSWORD=my-secret-password
# SMTP_TLS=false
# SMTP_AUTH=login
# SMTP_STARTTLS_AUTO=true
# OmniAuth
TWITTER_ID=
TWITTER_SECRET=

View File

@ -0,0 +1,6 @@
# Preview all emails at http://localhost:3000/rails/mailers/example_mailer
class NotificationMailerPreview < ActionMailer::Preview
def recording_ready_email_preview
NotificationMailer.recording_ready_email(User.first)
end
end