Skip to content

Commit 255f20e

Browse files
authored
Ensure cosistent split of description for webhook (#2)
* Ensure cosistent split of description for webhook Previously, it wasn't possible to reliably split the description into name and message, since the name could include `:`s. This change prepends the length of the `name` followed by a pipe. Splitting along the first pipe in the string now yields: 1. The length of the name (let's call it `len`) 2. The name, immediately followed by the message (let's call it `joint_description`) Now the webhook receiver can set `name` to be `joint_description[:len]`, and `message` to be `joint_descritption[len:]` * Update README.md
1 parent 45f0e88 commit 255f20e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ The TipJar extension allows you to integrate Bitcoin Lightning (and on-chain) ti
66

77
<h2>How to set it up</h2>
88

9-
1. Simply create a new Tip Jar with the desired details (onchain optional):
9+
1. Simply create a new Tip Jar with the desired details (onchain and webhook optional):
1010
![image](https://user-images.githubusercontent.com/28876473/134996842-ec2f2783-2eef-4671-8eaf-023713865512.png)
1111
1. Share the URL you get from this little button:
1212
![image](https://user-images.githubusercontent.com/28876473/134996973-f8ed4632-ea2f-4b62-83f1-1e4c6b6c91fa.png)
1313

14+
<h2>A note on webhooks</h3>
15+
16+
The `description` field of the message POSTed to your webhook will be in the following format:
17+
* `{length of the name}|{name}{message}`
18+
19+
You can split along the first `|`. This will give you the index at which to split between the name of the tipper and the message of the tipper.
1420

1521
<h3>And that's it already! Let the sats flow!</h3>

views_api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ async def api_create_tip(data: createTips):
6262

6363
name = data.name
6464

65-
# Ensure that description string can be split reliably
66-
name = name.replace('"', "''")
6765
if not name:
6866
name = "Anonymous"
6967

70-
description = f"{name}: {message}"
68+
# Ensure that description string can be split reliably
69+
description = f"{len(name)}|{name}{message}"
7170
charge_id = await create_charge(
7271
data={
7372
"amount": sats,

0 commit comments

Comments
 (0)