3 Commits

Author SHA1 Message Date
Râu Cao
9e988e92d1 Notify user about incoming sats via XMPP
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
2023-01-12 11:44:55 +08:00
Râu Cao
4232df302b Add send_message to ejabberd service 2023-01-12 11:44:28 +08:00
Râu Cao
2c8b3cdacc Rename job 2023-01-12 11:43:30 +08:00
5 changed files with 32 additions and 2 deletions

View File

@@ -6,15 +6,33 @@ class WebhooksController < ApplicationController
def lndhub
begin
payload = JSON.parse(request.body.read, symbolize_names: true)
return unless payload[:type] == "incoming"
rescue
head :unprocessable_entity and return
end
user = User.find_by(ln_account: payload[:user_login])
# TODO make configurable
notify_xmpp(user.address, payload[:amount], payload[:memo])
head :ok
end
private
def notify_xmpp(address, amt_sats, memo)
payload = {
type: "normal",
from: "kosmos.org", # TODO domain config
# to: address,
to: "raucao@kosmos.org",
subject: "Sats received!",
body: "#{amt_sats} sats received in your wallet. Memo: \"#{memo}\""
}
XmppSendMessageJob.perform_later(payload)
end
def authorize_request
if !ENV['WEBHOOKS_ALLOWED_IPS'].split(',').include?(request.remote_ip)
head :forbidden and return

View File

@@ -1,4 +1,4 @@
class ExchangeXmppContactsJob < ApplicationJob
class XmppExchangeContactsJob < ApplicationJob
queue_as :default
def perform(inviter, username, domain)

View File

@@ -0,0 +1,8 @@
class XmppSendMessageJob < ApplicationJob
queue_as :default
def perform(payload)
ejabberd = EjabberdApiClient.new
ejabberd.send_message payload
end
end

View File

@@ -46,7 +46,7 @@ class CreateAccount < ApplicationService
def exchange_xmpp_contacts
#TODO enable in development when we have easy setup of ejabberd etc.
return if Rails.env.development?
ExchangeXmppContactsJob.perform_later(@invitation.user, @username, @domain)
XmppExchangeContactsJob.perform_later(@invitation.user, @username, @domain)
end
def create_lndhub_account(user)

View File

@@ -17,4 +17,8 @@ class EjabberdApiClient
def add_rosteritem(payload)
post "add_rosteritem", payload
end
def send_message(payload)
post "send_message", payload
end
end