Compare commits
3 Commits
51952ecdc2
...
9e988e92d1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e988e92d1
|
||
|
|
4232df302b
|
||
|
|
2c8b3cdacc
|
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class ExchangeXmppContactsJob < ApplicationJob
|
||||
class XmppExchangeContactsJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(inviter, username, domain)
|
||||
8
app/jobs/xmpp_send_message_job.rb
Normal file
8
app/jobs/xmpp_send_message_job.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class XmppSendMessageJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(payload)
|
||||
ejabberd = EjabberdApiClient.new
|
||||
ejabberd.send_message payload
|
||||
end
|
||||
end
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user