specify webhooks from invoice creation and call them.

This commit is contained in:
fiatjaf
2020-12-24 09:39:46 -03:00
committed by fiatjaf
parent 503c981bc9
commit 4623220316
2 changed files with 21 additions and 23 deletions
+10
View File
@@ -1,4 +1,5 @@
import trio # type: ignore
import httpx
from typing import List
from lnbits.tasks import register_invoice_listener
@@ -14,9 +15,18 @@ async def register_listeners():
async def wait_for_paid_invoices(invoice_paid_chan: trio.MemoryReceiveChannel):
async for payment in invoice_paid_chan:
# send information to sse channel
for send_channel in sse_listeners:
try:
send_channel.send_nowait(payment)
except trio.WouldBlock:
print("removing sse listener", send_channel)
sse_listeners.remove(send_channel)
# dispatch webhook
if payment.extra and "webhook" in payment.extra:
async with httpx.AsyncClient() as client:
try:
await client.post(payment.extra["webhook"], json=payment._asdict(), timeout=40)
except (httpx.ConnectError, httpx.RequestError):
pass