diff --git a/lnurl.go b/lnurl.go index 9d0df28..7f4d124 100644 --- a/lnurl.go +++ b/lnurl.go @@ -52,6 +52,7 @@ type LNURLPayValuesCustom struct { Nip57ReceiptRelays []string `json:"nip57ReceiptRelays"` AwaitInvoicePaid bool `json:"awaitInvoicePaid"` Sender string `json:"sender"` + Note string `json:"note"` } func handleLNURL(w http.ResponseWriter, r *http.Request) { @@ -282,11 +283,15 @@ func serveLNURLpSecond(w http.ResponseWriter, params *Params, username string, a //Check invoice paid only if we actually have a NIP57 event var awaitPaid = false var sender = "" + var note = "" // nip57 - we need to store the newly created invoice in the zap receipt if zapEvent.Sig != "" { nip57Receipt = CreateNostrReceipt(zapEvent, invoice) awaitPaid = true sender = "@" + EncodeBench32Public(zapEvent.PubKey) + if zapEvent.Tags.GetFirst([]string{"e"}) != nil { + note = "@" + EncodeBench32Note(zapEvent.Tags.GetFirst([]string{"e"}).Value()) + } log.Debug().Str("Zap from", sender).Msg("Nostr") } @@ -306,6 +311,7 @@ func serveLNURLpSecond(w http.ResponseWriter, params *Params, username string, a Nip57ReceiptRelays: nip57ReceiptRelays, AwaitInvoicePaid: awaitPaid, Sender: sender, + Note: note, }, nil } diff --git a/nostr.go b/nostr.go index d1e0360..9accfb8 100644 --- a/nostr.go +++ b/nostr.go @@ -59,6 +59,13 @@ func EncodeBench32Private(key string) string { return key } +func EncodeBench32Note(key string) string { + if v, err := nip19.EncodeNote(key); err == nil { + return v + } + return key +} + func sendMessage(receiverKey string, message string) { var relays []string diff --git a/waitforinvoice.go b/waitforinvoice.go index 5e11519..3f19132 100644 --- a/waitforinvoice.go +++ b/waitforinvoice.go @@ -178,9 +178,19 @@ func WaitForInvoicePaid(payvalues LNURLPayValuesCustom, params *Params) { } if params.Npub != "" && params.NotifyZapComment && payvalues.Comment != "" { - go sendMessage(params.Npub, "Received Zap from "+payvalues.Sender+" with amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️. Comment: "+payvalues.Comment) + if payvalues.Note != "" { + go sendMessage(params.Npub, "Received Zap from "+payvalues.Sender+" with amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️ for note "+payvalues.Note+". Comment: "+payvalues.Comment) + + } else { + go sendMessage(params.Npub, "Received Profile Zap from "+payvalues.Sender+" with amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️. Comment: "+payvalues.Comment) + } } else if params.Npub != "" && params.NotifyZaps { - go sendMessage(params.Npub, "Received Zap from "+payvalues.Sender+" with amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️.") + if payvalues.Note != "" { + go sendMessage(params.Npub, "Received Zap from "+payvalues.Sender+" with amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️ for note "+payvalues.Note+".") + + } else { + go sendMessage(params.Npub, "Received Profile Zap from "+payvalues.Sender+" with amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️.") + } } log.Debug().Str("ZAPPED ⚡️", "Published zap on Nostr").Msg("Nostr")