Add Webhooks and XMPP notifications for incoming sats #79
@@ -6,15 +6,33 @@ class WebhooksController < ApplicationController
|
||||
def lndhub
|
||||
begin
|
||||
payload = JSON.parse(request.body.read, symbolize_names: true)
|
||||
|
raucao marked this conversation as resolved
|
||||
return unless payload[:type] == "incoming"
|
||||
rescue
|
||||
head :unprocessable_entity and return
|
||||
end
|
||||
|
||||
user = User.find_by(ln_account: payload[:user_login])
|
||||
|
raucao marked this conversation as resolved
Outdated
bumi
commented
should not be the case, but this might be nil. maybe we should do a should not be the case, but this might be nil. maybe we should do a `User.find_by!`
raucao
commented
Good idea! Fails much cleaner and more expressively than when trying to access properties on Good idea! Fails much cleaner and more expressively than when trying to access properties on `nil` later.
|
||||
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user
doesn't rails automatically parse the JSON because the proper content type is set?
so
params[:type]andparams[:user_login]should be enough?I didn't know, so I tried (also with explicitly setting the content type in the spec). Doesn't do it.