Add notification mailer, make wallet notifications configurable
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Râu Cao
2023-04-04 13:39:32 +02:00
parent 43a43e1a2c
commit ca7475dca2
4 changed files with 59 additions and 13 deletions

View File

@@ -12,22 +12,28 @@ class WebhooksController < ApplicationController
end
user = User.find_by!(ln_account: payload[:user_login])
# TODO make configurable
notify_xmpp(user.address, payload[:amount], payload[:memo])
notify = user.preferences.dig("lightning", "notify_sats_received")
case notify
when "xmpp"
notify_xmpp(user.address, payload[:amount], payload[:memo])
when "email"
NotificationMailer.with(user: user, amount_sats: payload[:amount])
.lightning_sats_received.deliver_later
end
head :ok
end
private
# TODO refactor into mailer-like generic class/service
def notify_xmpp(address, amt_sats, memo)
payload = {
type: "normal",
from: "kosmos.org", # TODO domain config
to: address,
subject: "Sats received!",
body: "#{amt_sats} sats received in your Lightning wallet:\n> #{memo}"
body: "#{helpers.number_with_delimiter amt_sats} sats received in your Lightning wallet:\n> #{memo}"
}
XmppSendMessageJob.perform_later(payload)
end

View File

@@ -0,0 +1,8 @@
class NotificationMailer < ApplicationMailer
def lightning_sats_received
@user = params[:user]
@amount_sats = params[:amount_sats]
@subject = "Sats received"
mail to: @user.email, subject: @subject
end
end

View File

@@ -0,0 +1,3 @@
You just received <%= number_with_delimiter @amount_sats %> sats in your Lightning account (<%= @user.address %>). Check your wallet app, or open the account page for details:
<%= wallet_transactions_url %>