From 255f20edef703cb8a0e14dfacda809526dedb488 Mon Sep 17 00:00:00 2001 From: Fitti Date: Tue, 26 Sep 2023 13:56:44 +0200 Subject: [PATCH] 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 --- README.md | 8 +++++++- views_api.py | 5 ++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4965ec9..3a6f1e4 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,16 @@ The TipJar extension allows you to integrate Bitcoin Lightning (and on-chain) ti

How to set it up

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

A note on webhooks

+ +The `description` field of the message POSTed to your webhook will be in the following format: + * `{length of the name}|{name}{message}` + +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.

And that's it already! Let the sats flow!

diff --git a/views_api.py b/views_api.py index 233eed9..302a265 100644 --- a/views_api.py +++ b/views_api.py @@ -62,12 +62,11 @@ async def api_create_tip(data: createTips): name = data.name - # Ensure that description string can be split reliably - name = name.replace('"', "''") if not name: name = "Anonymous" - description = f"{name}: {message}" + # Ensure that description string can be split reliably + description = f"{len(name)}|{name}{message}" charge_id = await create_charge( data={ "amount": sats,