mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-06 18:02:38 +02:00
added webhook and messages
This commit is contained in:
@@ -25,7 +25,8 @@ async def lnurl_response(cp_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
params = resp.dict()
|
params = resp.dict()
|
||||||
params["commentAllowed"] = 300
|
if cp.show_message:
|
||||||
|
params["commentAllowed"] = 300
|
||||||
|
|
||||||
return jsonify(params)
|
return jsonify(params)
|
||||||
|
|
||||||
@@ -54,14 +55,17 @@ async def lnurl_callback(cp_id):
|
|||||||
).dict()
|
).dict()
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
comment = ""
|
||||||
comment = request.args.get("comment")
|
if request.args.get("comment"):
|
||||||
if len(comment or "") > 300:
|
comment = request.args.get("comment")
|
||||||
return jsonify(
|
if len(comment or "") > 300:
|
||||||
LnurlErrorResponse(
|
return jsonify(
|
||||||
reason=f"Got a comment with {len(comment)} characters, but can only accept 300"
|
LnurlErrorResponse(
|
||||||
).dict()
|
reason=f"Got a comment with {len(comment)} characters, but can only accept 300"
|
||||||
)
|
).dict()
|
||||||
|
)
|
||||||
|
if len(comment) < 1:
|
||||||
|
comment = "none"
|
||||||
|
|
||||||
payment_hash, payment_request = await create_invoice(
|
payment_hash, payment_request = await create_invoice(
|
||||||
wallet_id=cp.wallet,
|
wallet_id=cp.wallet,
|
||||||
@@ -71,7 +75,8 @@ async def lnurl_callback(cp_id):
|
|||||||
"copilot.api_copilot_hooker",
|
"copilot.api_copilot_hooker",
|
||||||
copilot_id=cp_id,
|
copilot_id=cp_id,
|
||||||
amount=int(amount_received / 1000),
|
amount=int(amount_received / 1000),
|
||||||
_external=True,
|
comment=comment,
|
||||||
|
_external=False,
|
||||||
),
|
),
|
||||||
description_hash=hashlib.sha256(
|
description_hash=hashlib.sha256(
|
||||||
(
|
(
|
||||||
@@ -91,7 +96,8 @@ async def lnurl_callback(cp_id):
|
|||||||
"copilot.api_copilot_hooker",
|
"copilot.api_copilot_hooker",
|
||||||
copilot_id=cp_id,
|
copilot_id=cp_id,
|
||||||
amount=int(amount_received / 1000),
|
amount=int(amount_received / 1000),
|
||||||
_external=True,
|
comment=comment,
|
||||||
|
_external=False,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return jsonify(resp.dict())
|
return jsonify(resp.dict())
|
||||||
|
@@ -93,6 +93,15 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
showNotif: function (userMessage) {
|
||||||
|
this.$q.notify({
|
||||||
|
color: 'purple',
|
||||||
|
html: true,
|
||||||
|
message: '<h2 style="color: white;">' + userMessage + '</h2>',
|
||||||
|
position: 'left',
|
||||||
|
timeout: 5000
|
||||||
|
})
|
||||||
|
},
|
||||||
openURL: function (url) {
|
openURL: function (url) {
|
||||||
console.log(url)
|
console.log(url)
|
||||||
return Quasar.utils.openURL(url)
|
return Quasar.utils.openURL(url)
|
||||||
@@ -230,6 +239,9 @@
|
|||||||
if (res[1].substring(0, 3) == 'htt') {
|
if (res[1].substring(0, 3) == 'htt') {
|
||||||
document.getElementById('iframe_main').src = res[1]
|
document.getElementById('iframe_main').src = res[1]
|
||||||
}
|
}
|
||||||
|
if (res[2] != 'none') {
|
||||||
|
this.showNotif(res[2])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
from quart import g, abort, render_template, jsonify, websocket
|
from quart import g, abort, render_template, jsonify, websocket
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
import httpx
|
||||||
|
|
||||||
from lnbits.decorators import check_user_exists, validate_uuids
|
from lnbits.decorators import check_user_exists, validate_uuids
|
||||||
|
|
||||||
@@ -65,10 +66,13 @@ async def panel(copilot_id):
|
|||||||
return await render_template("copilot/panel.html", copilot=copilot)
|
return await render_template("copilot/panel.html", copilot=copilot)
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.route("/api/v1/copilot/hook/<copilot_id>/<amount>/", methods=["GET"])
|
@copilot_ext.route(
|
||||||
|
"/api/v1/copilot/hook/<copilot_id>/<amount>/<comment>", methods=["GET"]
|
||||||
|
)
|
||||||
async def api_copilot_hooker(copilot_id, amount):
|
async def api_copilot_hooker(copilot_id, amount):
|
||||||
|
|
||||||
data = ""
|
data = ""
|
||||||
|
webhook = ""
|
||||||
copilot = await get_copilot(copilot_id)
|
copilot = await get_copilot(copilot_id)
|
||||||
|
|
||||||
if not copilot:
|
if not copilot:
|
||||||
@@ -76,21 +80,31 @@ async def api_copilot_hooker(copilot_id, amount):
|
|||||||
jsonify({"message": "Copilot link link does not exist."}),
|
jsonify({"message": "Copilot link link does not exist."}),
|
||||||
HTTPStatus.NOT_FOUND,
|
HTTPStatus.NOT_FOUND,
|
||||||
)
|
)
|
||||||
print("got here")
|
|
||||||
if int(copilot.animation1threshold) and int(amount) > copilot.animation1threshold:
|
if int(copilot.animation1threshold) and int(amount) > copilot.animation1threshold:
|
||||||
print("one")
|
|
||||||
data = copilot.animation1
|
data = copilot.animation1
|
||||||
if int(copilot.animation2threshold) and int(amount) > copilot.animation2threshold:
|
webhook = copilot.animation1webhook
|
||||||
print("two")
|
if (
|
||||||
|
int(copilot.animation2threshold)
|
||||||
|
and int(amount) > copilot.animation2threshold
|
||||||
|
):
|
||||||
data = copilot.animation2
|
data = copilot.animation2
|
||||||
|
webhook = copilot.animation1webhook
|
||||||
if (
|
if (
|
||||||
int(copilot.animation3threshold)
|
int(copilot.animation3threshold)
|
||||||
and int(amount) > copilot.animation3threshold
|
and int(amount) > copilot.animation3threshold
|
||||||
):
|
):
|
||||||
print("three")
|
|
||||||
data = copilot.animation3
|
data = copilot.animation3
|
||||||
|
webhook = copilot.animation1webhook
|
||||||
|
if webhook:
|
||||||
|
async with httpx.AsyncClient() as client:
|
||||||
|
await client.post(
|
||||||
|
webhook,
|
||||||
|
json={
|
||||||
|
copilot,
|
||||||
|
},
|
||||||
|
timeout=40,
|
||||||
|
)
|
||||||
global connected_websockets
|
global connected_websockets
|
||||||
|
connected_websockets[copilot_id] = shortuuid.uuid() + "-" + data + "-" + comment
|
||||||
connected_websockets[copilot_id] = shortuuid.uuid() + "-" + data
|
|
||||||
print(connected_websockets)
|
print(connected_websockets)
|
||||||
return "", HTTPStatus.OK
|
return "", HTTPStatus.OK
|
||||||
|
Reference in New Issue
Block a user