diff --git a/go.mod b/go.mod
index aacbcb6..b7c86b3 100644
--- a/go.mod
+++ b/go.mod
@@ -26,7 +26,6 @@ require (
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f
golang.org/x/text v0.3.7
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba
- gopkg.in/lightningtipbot/telebot.v3 v3.0.0-20220326213923-f323bb71ac8e
gorm.io/driver/sqlite v1.1.4
gorm.io/gorm v1.21.12
)
@@ -73,7 +72,7 @@ require (
github.com/miekg/dns v1.1.43 // indirect
github.com/nbd-wtf/ln-decodepay v1.5.1 // indirect
github.com/pegasus-kv/thrift v0.13.0 // indirect
- github.com/spf13/cast v1.3.1 // indirect
+ github.com/spf13/cast v1.5.0 // indirect
github.com/tidwall/btree v0.6.1 // indirect
github.com/tidwall/grect v0.1.3 // indirect
github.com/tidwall/match v1.1.1 // indirect
@@ -88,10 +87,11 @@ require (
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
+ gopkg.in/lightningtipbot/telebot.v3 v3.0.0-20220828121412-0dea11ecc6dd // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apimachinery v0.0.0-20191123233150-4c4803ed55e3 // indirect
)
-// replace gopkg.in/lightningtipbot/telebot.v2 => ../telebot
+// replace gopkg.in/lightningtipbot/telebot.v3 => ../telebot
diff --git a/go.sum b/go.sum
index 4ac698b..9ede352 100644
--- a/go.sum
+++ b/go.sum
@@ -157,7 +157,6 @@ github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtE
github.com/btcsuite/winsvc v1.0.0 h1:J9B4L7e3oqhXOcm+2IuNApwzQec85lE+QaikUcCs+dk=
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
-github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm4fSc=
github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
@@ -261,6 +260,7 @@ github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHqu
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
github.com/frankban/quicktest v1.2.2/go.mod h1:Qh/WofXFeiAFII1aEBu529AtJo6Zg2VHscnEsbBnJ20=
+github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
@@ -360,8 +360,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
-github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
@@ -567,8 +567,8 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxv
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
-github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
+github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
@@ -795,6 +795,7 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
+github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
@@ -825,8 +826,9 @@ github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJ
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
-github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
+github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
+github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
@@ -850,8 +852,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
@@ -1389,6 +1391,8 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/lightningtipbot/telebot.v3 v3.0.0-20220326213923-f323bb71ac8e h1:x58PfjVq6dbYSzM4URM9QfKDKVru1CpngxCM5pGqwbk=
gopkg.in/lightningtipbot/telebot.v3 v3.0.0-20220326213923-f323bb71ac8e/go.mod h1:kIC/Dlp2OjWhVrOkZDN4iEoCaqoac5w1UjpKY6Ftf+U=
+gopkg.in/lightningtipbot/telebot.v3 v3.0.0-20220828121412-0dea11ecc6dd h1:LI1Q9RRmTKusLTpLGAHFUVT+wgzc0GHFKd3+34fARE8=
+gopkg.in/lightningtipbot/telebot.v3 v3.0.0-20220828121412-0dea11ecc6dd/go.mod h1:BefN0q4hcqXE1jXo4mTXZ9+29zl7IGsoSFXEQF455Oc=
gopkg.in/macaroon-bakery.v2 v2.0.1/go.mod h1:B4/T17l+ZWGwxFSZQmlBwp25x+og7OkhETfr3S9MbIA=
gopkg.in/macaroon.v2 v2.0.0/go.mod h1:+I6LnTMkm/uV5ew/0nsulNjL16SK4+C8yDmRUzHR17I=
gopkg.in/mgo.v2 v2.0.0-20160818015218-f2b6f6c918c4/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
@@ -1413,8 +1417,8 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM=
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
diff --git a/internal/api/userpage/static/webapp.html b/internal/api/userpage/static/webapp.html
new file mode 100644
index 0000000..15e517d
--- /dev/null
+++ b/internal/api/userpage/static/webapp.html
@@ -0,0 +1,247 @@
+
+
+{{define "webapp"}}
+
+
+
+
+
+
+
+
+
+
+
+ LNURL
+
+
+
+
+
+
+
+
+
+ {{.Username}}@ln.tips
+
+
+
+
+
+
+
+
+
+
+
+
+{{end}}
\ No newline at end of file
diff --git a/internal/api/userpage/userpage.go b/internal/api/userpage/userpage.go
index f6c6865..9db0452 100644
--- a/internal/api/userpage/userpage.go
+++ b/internal/api/userpage/userpage.go
@@ -31,7 +31,8 @@ const botImage = "https://avatars.githubusercontent.com/u/88730856?v=7"
//go:embed static
var templates embed.FS
-var tmpl = template.Must(template.ParseFS(templates, "static/userpage.html"))
+var userpage_tmpl = template.Must(template.ParseFS(templates, "static/userpage.html"))
+var qr_tmpl = template.Must(template.ParseFS(templates, "static/webapp.html"))
var Client = &http.Client{
Timeout: 10 * time.Second,
@@ -67,7 +68,7 @@ func (s Service) getTelegramUserPictureURL(username string) (string, error) {
}
func (s Service) UserPageHandler(w http.ResponseWriter, r *http.Request) {
- // https://ln.tips/.well-known/lnurlp/
+ // https://ln.tips/@
username := strings.ToLower(mux.Vars(r)["username"])
callback := fmt.Sprintf("%s/.well-known/lnurlp/%s", internal.Configuration.Bot.LNURLHostName, username)
log.Infof("[UserPage] rendering page of %s", username)
@@ -82,7 +83,7 @@ func (s Service) UserPageHandler(w http.ResponseWriter, r *http.Request) {
image = botImage
}
- if err := tmpl.ExecuteTemplate(w, "userpage", struct {
+ if err := userpage_tmpl.ExecuteTemplate(w, "userpage", struct {
Username string
Image string
LNURLPay string
@@ -90,3 +91,21 @@ func (s Service) UserPageHandler(w http.ResponseWriter, r *http.Request) {
log.Errorf("failed to render template")
}
}
+
+func (s Service) UserWebAppHandler(w http.ResponseWriter, r *http.Request) {
+ // https://ln.tips/app/
+ username := strings.ToLower(mux.Vars(r)["username"])
+ callback := fmt.Sprintf("%s/.well-known/lnurlp/%s", internal.Configuration.Bot.LNURLHostName, username)
+ log.Infof("[UserPage] rendering page of %s", username)
+ lnurlEncode, err := lnurl.LNURLEncode(callback)
+ if err != nil {
+ log.Errorln("[UserPage]", err)
+ return
+ }
+ if err := qr_tmpl.ExecuteTemplate(w, "webapp", struct {
+ Username string
+ LNURLPay string
+ }{username, lnurlEncode}); err != nil {
+ log.Errorf("failed to render template")
+ }
+}
diff --git a/internal/rate/limiter.go b/internal/rate/limiter.go
index 6851a1d..f62a91d 100644
--- a/internal/rate/limiter.go
+++ b/internal/rate/limiter.go
@@ -2,10 +2,11 @@ package rate
import (
"context"
- log "github.com/sirupsen/logrus"
"strconv"
"sync"
+ log "github.com/sirupsen/logrus"
+
"golang.org/x/time/rate"
tb "gopkg.in/lightningtipbot/telebot.v3"
)
diff --git a/internal/telegram/amounts.go b/internal/telegram/amounts.go
index 7241a39..b1ad7ce 100644
--- a/internal/telegram/amounts.go
+++ b/internal/telegram/amounts.go
@@ -4,10 +4,11 @@ import (
"context"
"encoding/json"
"fmt"
- "github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
"strconv"
"strings"
+ "github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
+
"github.com/LightningTipBot/LightningTipBot/internal/errors"
"github.com/LightningTipBot/LightningTipBot/internal/runtime/mutex"
diff --git a/internal/telegram/balance.go b/internal/telegram/balance.go
index 1e898c4..5ac6a7c 100644
--- a/internal/telegram/balance.go
+++ b/internal/telegram/balance.go
@@ -2,6 +2,7 @@ package telegram
import (
"fmt"
+
"github.com/LightningTipBot/LightningTipBot/internal/errors"
"github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
diff --git a/internal/telegram/bot.go b/internal/telegram/bot.go
index a154c53..a059e24 100644
--- a/internal/telegram/bot.go
+++ b/internal/telegram/bot.go
@@ -63,6 +63,7 @@ func newTelegramBot() *tb.Bot {
Token: internal.Configuration.Telegram.ApiKey,
Poller: &tb.LongPoller{Timeout: 60 * time.Second},
ParseMode: tb.ModeMarkdown,
+ Verbose: false,
})
if err != nil {
panic(err)
diff --git a/internal/telegram/buttons.go b/internal/telegram/buttons.go
index 78c314e..1584490 100644
--- a/internal/telegram/buttons.go
+++ b/internal/telegram/buttons.go
@@ -3,7 +3,9 @@ package telegram
import (
"context"
"fmt"
+ "strings"
+ "github.com/LightningTipBot/LightningTipBot/internal"
"github.com/LightningTipBot/LightningTipBot/internal/lnbits"
log "github.com/sirupsen/logrus"
tb "gopkg.in/lightningtipbot/telebot.v3"
@@ -11,7 +13,7 @@ import (
// we can't use space in the label of buttons, because string splitting will mess everything up.
const (
- MainMenuCommandSend = "💸 Send"
+ MainMenuCommandWebApp = "⬇️ LNURL"
MainMenuCommandBalance = "Balance"
MainMenuCommandInvoice = "⚡️ Invoice"
MainMenuCommandHelp = "📖 Help"
@@ -21,7 +23,7 @@ const (
var (
mainMenu = &tb.ReplyMarkup{ResizeKeyboard: true}
btnHelpMainMenu = mainMenu.Text(MainMenuCommandHelp)
- btnSendMainMenu = mainMenu.Text(MainMenuCommandSend)
+ btnWebAppMainMenu = mainMenu.Text(MainMenuCommandWebApp)
btnBalanceMainMenu = mainMenu.Text(MainMenuCommandBalance)
btnInvoiceMainMenu = mainMenu.Text(MainMenuCommandInvoice)
@@ -31,9 +33,10 @@ var (
)
func init() {
+ btnBalanceMainMenu = mainMenu.Text(MainMenuCommandBalance)
mainMenu.Reply(
mainMenu.Row(btnBalanceMainMenu),
- mainMenu.Row(btnInvoiceMainMenu, btnSendMainMenu, btnHelpMainMenu),
+ mainMenu.Row(btnInvoiceMainMenu, btnWebAppMainMenu, btnHelpMainMenu),
)
}
@@ -58,6 +61,21 @@ func buttonWrapper(buttons []tb.Btn, markup *tb.ReplyMarkup, length int) []tb.Ro
return rows
}
+// appendWebAppLinkToButton adds a WebApp object to a Button with the user's webapp page
+func (bot *TipBot) appendWebAppLinkToButton(btn *tb.Btn, user *lnbits.User) {
+ var url string
+ if len(user.Telegram.Username) > 0 {
+ url = fmt.Sprintf("%s/app/@%s", internal.Configuration.Bot.LNURLHostName, user.Telegram.Username)
+ } else {
+ url = fmt.Sprintf("%s/app/@%s", internal.Configuration.Bot.LNURLHostName, user.AnonIDSha256)
+ }
+ if strings.HasPrefix(url, "https://") {
+ // prevent adding a link if not https is used, otherwise
+ // Telegram returns an error and does not show the keyboard
+ btn.WebApp = &tb.WebAppInfo{Url: url}
+ }
+}
+
// mainMenuBalanceButtonUpdate updates the balance button in the mainMenu
func (bot *TipBot) mainMenuBalanceButtonUpdate(to int64) {
var user *lnbits.User
@@ -75,11 +93,13 @@ func (bot *TipBot) mainMenuBalanceButtonUpdate(to int64) {
log.Tracef("[appendMainMenu] user %s balance %d sat", GetUserStr(user.Telegram), amount)
MainMenuCommandBalance := fmt.Sprintf("%s %d sat", MainMenuCommandBalance, amount)
btnBalanceMainMenu = mainMenu.Text(MainMenuCommandBalance)
- mainMenu.Reply(
- mainMenu.Row(btnBalanceMainMenu),
- mainMenu.Row(btnInvoiceMainMenu, btnSendMainMenu, btnHelpMainMenu),
- )
}
+
+ bot.appendWebAppLinkToButton(&btnWebAppMainMenu, user)
+ mainMenu.Reply(
+ mainMenu.Row(btnBalanceMainMenu),
+ mainMenu.Row(btnInvoiceMainMenu, btnWebAppMainMenu, btnHelpMainMenu),
+ )
}
}
@@ -98,7 +118,7 @@ func (bot *TipBot) makeContactsButtons(ctx context.Context) []tb.Btn {
// get all contacts and add them to the buttons
for i, r := range records {
log.Tracef("[makeContactsButtons] toNames[%d] = %s (id=%d)", i, r.ToUser, r.ID)
- sendToButtons = append(sendToButtons, tb.Btn{Text: fmt.Sprintf("%s", r.ToUser)})
+ sendToButtons = append(sendToButtons, tb.Btn{Text: r.ToUser})
}
// add the "enter a username" button to the end
diff --git a/internal/telegram/donate.go b/internal/telegram/donate.go
index 787a318..9d78313 100644
--- a/internal/telegram/donate.go
+++ b/internal/telegram/donate.go
@@ -3,12 +3,13 @@ package telegram
import (
"context"
"fmt"
- "github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
"io"
"io/ioutil"
"net/http"
"strings"
+ "github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
+
"github.com/LightningTipBot/LightningTipBot/internal/errors"
"github.com/LightningTipBot/LightningTipBot/internal/str"
diff --git a/internal/telegram/handler.go b/internal/telegram/handler.go
index fa042f9..df83723 100644
--- a/internal/telegram/handler.go
+++ b/internal/telegram/handler.go
@@ -245,23 +245,25 @@ func (bot TipBot) getHandler() []InterceptionWrapper {
},
},
},
- {
- Endpoints: []interface{}{&btnSendMainMenu},
- Handler: bot.keyboardSendHandler,
- Interceptor: &Interceptor{
+ // previously, this was the send menu but it
+ // was replaced with the webapp
+ // {
+ // Endpoints: []interface{}{&btnWebAppMainMenu},
+ // Handler: bot.keyboardSendHandler,
+ // Interceptor: &Interceptor{
- Before: []intercept.Func{
- bot.localizerInterceptor,
- bot.logMessageInterceptor,
- bot.requireUserInterceptor,
- bot.loadReplyToInterceptor,
- bot.lockInterceptor,
- },
- OnDefer: []intercept.Func{
- bot.unlockInterceptor,
- },
- },
- },
+ // Before: []intercept.Func{
+ // bot.localizerInterceptor,
+ // bot.logMessageInterceptor,
+ // bot.requireUserInterceptor,
+ // bot.loadReplyToInterceptor,
+ // bot.lockInterceptor,
+ // },
+ // OnDefer: []intercept.Func{
+ // bot.unlockInterceptor,
+ // },
+ // },
+ // },
{
Endpoints: []interface{}{"/transactions"},
Handler: bot.transactionsHandler,
@@ -430,6 +432,22 @@ func (bot TipBot) getHandler() []InterceptionWrapper {
},
},
},
+ {
+ Endpoints: []interface{}{&btnWebAppStart},
+ Handler: bot.webAppButtonHandler,
+ Interceptor: &Interceptor{
+
+ Before: []intercept.Func{
+ bot.localizerInterceptor,
+ bot.requireUserInterceptor,
+ bot.answerCallbackInterceptor,
+ bot.lockInterceptor,
+ },
+ OnDefer: []intercept.Func{
+ bot.unlockInterceptor,
+ },
+ },
+ },
{
Endpoints: []interface{}{"/lnurl"},
Handler: bot.lnurlHandler,
diff --git a/internal/telegram/lnurl.go b/internal/telegram/lnurl.go
index 4e4ecfb..334f5fb 100644
--- a/internal/telegram/lnurl.go
+++ b/internal/telegram/lnurl.go
@@ -144,7 +144,7 @@ func UserGetLNURL(user *lnbits.User) (string, error) {
}
func UserGetAnonLNURL(user *lnbits.User) (string, error) {
- callback := fmt.Sprintf("%s/.well-known/lnurlp/%s", internal.Configuration.Bot.LNURLHostName, fmt.Sprint(user.AnonIDSha256))
+ callback := fmt.Sprintf("%s/.well-known/lnurlp/%s", internal.Configuration.Bot.LNURLHostName, user.AnonIDSha256)
lnurlEncode, err := lnurl.LNURLEncode(callback)
if err != nil {
return "", err
diff --git a/internal/telegram/photo.go b/internal/telegram/photo.go
index fd91475..d10eb6c 100644
--- a/internal/telegram/photo.go
+++ b/internal/telegram/photo.go
@@ -4,11 +4,12 @@ import (
"bytes"
"encoding/json"
"fmt"
- "github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
"image"
"image/jpeg"
"strings"
+ "github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
+
"github.com/LightningTipBot/LightningTipBot/internal/errors"
"github.com/LightningTipBot/LightningTipBot/pkg/lightning"
diff --git a/internal/telegram/shop_helpers.go b/internal/telegram/shop_helpers.go
index 3cb52ed..db71f27 100644
--- a/internal/telegram/shop_helpers.go
+++ b/internal/telegram/shop_helpers.go
@@ -2,6 +2,8 @@ package telegram
import (
"fmt"
+ "time"
+
"github.com/LightningTipBot/LightningTipBot/internal/lnbits"
"github.com/LightningTipBot/LightningTipBot/internal/runtime"
"github.com/LightningTipBot/LightningTipBot/internal/runtime/mutex"
@@ -10,7 +12,6 @@ import (
"github.com/eko/gocache/store"
log "github.com/sirupsen/logrus"
tb "gopkg.in/lightningtipbot/telebot.v3"
- "time"
)
func (bot TipBot) shopsMainMenu(ctx intercept.Context, shops *Shops) *tb.ReplyMarkup {
diff --git a/internal/telegram/start.go b/internal/telegram/start.go
index f31a67e..3f32595 100644
--- a/internal/telegram/start.go
+++ b/internal/telegram/start.go
@@ -4,10 +4,11 @@ import (
"context"
stderrors "errors"
"fmt"
- "github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
"strconv"
"time"
+ "github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
+
"github.com/LightningTipBot/LightningTipBot/internal/errors"
"github.com/LightningTipBot/LightningTipBot/internal"
diff --git a/internal/telegram/text.go b/internal/telegram/text.go
index 37929fc..d4eaacf 100644
--- a/internal/telegram/text.go
+++ b/internal/telegram/text.go
@@ -4,9 +4,10 @@ import (
"context"
"encoding/json"
"fmt"
+ "strings"
+
"github.com/LightningTipBot/LightningTipBot/internal/errors"
"github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
- "strings"
"github.com/LightningTipBot/LightningTipBot/internal/lnbits"
"github.com/LightningTipBot/LightningTipBot/pkg/lightning"
diff --git a/main.go b/main.go
index a85c8be..0aa1cf7 100644
--- a/main.go
+++ b/main.go
@@ -57,6 +57,7 @@ func startApiServer(bot *telegram.TipBot) {
// userpage server
userpage := userpage.New(bot)
s.AppendRoute("/@{username}", userpage.UserPageHandler, http.MethodGet)
+ s.AppendRoute("/app/@{username}", userpage.UserWebAppHandler, http.MethodGet)
// append lndhub ctx functions
hub := lndhub.New(bot)