Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

chore: upgrade Fiber to v3 (#764)

Aldino Kemalbbfe75ca49e0
diff --git a/.gitignore b/.gitignore
index decba309..38168fe1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,5 +38,8 @@ tmp/
# Worktrees
.worktrees/
+# Local Superpowers planning artifacts
+docs/superpowers/
+
# whatsmeow store (legacy path)
src/whatsapp/
diff --git a/src/cmd/rest.go b/src/cmd/rest.go
index cf4bac0b..7ec81e05 100644
--- a/src/cmd/rest.go
+++ b/src/cmd/rest.go
@@ -2,6 +2,7 @@ package cmd
import (
"context"
+ "crypto/subtle"
"fmt"
"net/http"
"os"
@@ -18,11 +19,11 @@ import (
"github.com/aldinokemal/go-whatsapp-web-multidevice/ui/rest/middleware"
"github.com/aldinokemal/go-whatsapp-web-multidevice/ui/websocket"
"github.com/dustin/go-humanize"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/fiber/v2/middleware/basicauth"
- "github.com/gofiber/fiber/v2/middleware/cors"
- "github.com/gofiber/fiber/v2/middleware/filesystem"
- "github.com/gofiber/fiber/v2/middleware/logger"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/fiber/v3/middleware/basicauth"
+ "github.com/gofiber/fiber/v3/middleware/cors"
+ "github.com/gofiber/fiber/v3/middleware/logger"
+ "github.com/gofiber/fiber/v3/middleware/static"
"github.com/gofiber/template/html/v2"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@@ -45,30 +46,27 @@ func restServer(_ *cobra.Command, _ []string) {
return token != nil
})
fiberConfig := fiber.Config{
- Views: engine,
- EnableTrustedProxyCheck: true,
- BodyLimit: int(config.WhatsappSettingMaxVideoSize),
- Network: "tcp",
+ Views: engine,
+ TrustProxy: true,
+ BodyLimit: int(config.WhatsappSettingMaxVideoSize),
}
// Configure proxy settings if trusted proxies are specified
if len(config.AppTrustedProxies) > 0 {
- fiberConfig.TrustedProxies = config.AppTrustedProxies
+ fiberConfig.TrustProxyConfig = fiber.TrustProxyConfig{Proxies: config.AppTrustedProxies}
fiberConfig.ProxyHeader = fiber.HeaderXForwardedHost
}
app := fiber.New(fiberConfig)
- app.Static(config.AppBasePath+"/statics", "./statics")
- app.Use(config.AppBasePath+"/components", filesystem.New(filesystem.Config{
- Root: http.FS(EmbedViews),
- PathPrefix: "views/components",
- Browse: true,
+ app.Use(config.AppBasePath+"/statics", static.New("./statics"))
+ app.Use(config.AppBasePath+"/components", static.New("views/components", static.Config{
+ FS: EmbedViews,
+ Browse: true,
}))
- app.Use(config.AppBasePath+"/assets", filesystem.New(filesystem.Config{
- Root: http.FS(EmbedViews),
- PathPrefix: "views/assets",
- Browse: true,
+ app.Use(config.AppBasePath+"/assets", static.New("views/assets", static.Config{
+ FS: EmbedViews,
+ Browse: true,
}))
app.Use(middleware.Recovery())
@@ -78,8 +76,8 @@ func restServer(_ *cobra.Command, _ []string) {
app.Use(logger.New())
}
app.Use(cors.New(cors.Config{
- AllowOrigins: "*",
- AllowHeaders: "Origin, Content-Type, Accept",
+ AllowOrigins: []string{"*"},
+ AllowHeaders: []string{"Origin", "Content-Type", "Accept"},
}))
// Device manager - needed for chatwoot webhook and health check
@@ -88,7 +86,7 @@ func restServer(_ *cobra.Command, _ []string) {
// Health check endpoint (public, no auth)
// Registered at root path (ignoring AppBasePath) to ensure fixed availability
// for infrastructure health probes (Kubernetes liveness/readiness, Docker healthcheck, etc.)
- app.Get("/health", func(c *fiber.Ctx) error {
+ app.Get("/health", func(c fiber.Ctx) error {
if dm != nil && dm.IsHealthy() {
return c.SendString("OK")
}
@@ -125,9 +123,7 @@ func restServer(_ *cobra.Command, _ []string) {
account[ba[0]] = ba[1]
}
- app.Use(basicauth.New(basicauth.Config{
- Users: account,
- }))
+ app.Use(newBasicAuthMiddleware(account))
}
// Create base path group or use app directly
@@ -166,12 +162,12 @@ func restServer(_ *cobra.Command, _ []string) {
apiGroup.Delete("/devices/:device_id/chatwoot/config", chatwootHandler.DeleteChatwootConfig)
}
- apiGroup.Get("/", func(c *fiber.Ctx) error {
+ apiGroup.Get("/", func(c fiber.Ctx) error {
return c.Render("views/index", fiber.Map{
- "AppHost": fmt.Sprintf("%s://%s", c.Protocol(), c.Hostname()),
+ "AppHost": fmt.Sprintf("%s://%s", c.Scheme(), c.Hostname()),
"AppVersion": config.AppVersion,
"AppBasePath": config.AppBasePath,
- "BasicAuthToken": c.UserContext().Value(middleware.AuthorizationValue("BASIC_AUTH")),
+ "BasicAuthToken": c.Context().Value(middleware.AuthorizationValue("BASIC_AUTH")),
"MaxFileSize": humanize.Bytes(uint64(config.WhatsappSettingMaxFileSize)),
"MaxVideoSize": humanize.Bytes(uint64(config.WhatsappSettingMaxVideoSize)),
})
@@ -194,7 +190,7 @@ func restServer(_ *cobra.Command, _ []string) {
// the chat storage DB connection.
listenErr := make(chan error, 1)
go func() {
- listenErr <- app.Listen(config.AppHost + ":" + config.AppPort)
+ listenErr <- app.Listen(config.AppHost+":"+config.AppPort, fiber.ListenConfig{ListenerNetwork: "tcp"})
}()
sigCh := make(chan os.Signal, 1)
@@ -224,3 +220,16 @@ func restServer(_ *cobra.Command, _ []string) {
}
}
}
+
+func newBasicAuthMiddleware(accounts map[string]string) fiber.Handler {
+ return basicauth.New(basicauth.Config{
+ Authorizer: func(username, password string, _ fiber.Ctx) bool {
+ expectedPassword, ok := accounts[username]
+ if !ok {
+ return false
+ }
+
+ return subtle.ConstantTimeCompare([]byte(password), []byte(expectedPassword)) == 1
+ },
+ })
+}
diff --git a/src/cmd/rest_test.go b/src/cmd/rest_test.go
new file mode 100644
index 00000000..6b05ed09
--- /dev/null
+++ b/src/cmd/rest_test.go
@@ -0,0 +1,55 @@
+package cmd
+
+import (
+ "net/http/httptest"
+ "testing"
+
+ "github.com/gofiber/fiber/v3"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestBasicAuthMiddleware(t *testing.T) {
+ tests := []struct {
+ name string
+ username string
+ password string
+ wantStatus int
+ }{
+ {
+ name: "accepts configured plaintext credential",
+ username: "user",
+ password: "secret",
+ wantStatus: fiber.StatusOK,
+ },
+ {
+ name: "rejects wrong password",
+ username: "user",
+ password: "wrong",
+ wantStatus: fiber.StatusUnauthorized,
+ },
+ {
+ name: "rejects unknown user",
+ username: "unknown",
+ password: "secret",
+ wantStatus: fiber.StatusUnauthorized,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ app := fiber.New()
+ app.Use(newBasicAuthMiddleware(map[string]string{"user": "secret"}))
+ app.Get("/", func(c fiber.Ctx) error {
+ return c.SendStatus(fiber.StatusOK)
+ })
+
+ req := httptest.NewRequest("GET", "/", nil)
+ req.SetBasicAuth(tt.username, tt.password)
+
+ resp, err := app.Test(req)
+ require.NoError(t, err)
+ assert.Equal(t, tt.wantStatus, resp.StatusCode)
+ })
+ }
+}
diff --git a/src/go.mod b/src/go.mod
index ca93f5a1..f399b182 100644
--- a/src/go.mod
+++ b/src/go.mod
@@ -8,9 +8,10 @@ require (
github.com/disintegration/imaging v1.6.2
github.com/dustin/go-humanize v1.0.1
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
- github.com/gofiber/fiber/v2 v2.52.14
+ github.com/gofiber/contrib/v3/websocket v1.2.1
+ github.com/gofiber/fiber/v3 v3.4.0
github.com/gofiber/template/html/v2 v2.1.3
- github.com/gofiber/websocket/v2 v2.2.1
+ github.com/gofiber/utils/v2 v2.1.2
github.com/google/uuid v1.6.0
github.com/lib/pq v1.12.3
github.com/mark3labs/mcp-go v0.56.0
@@ -34,13 +35,13 @@ require (
github.com/andybalholm/cascadia v1.3.4 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beeper/argo-go v1.1.2 // indirect
- github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
github.com/coder/websocket v1.8.15 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/elliotchance/orderedmap/v3 v3.1.1 // indirect
github.com/fasthttp/websocket v1.5.12 // indirect
github.com/fsnotify/fsnotify v1.10.1 // indirect
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
+ github.com/gofiber/schema v1.8.0 // indirect
github.com/gofiber/template v1.8.3 // indirect
github.com/gofiber/utils v1.2.0 // indirect
github.com/google/jsonschema-go v0.4.3 // indirect
@@ -48,10 +49,10 @@ require (
github.com/klauspost/compress v1.19.0 // indirect
github.com/mattn/go-colorable v0.1.15 // indirect
github.com/mattn/go-isatty v0.0.22 // indirect
- github.com/mattn/go-runewidth v0.0.24 // indirect
github.com/ncruces/go-strftime v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.4.3 // indirect
github.com/petermattis/goid v0.0.0-20260713124913-97594f28f5ca // indirect
+ github.com/philhofer/fwd v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rs/zerolog v1.35.1 // indirect
@@ -62,6 +63,7 @@ require (
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
+ github.com/tinylib/msgp v1.6.4 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/vektah/gqlparser/v2 v2.5.36 // indirect
github.com/xyproto/randomstring v1.2.0 // indirect
diff --git a/src/go.sum b/src/go.sum
index 6ceb0477..c4afbc5c 100644
--- a/src/go.sum
+++ b/src/go.sum
@@ -15,8 +15,6 @@ github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3d
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/beeper/argo-go v1.1.2 h1:UQI2G8F+NLfGTOmTUI0254pGKx/HUU/etbUGTJv91Fs=
github.com/beeper/argo-go v1.1.2/go.mod h1:M+LJAnyowKVQ6Rdj6XYGEn+qcVFkb3R/MUpqkGR0hM4=
-github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk=
-github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
github.com/coder/websocket v1.8.15 h1:6B2JPeOGlpff2Uz6vOEH1Vzpi0iUz20A+lPVhPHtNUA=
github.com/coder/websocket v1.8.15/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
@@ -37,20 +35,26 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.10.1 h1:b0/UzAf9yR5rhf3RPm9gf3ehBPpf0oZKIjtpKrx59Ho=
github.com/fsnotify/fsnotify v1.10.1/go.mod h1:TLheqan6HD6GBK6PrDWyDPBaEV8LspOxvPSjC+bVfgo=
+github.com/fxamacker/cbor/v2 v2.9.2 h1:X4Ksno9+x3cz0TZv69ec1hxP/+tymuR8PXQJyDwfh78=
+github.com/fxamacker/cbor/v2 v2.9.2/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 h1:byhDUpfEwjsVQb1vBunvIjh2BHQ9ead57VkAEY4V+Es=
github.com/go-ozzo/ozzo-validation/v4 v4.3.0/go.mod h1:2NKgrcHl3z6cJs+3Oo940FPRiTzuqKbvfrL2RxCj6Ew=
github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro=
github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
-github.com/gofiber/fiber/v2 v2.52.14 h1:Of3L+9qVFaQNwPlcmEdl5IIodHz8BSE0j37R7rWu4pE=
-github.com/gofiber/fiber/v2 v2.52.14/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
+github.com/gofiber/contrib/v3/websocket v1.2.1 h1:E4I1dVCvNF56ELdKksUJilo1r7dpw7lgt1DmsJd7hOo=
+github.com/gofiber/contrib/v3/websocket v1.2.1/go.mod h1:rQO2z0SbC/l8lP36gXTKrD1QZBXzHKwt9E8c5em1IiA=
+github.com/gofiber/fiber/v3 v3.4.0 h1:F0aND4vwZF7dR7cbvSwFQQEpBU902XHKWxrLsFBkVqw=
+github.com/gofiber/fiber/v3 v3.4.0/go.mod h1:nAhJfdxUIJJph2tPWPmqWf8QDIN2iiqQiQf3lENZpdk=
+github.com/gofiber/schema v1.8.0 h1:NGsC9toPHmj8Xg4KpznuXBzNmHG6V5YV0tXKpKMcmis=
+github.com/gofiber/schema v1.8.0/go.mod h1:lmbXPQ8hvzXSLkdS2DS7pb4kpunC2Roh7Sj3HMjGfzA=
github.com/gofiber/template v1.8.3 h1:hzHdvMwMo/T2kouz2pPCA0zGiLCeMnoGsQZBTSYgZxc=
github.com/gofiber/template v1.8.3/go.mod h1:bs/2n0pSNPOkRa5VJ8zTIvedcI/lEYxzV3+YPXdBvq8=
github.com/gofiber/template/html/v2 v2.1.3 h1:n1LYBtmr9C0V/k/3qBblXyMxV5B0o/gpb6dFLp8ea+o=
github.com/gofiber/template/html/v2 v2.1.3/go.mod h1:U5Fxgc5KpyujU9OqKzy6Kn6Qup6Tm7zdsISR+VpnHRE=
github.com/gofiber/utils v1.2.0 h1:NCaqd+Efg3khhN++eeUUTyBz+byIxAsmIjpl8kKOMIc=
github.com/gofiber/utils v1.2.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
-github.com/gofiber/websocket/v2 v2.2.1 h1:C9cjxvloojayOp9AovmpQrk8VqvVnT8Oao3+IUygH7w=
-github.com/gofiber/websocket/v2 v2.2.1/go.mod h1:Ao/+nyNnX5u/hIFPuHl28a+NIkrqK7PRimyKaj4JxVU=
+github.com/gofiber/utils/v2 v2.1.2 h1:/rfkCHvC3XWfOHR04c34KajAhbs5QxmF6cNeJKnkEBI=
+github.com/gofiber/utils/v2 v2.1.2/go.mod h1:DdOgEVwQTi8cou/AKWPqhXOR4fHGRVhA/rEWL3IXG7Q=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/jsonschema-go v0.4.3 h1:/DBOLZTfDow7pe2GmaJNhltueGTtDKICi8V8p+DQPd0=
@@ -78,8 +82,6 @@ github.com/mattn/go-colorable v0.1.15 h1:+u9SLTRGnXv73cEsnsmoZBom+dMU88B2M0aDcWy
github.com/mattn/go-colorable v0.1.15/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4=
github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
-github.com/mattn/go-runewidth v0.0.24 h1:cpokDiIn0MGnhdHwuWnJBITySJ20QyNGnY2kR/ay2DU=
-github.com/mattn/go-runewidth v0.0.24/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
github.com/mattn/go-sqlite3 v1.14.48 h1:7XHIgl0a8HwOaiK4E47ozLkST78rR9+OtNGx27D/TFs=
github.com/mattn/go-sqlite3 v1.14.48/go.mod h1:6JTjA44L93a0QCyJef5YvlPoKXntQPjzWv5gtm9sB6w=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
@@ -88,13 +90,15 @@ github.com/pelletier/go-toml/v2 v2.4.3 h1:GTRvJQutkOSftxIFD5xw9aepkYNuPWmVJpffdD
github.com/pelletier/go-toml/v2 v2.4.3/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/petermattis/goid v0.0.0-20260713124913-97594f28f5ca h1:GHSUVE4yOgX4E7kTRzpxCPbCOYkd3Kj8Dgdod30OI1E=
github.com/petermattis/goid v0.0.0-20260713124913-97594f28f5ca/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
+github.com/philhofer/fwd v1.2.0 h1:e6DnBTl7vGY+Gz322/ASL4Gyp1FspeMvx1RNDoToZuM=
+github.com/philhofer/fwd v1.2.0/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
-github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
-github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
+github.com/rogpeppe/go-internal v1.15.0 h1:D0RCU5rMAp+SpgkiNdrjfJ+LX4J1M32V2NeCY7EJ6hc=
+github.com/rogpeppe/go-internal v1.15.0/go.mod h1:DrUVZyrJU+txYW5/1kwtXQSMFio52ZOxX7yM1VHvnxs=
github.com/rs/zerolog v1.35.1 h1:m7xQeoiLIiV0BCEY4Hs+j2NG4Gp2o2KPKmhnnLiazKI=
github.com/rs/zerolog v1.35.1/go.mod h1:EjML9kdfa/RMA7h/6z6pYmq1ykOuA8/mjWaEvGI+jcw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
@@ -104,6 +108,8 @@ github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 h1:KRzFb2m7YtdldCEkzs6KqmJw4nqEV
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
github.com/savsgio/gotils v0.0.0-20250924091648-bce9a52d7761 h1:McifyVxygw1d67y6vxUqls2D46J8W9nrki9c8c0eVvE=
github.com/savsgio/gotils v0.0.0-20250924091648-bce9a52d7761/go.mod h1:Vi9gvHvTw4yCUHIznFl5TPULS7aXwgaTByGeBY75Wko=
+github.com/shamaton/msgpack/v3 v3.1.2 h1:d5gWAIyMU4M0WgDjz6IFSCuXJUA2dFwRHBpDclE8CLw=
+github.com/shamaton/msgpack/v3 v3.1.2/go.mod h1:DcQG8jrdrQCIxr3HlMYkiXdMhK+KfN2CitkyzsQV4uc=
github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w=
github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
@@ -125,12 +131,16 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
+github.com/tinylib/msgp v1.6.4 h1:mOwYbyYDLPj35mkA2BjjYejgJk9BuHxDdvRnb6v2ZcQ=
+github.com/tinylib/msgp v1.6.4/go.mod h1:RSp0LW9oSxFut3KzESt5Voq4GVWyS+PSulT77roAqEA=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.72.0 h1:R7kYdoWhn1ye1fVpP+cDHDJwYm3NkwLliwgzJ/Abg7M=
github.com/valyala/fasthttp v1.72.0/go.mod h1:zsbLTYqcpIktdQytlVBwIjY9La5d6bs990nBxWg8efk=
github.com/vektah/gqlparser/v2 v2.5.36 h1:CN9mKVHgMkc+XftdOWIhb4HEL8wKSYkFAqhf8booa7s=
github.com/vektah/gqlparser/v2 v2.5.36/go.mod h1:cAJ9qwVgPaUkWv6Gn8vn0mqOE0Ui5Pn56wNy5396XWo=
+github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
+github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xyproto/randomstring v1.2.0 h1:y7PXAEBM3XlwJjPG2JQg4voxBYZ4+hPgRdGKCfU8wik=
github.com/xyproto/randomstring v1.2.0/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
diff --git a/src/infrastructure/whatsapp/device_manager.go b/src/infrastructure/whatsapp/device_manager.go
index 465afe53..f07285fe 100644
--- a/src/infrastructure/whatsapp/device_manager.go
+++ b/src/infrastructure/whatsapp/device_manager.go
@@ -13,7 +13,7 @@ import (
domainChatStorage "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chatstorage"
domainDevice "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/device"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/chatwoot"
- fiberUtils "github.com/gofiber/fiber/v2/utils"
+ fiberUtils "github.com/gofiber/utils/v2"
"github.com/sirupsen/logrus"
"go.mau.fi/whatsmeow"
"go.mau.fi/whatsmeow/store"
diff --git a/src/pkg/utils/response.go b/src/pkg/utils/response.go
index aa202872..52120aed 100644
--- a/src/pkg/utils/response.go
+++ b/src/pkg/utils/response.go
@@ -1,7 +1,7 @@
package utils
import (
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
type ResponseData struct {
@@ -11,7 +11,7 @@ type ResponseData struct {
Results any `json:"results,omitempty"`
}
-func ResponseError(c *fiber.Ctx, message string) error {
+func ResponseError(c fiber.Ctx, message string) error {
return c.Status(fiber.StatusBadRequest).JSON(ResponseData{
Code: "INVALID_REQUEST",
Message: message,
diff --git a/src/ui/rest/app.go b/src/ui/rest/app.go
index 52969c35..18c9347c 100644
--- a/src/ui/rest/app.go
+++ b/src/ui/rest/app.go
@@ -7,7 +7,7 @@ import (
domainApp "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/app"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
"go.mau.fi/whatsmeow/types"
)
@@ -30,13 +30,13 @@ func InitRestApp(app fiber.Router, service domainApp.IAppUsecase) App {
return App{Service: service}
}
-func (handler *App) Login(c *fiber.Ctx) error {
+func (handler *App) Login(c fiber.Ctx) error {
device, err := getDeviceInstance(c)
if err != nil {
return err
}
- response, err := handler.Service.Login(c.UserContext(), device.ID())
+ response, err := handler.Service.Login(c.Context(), device.ID())
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -45,19 +45,19 @@ func (handler *App) Login(c *fiber.Ctx) error {
Message: "Login success",
Results: map[string]any{
"device_id": device.ID(),
- "qr_link": fmt.Sprintf("%s://%s%s/%s", c.Protocol(), c.Hostname(), config.AppBasePath, response.ImagePath),
+ "qr_link": fmt.Sprintf("%s://%s%s/%s", c.Scheme(), c.Hostname(), config.AppBasePath, response.ImagePath),
"qr_duration": response.Duration,
},
})
}
-func (handler *App) LoginWithCode(c *fiber.Ctx) error {
+func (handler *App) LoginWithCode(c fiber.Ctx) error {
device, err := getDeviceInstance(c)
if err != nil {
return err
}
- pairCode, err := handler.Service.LoginWithCode(c.UserContext(), device.ID(), c.Query("phone"))
+ pairCode, err := handler.Service.LoginWithCode(c.Context(), device.ID(), c.Query("phone"))
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -71,13 +71,13 @@ func (handler *App) LoginWithCode(c *fiber.Ctx) error {
})
}
-func (handler *App) PasskeyChallenge(c *fiber.Ctx) error {
+func (handler *App) PasskeyChallenge(c fiber.Ctx) error {
device, err := getDeviceInstance(c)
if err != nil {
return err
}
- response, err := handler.Service.PasskeyChallenge(c.UserContext(), device.ID())
+ response, err := handler.Service.PasskeyChallenge(c.Context(), device.ID())
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -94,18 +94,18 @@ func (handler *App) PasskeyChallenge(c *fiber.Ctx) error {
})
}
-func (handler *App) PasskeyResponse(c *fiber.Ctx) error {
+func (handler *App) PasskeyResponse(c fiber.Ctx) error {
device, err := getDeviceInstance(c)
if err != nil {
return err
}
var assertion types.WebAuthnResponse
- if err := c.BodyParser(&assertion); err != nil {
+ if err := c.Bind().Body(&assertion); err != nil {
return fiber.NewError(fiber.StatusBadRequest, "invalid WebAuthn assertion payload: "+err.Error())
}
- err = handler.Service.PasskeyResponse(c.UserContext(), device.ID(), &assertion)
+ err = handler.Service.PasskeyResponse(c.Context(), device.ID(), &assertion)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -116,13 +116,13 @@ func (handler *App) PasskeyResponse(c *fiber.Ctx) error {
})
}
-func (handler *App) PasskeyConfirm(c *fiber.Ctx) error {
+func (handler *App) PasskeyConfirm(c fiber.Ctx) error {
device, err := getDeviceInstance(c)
if err != nil {
return err
}
- err = handler.Service.PasskeyConfirm(c.UserContext(), device.ID())
+ err = handler.Service.PasskeyConfirm(c.Context(), device.ID())
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -133,13 +133,13 @@ func (handler *App) PasskeyConfirm(c *fiber.Ctx) error {
})
}
-func (handler *App) Logout(c *fiber.Ctx) error {
+func (handler *App) Logout(c fiber.Ctx) error {
device, err := getDeviceInstance(c)
if err != nil {
return err
}
- err = handler.Service.Logout(c.UserContext(), device.ID())
+ err = handler.Service.Logout(c.Context(), device.ID())
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -150,13 +150,13 @@ func (handler *App) Logout(c *fiber.Ctx) error {
})
}
-func (handler *App) Reconnect(c *fiber.Ctx) error {
+func (handler *App) Reconnect(c fiber.Ctx) error {
device, err := getDeviceInstance(c)
if err != nil {
return err
}
- err = handler.Service.Reconnect(c.UserContext(), device.ID())
+ err = handler.Service.Reconnect(c.Context(), device.ID())
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -167,8 +167,8 @@ func (handler *App) Reconnect(c *fiber.Ctx) error {
})
}
-func (handler *App) Devices(c *fiber.Ctx) error {
- devices, err := handler.Service.FetchDevices(c.UserContext())
+func (handler *App) Devices(c fiber.Ctx) error {
+ devices, err := handler.Service.FetchDevices(c.Context())
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -179,13 +179,13 @@ func (handler *App) Devices(c *fiber.Ctx) error {
})
}
-func (handler *App) ConnectionStatus(c *fiber.Ctx) error {
+func (handler *App) ConnectionStatus(c fiber.Ctx) error {
device, err := getDeviceInstance(c)
if err != nil {
return err
}
- isConnected, isLoggedIn, err := handler.Service.Status(c.UserContext(), device.ID())
+ isConnected, isLoggedIn, err := handler.Service.Status(c.Context(), device.ID())
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -201,7 +201,7 @@ func (handler *App) ConnectionStatus(c *fiber.Ctx) error {
})
}
-func getDeviceInstance(c *fiber.Ctx) (*whatsapp.DeviceInstance, error) {
+func getDeviceInstance(c fiber.Ctx) (*whatsapp.DeviceInstance, error) {
value := c.Locals("device")
if value == nil {
return nil, fiber.NewError(fiber.StatusBadRequest, "device context is missing")
diff --git a/src/ui/rest/call.go b/src/ui/rest/call.go
index 730248c1..b65c888b 100644
--- a/src/ui/rest/call.go
+++ b/src/ui/rest/call.go
@@ -4,7 +4,7 @@ import (
domainCall "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/call"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
type Call struct {
@@ -17,13 +17,13 @@ func InitRestCall(app fiber.Router, service domainCall.ICallUsecase) Call {
return rest
}
-func (controller *Call) RejectCall(c *fiber.Ctx) error {
+func (controller *Call) RejectCall(c fiber.Ctx) error {
var request domainCall.RejectCallRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
err = controller.Service.RejectCall(
- whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)),
+ whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)),
request.CallerJID,
request.CallID,
)
diff --git a/src/ui/rest/chat.go b/src/ui/rest/chat.go
index 93825589..5a4dd669 100644
--- a/src/ui/rest/chat.go
+++ b/src/ui/rest/chat.go
@@ -4,7 +4,7 @@ import (
domainChat "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chat"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
type Chat struct {
@@ -24,20 +24,20 @@ func InitRestChat(app fiber.Router, service domainChat.IChatUsecase) Chat {
return rest
}
-func (controller *Chat) ListChats(c *fiber.Ctx) error {
+func (controller *Chat) ListChats(c fiber.Ctx) error {
var request domainChat.ListChatsRequest
// Parse query parameters
- request.Limit = c.QueryInt("limit", 25)
- request.Offset = c.QueryInt("offset", 0)
+ request.Limit = fiber.Query[int](c, "limit", 25)
+ request.Offset = fiber.Query[int](c, "offset", 0)
request.Search = c.Query("search", "")
- request.HasMedia = c.QueryBool("has_media", false)
+ request.HasMedia = fiber.Query[bool](c, "has_media", false)
if archivedStr := c.Query("archived"); archivedStr != "" {
- isArchived := c.QueryBool("archived")
+ isArchived := fiber.Query[bool](c, "archived")
request.Archived = &isArchived
}
- response, err := controller.Service.ListChats(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.ListChats(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -48,16 +48,16 @@ func (controller *Chat) ListChats(c *fiber.Ctx) error {
})
}
-func (controller *Chat) GetChatMessages(c *fiber.Ctx) error {
+func (controller *Chat) GetChatMessages(c fiber.Ctx) error {
var request domainChat.GetChatMessagesRequest
// Parse path parameter
request.ChatJID = c.Params("chat_jid")
// Parse query parameters
- request.Limit = c.QueryInt("limit", 50)
- request.Offset = c.QueryInt("offset", 0)
- request.MediaOnly = c.QueryBool("media_only", false)
+ request.Limit = fiber.Query[int](c, "limit", 50)
+ request.Offset = fiber.Query[int](c, "offset", 0)
+ request.MediaOnly = fiber.Query[bool](c, "media_only", false)
request.Search = c.Query("search", "")
// Parse time filters
@@ -70,11 +70,11 @@ func (controller *Chat) GetChatMessages(c *fiber.Ctx) error {
// Parse is_from_me filter
if isFromMeStr := c.Query("is_from_me"); isFromMeStr != "" {
- isFromMe := c.QueryBool("is_from_me")
+ isFromMe := fiber.Query[bool](c, "is_from_me")
request.IsFromMe = &isFromMe
}
- response, err := controller.Service.GetChatMessages(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.GetChatMessages(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -85,14 +85,14 @@ func (controller *Chat) GetChatMessages(c *fiber.Ctx) error {
})
}
-func (controller *Chat) PinChat(c *fiber.Ctx) error {
+func (controller *Chat) PinChat(c fiber.Ctx) error {
var request domainChat.PinChatRequest
// Parse path parameter
request.ChatJID = c.Params("chat_jid")
// Parse JSON body
- if err := c.BodyParser(&request); err != nil {
+ if err := c.Bind().Body(&request); err != nil {
return c.Status(400).JSON(utils.ResponseData{
Status: 400,
Code: "BAD_REQUEST",
@@ -101,7 +101,7 @@ func (controller *Chat) PinChat(c *fiber.Ctx) error {
})
}
- response, err := controller.Service.PinChat(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.PinChat(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -112,14 +112,14 @@ func (controller *Chat) PinChat(c *fiber.Ctx) error {
})
}
-func (controller *Chat) SetDisappearingTimer(c *fiber.Ctx) error {
+func (controller *Chat) SetDisappearingTimer(c fiber.Ctx) error {
var request domainChat.SetDisappearingTimerRequest
// Parse path parameter
request.ChatJID = c.Params("chat_jid")
// Parse JSON body
- if err := c.BodyParser(&request); err != nil {
+ if err := c.Bind().Body(&request); err != nil {
return c.Status(400).JSON(utils.ResponseData{
Status: 400,
Code: "BAD_REQUEST",
@@ -128,7 +128,7 @@ func (controller *Chat) SetDisappearingTimer(c *fiber.Ctx) error {
})
}
- response, err := controller.Service.SetDisappearingTimer(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.SetDisappearingTimer(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -139,14 +139,14 @@ func (controller *Chat) SetDisappearingTimer(c *fiber.Ctx) error {
})
}
-func (controller *Chat) ArchiveChat(c *fiber.Ctx) error {
+func (controller *Chat) ArchiveChat(c fiber.Ctx) error {
var request domainChat.ArchiveChatRequest
// Parse path parameter
request.ChatJID = c.Params("chat_jid")
// Parse JSON body
- if err := c.BodyParser(&request); err != nil {
+ if err := c.Bind().Body(&request); err != nil {
return c.Status(400).JSON(utils.ResponseData{
Status: 400,
Code: "BAD_REQUEST",
@@ -155,7 +155,7 @@ func (controller *Chat) ArchiveChat(c *fiber.Ctx) error {
})
}
- response, err := controller.Service.ArchiveChat(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.ArchiveChat(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
diff --git a/src/ui/rest/chatwoot.go b/src/ui/rest/chatwoot.go
index 9f53a7e1..3e0ea2ad 100644
--- a/src/ui/rest/chatwoot.go
+++ b/src/ui/rest/chatwoot.go
@@ -15,7 +15,7 @@ import (
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/chatwoot"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
"github.com/sirupsen/logrus"
)
@@ -95,7 +95,7 @@ func chatwootSecretMatches(expected, candidate string) bool {
return subtle.ConstantTimeCompare([]byte(expected), []byte(candidate)) == 1
}
-func chatwootWebhookAuthorized(c *fiber.Ctx) bool {
+func chatwootWebhookAuthorized(c fiber.Ctx) bool {
secret := strings.TrimSpace(config.ChatwootWebhookSecret)
if secret == "" {
return true
@@ -334,7 +334,7 @@ func (h *ChatwootHandler) resolveChatwootForDevice(deviceID string) *chatwoot.Re
// HandleWebhook is the shared (legacy / single-webhook) Chatwoot endpoint. The
// device is resolved from the payload (conversation link, contact attrs, inbox
// map, or env fallback).
-func (h *ChatwootHandler) HandleWebhook(c *fiber.Ctx) error {
+func (h *ChatwootHandler) HandleWebhook(c fiber.Ctx) error {
if !chatwootWebhookAuthorized(c) {
logrus.Warn("Chatwoot Webhook: Rejected request with invalid secret")
return c.SendStatus(fiber.StatusUnauthorized)
@@ -343,7 +343,7 @@ func (h *ChatwootHandler) HandleWebhook(c *fiber.Ctx) error {
logrus.Debugf("Chatwoot Webhook raw body: %s", string(c.Body()))
var payload chatwoot.WebhookPayload
- if err := c.BodyParser(&payload); err != nil {
+ if err := c.Bind().Body(&payload); err != nil {
return utils.ResponseError(c, "Invalid payload")
}
return h.processChatwootWebhook(c, payload, nil)
@@ -354,14 +354,14 @@ func (h *ChatwootHandler) HandleWebhook(c *fiber.Ctx) error {
// trust-by-path: in addition to the shared secret it verifies that the payload's
// account and inbox match the device's configured account and inbox, so a
// webhook for one device cannot be delivered through another device's path.
-func (h *ChatwootHandler) HandleDeviceWebhook(c *fiber.Ctx) error {
+func (h *ChatwootHandler) HandleDeviceWebhook(c fiber.Ctx) error {
if !chatwootWebhookAuthorized(c) {
logrus.Warn("Chatwoot Webhook: Rejected per-device request with invalid secret")
return c.SendStatus(fiber.StatusUnauthorized)
}
var payload chatwoot.WebhookPayload
- if err := c.BodyParser(&payload); err != nil {
+ if err := c.Bind().Body(&payload); err != nil {
return utils.ResponseError(c, "Invalid payload")
}
@@ -412,7 +412,7 @@ func (h *ChatwootHandler) HandleDeviceWebhook(c *fiber.Ctx) error {
// processChatwootWebhook performs the event gating shared by both webhook
// endpoints, then delivers an agent reply using either the forced route (when
// set by the per-device endpoint) or one resolved from the payload.
-func (h *ChatwootHandler) processChatwootWebhook(c *fiber.Ctx, payload chatwoot.WebhookPayload, forced *chatwootWebhookRoute) error {
+func (h *ChatwootHandler) processChatwootWebhook(c fiber.Ctx, payload chatwoot.WebhookPayload, forced *chatwootWebhookRoute) error {
contact := payload.Conversation.Meta.Sender
logrus.Debugf("Chatwoot Webhook: event=%s message_type=%s contact_id=%d contact_phone=%s",
payload.Event, payload.MessageType, contact.ID, contact.PhoneNumber)
@@ -465,7 +465,7 @@ func (h *ChatwootHandler) processChatwootWebhook(c *fiber.Ctx, payload chatwoot.
return h.deliverChatwootReply(c, payload, route, contact)
}
-func (h *ChatwootHandler) deliverChatwootReply(c *fiber.Ctx, payload chatwoot.WebhookPayload, route chatwootWebhookRoute, contact chatwoot.Contact) error {
+func (h *ChatwootHandler) deliverChatwootReply(c fiber.Ctx, payload chatwoot.WebhookPayload, route chatwootWebhookRoute, contact chatwoot.Contact) error {
if h.DeviceManager == nil {
err := fmt.Errorf("device manager not initialized")
logrus.Errorf("Chatwoot Webhook: Failed to resolve device: %v", err)
@@ -485,10 +485,10 @@ func (h *ChatwootHandler) deliverChatwootReply(c *fiber.Ctx, payload chatwoot.We
// operations below. The send usecases resolve the WhatsApp client from this
// context (whatsapp.ClientFromContext), so without it the reply goes out
// from the global default device instead of the routed one — a cross-account
- // mis-delivery in multi-device deployments. It is also stored on the fiber
- // user-context because the read/revoke paths read c.UserContext().
- ctx := whatsapp.ContextWithDevice(c.UserContext(), instance)
- c.SetUserContext(ctx)
+ // mis-delivery in multi-device deployments. It is also stored on the Fiber
+ // request context because the read/revoke paths read c.Context().
+ ctx := whatsapp.ContextWithDevice(c.Context(), instance)
+ c.SetContext(ctx)
destination := route.Destination
if destination == "" {
@@ -564,7 +564,7 @@ func (h *ChatwootHandler) deliverChatwootReply(c *fiber.Ctx, payload chatwoot.We
return c.SendStatus(fiber.StatusOK)
}
-func (h *ChatwootHandler) handleDeletedChatwootMessage(c *fiber.Ctx, payload chatwoot.WebhookPayload, forced *chatwootWebhookRoute) error {
+func (h *ChatwootHandler) handleDeletedChatwootMessage(c fiber.Ctx, payload chatwoot.WebhookPayload, forced *chatwootWebhookRoute) error {
if !config.ChatwootMessageDelete {
return c.SendStatus(fiber.StatusOK)
}
@@ -603,7 +603,7 @@ func (h *ChatwootHandler) handleDeletedChatwootMessage(c *fiber.Ctx, payload cha
return c.SendStatus(fiber.StatusOK)
}
- ctx := whatsapp.ContextWithDevice(c.UserContext(), instance)
+ ctx := whatsapp.ContextWithDevice(c.Context(), instance)
if _, err := h.MessageUsecase.RevokeMessage(ctx, domainMessage.RevokeRequest{
MessageID: link.WhatsAppMessageID,
Phone: link.WhatsAppChatJID,
@@ -644,7 +644,7 @@ func (h *ChatwootHandler) storeChatwootOutboundLink(route chatwootWebhookRoute,
}
}
-func (h *ChatwootHandler) markLatestInboundAsRead(c *fiber.Ctx, deviceID, chatJID string) {
+func (h *ChatwootHandler) markLatestInboundAsRead(c fiber.Ctx, deviceID, chatJID string) {
if !config.ChatwootMessageRead || h.MessageUsecase == nil || h.ChatStorageRepo == nil || chatJID == "" {
return
}
@@ -658,7 +658,7 @@ func (h *ChatwootHandler) markLatestInboundAsRead(c *fiber.Ctx, deviceID, chatJI
return
}
- if _, err := h.MessageUsecase.MarkAsRead(c.UserContext(), domainMessage.MarkAsReadRequest{
+ if _, err := h.MessageUsecase.MarkAsRead(c.Context(), domainMessage.MarkAsReadRequest{
MessageID: link.WhatsAppMessageID,
Phone: link.WhatsAppChatJID,
}); err != nil {
@@ -794,10 +794,10 @@ func (h *ChatwootHandler) handleAttachment(ctx context.Context, phone string, at
// SyncHistory triggers a message history sync to Chatwoot
// POST /chatwoot/sync
-func (h *ChatwootHandler) SyncHistory(c *fiber.Ctx) error {
+func (h *ChatwootHandler) SyncHistory(c fiber.Ctx) error {
var req chatwoot.SyncRequest
if strings.TrimSpace(string(c.Body())) != "" {
- if err := c.BodyParser(&req); err != nil {
+ if err := c.Bind().Body(&req); err != nil {
return utils.ResponseError(c, "Invalid payload")
}
}
@@ -806,7 +806,7 @@ func (h *ChatwootHandler) SyncHistory(c *fiber.Ctx) error {
req.DeviceID = c.Query("device_id", config.ChatwootDeviceID)
}
if req.DaysLimit <= 0 {
- req.DaysLimit = c.QueryInt("days", config.ChatwootDaysLimitImportMessages)
+ req.DaysLimit = fiber.Query[int](c, "days", config.ChatwootDaysLimitImportMessages)
}
// Resolve device
@@ -863,12 +863,12 @@ func (h *ChatwootHandler) SyncHistory(c *fiber.Ctx) error {
if req.IncludeMedia != nil {
opts.IncludeMedia = *req.IncludeMedia
} else if c.Query("media") != "" {
- opts.IncludeMedia = c.QueryBool("media", opts.IncludeMedia)
+ opts.IncludeMedia = fiber.Query[bool](c, "media", opts.IncludeMedia)
}
if req.IncludeGroups != nil {
opts.IncludeGroups = *req.IncludeGroups
} else if c.Query("groups") != "" {
- opts.IncludeGroups = c.QueryBool("groups", opts.IncludeGroups)
+ opts.IncludeGroups = fiber.Query[bool](c, "groups", opts.IncludeGroups)
}
// Start async sync
@@ -898,7 +898,7 @@ func (h *ChatwootHandler) SyncHistory(c *fiber.Ctx) error {
// SyncStatus returns the current sync progress
// GET /chatwoot/sync/status
-func (h *ChatwootHandler) SyncStatus(c *fiber.Ctx) error {
+func (h *ChatwootHandler) SyncStatus(c fiber.Ctx) error {
deviceID := c.Query("device_id", config.ChatwootDeviceID)
instance, resolvedID, err := h.DeviceManager.ResolveDevice(deviceID)
diff --git a/src/ui/rest/chatwoot_config.go b/src/ui/rest/chatwoot_config.go
index 3f8ac56d..0abd52d5 100644
--- a/src/ui/rest/chatwoot_config.go
+++ b/src/ui/rest/chatwoot_config.go
@@ -8,7 +8,7 @@ import (
domainChatStorage "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chatstorage"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/chatwoot"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
"github.com/sirupsen/logrus"
)
@@ -63,7 +63,7 @@ func chatwootConfigView(cfg *domainChatStorage.ChatwootDeviceConfig) map[string]
// ListChatwootConfigs returns all per-device Chatwoot configs (tokens masked).
// GET /chatwoot/configs
-func (h *ChatwootHandler) ListChatwootConfigs(c *fiber.Ctx) error {
+func (h *ChatwootHandler) ListChatwootConfigs(c fiber.Ctx) error {
if h.ChatStorageRepo == nil {
return utils.ResponseError(c, "storage not available")
}
@@ -80,7 +80,7 @@ func (h *ChatwootHandler) ListChatwootConfigs(c *fiber.Ctx) error {
// GetChatwootConfig returns one device's Chatwoot config (token masked).
// GET /devices/:device_id/chatwoot/config
-func (h *ChatwootHandler) GetChatwootConfig(c *fiber.Ctx) error {
+func (h *ChatwootHandler) GetChatwootConfig(c fiber.Ctx) error {
deviceID, ok := h.resolveConfigDeviceID(c)
if !ok {
return c.Status(fiber.StatusNotFound).JSON(utils.ResponseData{Status: fiber.StatusNotFound, Code: "DEVICE_NOT_FOUND", Message: "device not found"})
@@ -97,14 +97,14 @@ func (h *ChatwootHandler) GetChatwootConfig(c *fiber.Ctx) error {
// UpsertChatwootConfig creates or updates a device's Chatwoot config.
// PUT /devices/:device_id/chatwoot/config
-func (h *ChatwootHandler) UpsertChatwootConfig(c *fiber.Ctx) error {
+func (h *ChatwootHandler) UpsertChatwootConfig(c fiber.Ctx) error {
deviceID, ok := h.resolveConfigDeviceID(c)
if !ok {
return c.Status(fiber.StatusNotFound).JSON(utils.ResponseData{Status: fiber.StatusNotFound, Code: "DEVICE_NOT_FOUND", Message: "device not found"})
}
var req chatwootConfigRequest
- if err := c.BodyParser(&req); err != nil {
+ if err := c.Bind().Body(&req); err != nil {
return utils.ResponseError(c, "Invalid request body")
}
@@ -192,7 +192,7 @@ func (h *ChatwootHandler) UpsertChatwootConfig(c *fiber.Ctx) error {
// after a delete-and-recreate rebind they would still win the account-scoped
// reverse lookup and hijack reply destinations toward the old mapping.
// DELETE /devices/:device_id/chatwoot/config
-func (h *ChatwootHandler) DeleteChatwootConfig(c *fiber.Ctx) error {
+func (h *ChatwootHandler) DeleteChatwootConfig(c fiber.Ctx) error {
// Resolve aliases/JIDs the same way GET and PUT do — a raw JID param would
// otherwise delete nothing and still report success. Fall back to the raw
// param so a config orphaned by device removal stays deletable.
@@ -228,7 +228,7 @@ func (h *ChatwootHandler) DeleteChatwootConfig(c *fiber.Ctx) error {
// param-derived string itself, whose backing buffer fasthttp recycles after the
// request. Handlers persist this id (config rows, registry cache), so an
// uncopied value would mutate under the next request.
-func (h *ChatwootHandler) resolveConfigDeviceID(c *fiber.Ctx) (string, bool) {
+func (h *ChatwootHandler) resolveConfigDeviceID(c fiber.Ctx) (string, bool) {
deviceID := strings.TrimSpace(c.Params("device_id"))
if deviceID == "" || h.DeviceManager == nil {
return "", false
diff --git a/src/ui/rest/chatwoot_config_test.go b/src/ui/rest/chatwoot_config_test.go
index def4694b..5f3c6dfc 100644
--- a/src/ui/rest/chatwoot_config_test.go
+++ b/src/ui/rest/chatwoot_config_test.go
@@ -10,7 +10,7 @@ import (
domainChatStorage "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chatstorage"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/chatwoot"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
func TestMaskAPIToken(t *testing.T) {
diff --git a/src/ui/rest/chatwoot_device_webhook_test.go b/src/ui/rest/chatwoot_device_webhook_test.go
index aa20d7cc..ba96c66f 100644
--- a/src/ui/rest/chatwoot_device_webhook_test.go
+++ b/src/ui/rest/chatwoot_device_webhook_test.go
@@ -9,7 +9,7 @@ import (
"github.com/aldinokemal/go-whatsapp-web-multidevice/config"
domainChatStorage "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chatstorage"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/chatwoot"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
// deviceWebhookTestRepo satisfies the few repo methods the ClientRegistry and
diff --git a/src/ui/rest/chatwoot_test.go b/src/ui/rest/chatwoot_test.go
index ae550972..b15fda0c 100644
--- a/src/ui/rest/chatwoot_test.go
+++ b/src/ui/rest/chatwoot_test.go
@@ -10,7 +10,7 @@ import (
"github.com/aldinokemal/go-whatsapp-web-multidevice/config"
domainChatStorage "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chatstorage"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/chatwoot"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
// withSignConfig sets the Chatwoot signature globals for the duration of a
diff --git a/src/ui/rest/device.go b/src/ui/rest/device.go
index 30078168..dd5f1402 100644
--- a/src/ui/rest/device.go
+++ b/src/ui/rest/device.go
@@ -7,7 +7,7 @@ import (
"github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chatstorage"
"github.com/aldinokemal/go-whatsapp-web-multidevice/domains/device"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
type Device struct {
@@ -34,8 +34,8 @@ func InitRestDevice(app fiber.Router, service device.IDeviceUsecase) Device {
return rest
}
-func (handler *Device) ListDevices(c *fiber.Ctx) error {
- devices, err := handler.Service.ListDevices(c.UserContext())
+func (handler *Device) ListDevices(c fiber.Ctx) error {
+ devices, err := handler.Service.ListDevices(c.Context())
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -46,9 +46,9 @@ func (handler *Device) ListDevices(c *fiber.Ctx) error {
})
}
-func (handler *Device) GetDevice(c *fiber.Ctx) error {
+func (handler *Device) GetDevice(c fiber.Ctx) error {
deviceID := c.Params("device_id")
- device, err := handler.Service.GetDevice(c.UserContext(), deviceID)
+ device, err := handler.Service.GetDevice(c.Context(), deviceID)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -59,7 +59,7 @@ func (handler *Device) GetDevice(c *fiber.Ctx) error {
})
}
-func (handler *Device) AddDevice(c *fiber.Ctx) error {
+func (handler *Device) AddDevice(c fiber.Ctx) error {
var req struct {
DeviceID string `json:"device_id"`
WebhookURL string `json:"webhook_url"`
@@ -68,7 +68,7 @@ func (handler *Device) AddDevice(c *fiber.Ctx) error {
WebhookInsecureSkipVerify bool `json:"webhook_insecure_skip_verify"`
}
- if err := c.BodyParser(&req); err != nil {
+ if err := c.Bind().Body(&req); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(utils.ResponseData{
Status: 400,
Code: "BAD_REQUEST",
@@ -87,7 +87,7 @@ func (handler *Device) AddDevice(c *fiber.Ctx) error {
}
}
- device, err := handler.Service.AddDevice(c.UserContext(), req.DeviceID, webhook)
+ device, err := handler.Service.AddDevice(c.Context(), req.DeviceID, webhook)
utils.PanicIfNeeded(err)
result := map[string]any{
@@ -112,9 +112,9 @@ func (handler *Device) AddDevice(c *fiber.Ctx) error {
})
}
-func (handler *Device) RemoveDevice(c *fiber.Ctx) error {
+func (handler *Device) RemoveDevice(c fiber.Ctx) error {
deviceID := c.Params("device_id")
- err := handler.Service.RemoveDevice(c.UserContext(), deviceID)
+ err := handler.Service.RemoveDevice(c.Context(), deviceID)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -125,9 +125,9 @@ func (handler *Device) RemoveDevice(c *fiber.Ctx) error {
})
}
-func (handler *Device) LoginDevice(c *fiber.Ctx) error {
+func (handler *Device) LoginDevice(c fiber.Ctx) error {
deviceID := c.Params("device_id")
- response, err := handler.Service.LoginDevice(c.UserContext(), deviceID)
+ response, err := handler.Service.LoginDevice(c.Context(), deviceID)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -136,15 +136,15 @@ func (handler *Device) LoginDevice(c *fiber.Ctx) error {
Message: "Login success",
Results: map[string]any{
"device_id": deviceID,
- "qr_link": fmt.Sprintf("%s://%s%s/%s", c.Protocol(), c.Hostname(), config.AppBasePath, response.ImagePath),
+ "qr_link": fmt.Sprintf("%s://%s%s/%s", c.Scheme(), c.Hostname(), config.AppBasePath, response.ImagePath),
"qr_duration": response.Duration,
},
})
}
-func (handler *Device) LoginDeviceWithCode(c *fiber.Ctx) error {
+func (handler *Device) LoginDeviceWithCode(c fiber.Ctx) error {
deviceID := c.Params("device_id")
- code, err := handler.Service.LoginDeviceWithCode(c.UserContext(), deviceID, c.Query("phone"))
+ code, err := handler.Service.LoginDeviceWithCode(c.Context(), deviceID, c.Query("phone"))
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -158,9 +158,9 @@ func (handler *Device) LoginDeviceWithCode(c *fiber.Ctx) error {
})
}
-func (handler *Device) LogoutDevice(c *fiber.Ctx) error {
+func (handler *Device) LogoutDevice(c fiber.Ctx) error {
deviceID := c.Params("device_id")
- err := handler.Service.LogoutDevice(c.UserContext(), deviceID)
+ err := handler.Service.LogoutDevice(c.Context(), deviceID)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -171,9 +171,9 @@ func (handler *Device) LogoutDevice(c *fiber.Ctx) error {
})
}
-func (handler *Device) ReconnectDevice(c *fiber.Ctx) error {
+func (handler *Device) ReconnectDevice(c fiber.Ctx) error {
deviceID := c.Params("device_id")
- err := handler.Service.ReconnectDevice(c.UserContext(), deviceID)
+ err := handler.Service.ReconnectDevice(c.Context(), deviceID)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -184,9 +184,9 @@ func (handler *Device) ReconnectDevice(c *fiber.Ctx) error {
})
}
-func (handler *Device) Status(c *fiber.Ctx) error {
+func (handler *Device) Status(c fiber.Ctx) error {
deviceID := c.Params("device_id")
- isConnected, isLoggedIn, err := handler.Service.GetStatus(c.UserContext(), deviceID)
+ isConnected, isLoggedIn, err := handler.Service.GetStatus(c.Context(), deviceID)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -202,7 +202,7 @@ func (handler *Device) Status(c *fiber.Ctx) error {
}
// UpdateDeviceWebhook handles PATCH /devices/:device_id/webhook.
-func (handler *Device) UpdateDeviceWebhook(c *fiber.Ctx) error {
+func (handler *Device) UpdateDeviceWebhook(c fiber.Ctx) error {
deviceID := c.Params("device_id")
var req struct {
WebhookURL *string `json:"webhook_url"`
@@ -211,7 +211,7 @@ func (handler *Device) UpdateDeviceWebhook(c *fiber.Ctx) error {
WebhookInsecureSkipVerify bool `json:"webhook_insecure_skip_verify"`
}
- if err := c.BodyParser(&req); err != nil {
+ if err := c.Bind().Body(&req); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(utils.ResponseData{
Status: 400,
Code: "BAD_REQUEST",
@@ -236,7 +236,7 @@ func (handler *Device) UpdateDeviceWebhook(c *fiber.Ctx) error {
WebhookInsecureSkipVerify: req.WebhookInsecureSkipVerify,
}
- err := handler.Service.SetDeviceWebhookConfig(c.UserContext(), deviceID, config)
+ err := handler.Service.SetDeviceWebhookConfig(c.Context(), deviceID, config)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -254,9 +254,9 @@ func (handler *Device) UpdateDeviceWebhook(c *fiber.Ctx) error {
}
// GetDeviceWebhook handles GET /devices/:device_id/webhook.
-func (handler *Device) GetDeviceWebhook(c *fiber.Ctx) error {
+func (handler *Device) GetDeviceWebhook(c fiber.Ctx) error {
deviceID := c.Params("device_id")
- config, err := handler.Service.GetDeviceWebhookConfig(c.UserContext(), deviceID)
+ config, err := handler.Service.GetDeviceWebhookConfig(c.Context(), deviceID)
utils.PanicIfNeeded(err)
webhookURL := ""
diff --git a/src/ui/rest/device_test.go b/src/ui/rest/device_test.go
index 37edac0a..7e46e969 100644
--- a/src/ui/rest/device_test.go
+++ b/src/ui/rest/device_test.go
@@ -11,7 +11,7 @@ import (
"github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chatstorage"
domainDevice "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/device"
"github.com/aldinokemal/go-whatsapp-web-multidevice/ui/rest/middleware"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
// addDeviceStubUsecase implements domainDevice.IDeviceUsecase by embedding the
diff --git a/src/ui/rest/group.go b/src/ui/rest/group.go
index 8427fb03..2ebd38f1 100644
--- a/src/ui/rest/group.go
+++ b/src/ui/rest/group.go
@@ -11,7 +11,7 @@ import (
domainGroup "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/group"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
"go.mau.fi/whatsmeow"
)
@@ -44,12 +44,12 @@ func InitRestGroup(app fiber.Router, service domainGroup.IGroupUsecase) Group {
return rest
}
-func (controller *Group) JoinGroupWithLink(c *fiber.Ctx) error {
+func (controller *Group) JoinGroupWithLink(c fiber.Ctx) error {
var request domainGroup.JoinGroupWithLinkRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
- response, err := controller.Service.JoinGroupWithLink(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.JoinGroupWithLink(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -62,12 +62,12 @@ func (controller *Group) JoinGroupWithLink(c *fiber.Ctx) error {
})
}
-func (controller *Group) GetGroupInfoFromLink(c *fiber.Ctx) error {
+func (controller *Group) GetGroupInfoFromLink(c fiber.Ctx) error {
var request domainGroup.GetGroupInfoFromLinkRequest
- err := c.QueryParser(&request)
+ err := c.Bind().Query(&request)
utils.PanicIfNeeded(err)
- response, err := controller.Service.GetGroupInfoFromLink(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.GetGroupInfoFromLink(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -78,14 +78,14 @@ func (controller *Group) GetGroupInfoFromLink(c *fiber.Ctx) error {
})
}
-func (controller *Group) LeaveGroup(c *fiber.Ctx) error {
+func (controller *Group) LeaveGroup(c fiber.Ctx) error {
var request domainGroup.LeaveGroupRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.GroupID)
- err = controller.Service.LeaveGroup(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ err = controller.Service.LeaveGroup(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -95,12 +95,12 @@ func (controller *Group) LeaveGroup(c *fiber.Ctx) error {
})
}
-func (controller *Group) CreateGroup(c *fiber.Ctx) error {
+func (controller *Group) CreateGroup(c fiber.Ctx) error {
var request domainGroup.CreateGroupRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
- groupID, err := controller.Service.CreateGroup(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ groupID, err := controller.Service.CreateGroup(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -113,9 +113,9 @@ func (controller *Group) CreateGroup(c *fiber.Ctx) error {
})
}
-func (controller *Group) ListParticipants(c *fiber.Ctx) error {
+func (controller *Group) ListParticipants(c fiber.Ctx) error {
var request domainGroup.GetGroupParticipantsRequest
- err := c.QueryParser(&request)
+ err := c.Bind().Query(&request)
utils.PanicIfNeeded(err)
if request.GroupID == "" {
@@ -128,7 +128,7 @@ func (controller *Group) ListParticipants(c *fiber.Ctx) error {
utils.SanitizePhone(&request.GroupID)
- result, err := controller.Service.GetGroupParticipants(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ result, err := controller.Service.GetGroupParticipants(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -139,9 +139,9 @@ func (controller *Group) ListParticipants(c *fiber.Ctx) error {
})
}
-func (controller *Group) ExportParticipants(c *fiber.Ctx) error {
+func (controller *Group) ExportParticipants(c fiber.Ctx) error {
var request domainGroup.GetGroupParticipantsRequest
- err := c.QueryParser(&request)
+ err := c.Bind().Query(&request)
utils.PanicIfNeeded(err)
if request.GroupID == "" {
@@ -154,7 +154,7 @@ func (controller *Group) ExportParticipants(c *fiber.Ctx) error {
utils.SanitizePhone(&request.GroupID)
- result, err := controller.Service.GetGroupParticipants(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ result, err := controller.Service.GetGroupParticipants(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
var buffer bytes.Buffer
@@ -192,25 +192,25 @@ func (controller *Group) ExportParticipants(c *fiber.Ctx) error {
return c.Send(buffer.Bytes())
}
-func (controller *Group) AddParticipants(c *fiber.Ctx) error {
+func (controller *Group) AddParticipants(c fiber.Ctx) error {
return controller.manageParticipants(c, whatsmeow.ParticipantChangeAdd, "Success add participants")
}
-func (controller *Group) DeleteParticipants(c *fiber.Ctx) error {
+func (controller *Group) DeleteParticipants(c fiber.Ctx) error {
return controller.manageParticipants(c, whatsmeow.ParticipantChangeRemove, "Success delete participants")
}
-func (controller *Group) PromoteParticipants(c *fiber.Ctx) error {
+func (controller *Group) PromoteParticipants(c fiber.Ctx) error {
return controller.manageParticipants(c, whatsmeow.ParticipantChangePromote, "Success promote participants")
}
-func (controller *Group) DemoteParticipants(c *fiber.Ctx) error {
+func (controller *Group) DemoteParticipants(c fiber.Ctx) error {
return controller.manageParticipants(c, whatsmeow.ParticipantChangeDemote, "Success demote participants")
}
-func (controller *Group) ListParticipantRequests(c *fiber.Ctx) error {
+func (controller *Group) ListParticipantRequests(c fiber.Ctx) error {
var request domainGroup.GetGroupRequestParticipantsRequest
- err := c.QueryParser(&request)
+ err := c.Bind().Query(&request)
utils.PanicIfNeeded(err)
if request.GroupID == "" {
@@ -223,7 +223,7 @@ func (controller *Group) ListParticipantRequests(c *fiber.Ctx) error {
utils.SanitizePhone(&request.GroupID)
- result, err := controller.Service.GetGroupRequestParticipants(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ result, err := controller.Service.GetGroupRequestParticipants(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -234,22 +234,22 @@ func (controller *Group) ListParticipantRequests(c *fiber.Ctx) error {
})
}
-func (controller *Group) ApproveParticipantRequests(c *fiber.Ctx) error {
+func (controller *Group) ApproveParticipantRequests(c fiber.Ctx) error {
return controller.handleRequestedParticipants(c, whatsmeow.ParticipantChangeApprove, "Success approve requested participants")
}
-func (controller *Group) RejectParticipantRequests(c *fiber.Ctx) error {
+func (controller *Group) RejectParticipantRequests(c fiber.Ctx) error {
return controller.handleRequestedParticipants(c, whatsmeow.ParticipantChangeReject, "Success reject requested participants")
}
// Generalized participant management handler
-func (controller *Group) manageParticipants(c *fiber.Ctx, action whatsmeow.ParticipantChange, successMsg string) error {
+func (controller *Group) manageParticipants(c fiber.Ctx, action whatsmeow.ParticipantChange, successMsg string) error {
var request domainGroup.ParticipantRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.GroupID)
request.Action = action
- result, err := controller.Service.ManageParticipant(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ result, err := controller.Service.ManageParticipant(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
Status: 200,
@@ -260,13 +260,13 @@ func (controller *Group) manageParticipants(c *fiber.Ctx, action whatsmeow.Parti
}
// Generalized requested participants handler
-func (controller *Group) handleRequestedParticipants(c *fiber.Ctx, action whatsmeow.ParticipantRequestChange, successMsg string) error {
+func (controller *Group) handleRequestedParticipants(c fiber.Ctx, action whatsmeow.ParticipantRequestChange, successMsg string) error {
var request domainGroup.GroupRequestParticipantsRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.GroupID)
request.Action = action
- result, err := controller.Service.ManageGroupRequestParticipants(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ result, err := controller.Service.ManageGroupRequestParticipants(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
Status: 200,
@@ -276,9 +276,9 @@ func (controller *Group) handleRequestedParticipants(c *fiber.Ctx, action whatsm
})
}
-func (controller *Group) SetGroupPhoto(c *fiber.Ctx) error {
+func (controller *Group) SetGroupPhoto(c fiber.Ctx) error {
var request domainGroup.SetGroupPhotoRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.GroupID)
@@ -303,7 +303,7 @@ func (controller *Group) SetGroupPhoto(c *fiber.Ctx) error {
logrus.Printf("DEBUG: No photo file provided - Error: %v", err)
}
- pictureID, err := controller.Service.SetGroupPhoto(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ pictureID, err := controller.Service.SetGroupPhoto(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
if err != nil {
logrus.Printf("ERROR: WhatsApp service failed to set group photo - %v", err)
}
@@ -325,14 +325,14 @@ func (controller *Group) SetGroupPhoto(c *fiber.Ctx) error {
})
}
-func (controller *Group) SetGroupName(c *fiber.Ctx) error {
+func (controller *Group) SetGroupName(c fiber.Ctx) error {
var request domainGroup.SetGroupNameRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.GroupID)
- err = controller.Service.SetGroupName(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ err = controller.Service.SetGroupName(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -342,14 +342,14 @@ func (controller *Group) SetGroupName(c *fiber.Ctx) error {
})
}
-func (controller *Group) SetGroupLocked(c *fiber.Ctx) error {
+func (controller *Group) SetGroupLocked(c fiber.Ctx) error {
var request domainGroup.SetGroupLockedRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.GroupID)
- err = controller.Service.SetGroupLocked(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ err = controller.Service.SetGroupLocked(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
message := "Success set group as unlocked"
@@ -364,14 +364,14 @@ func (controller *Group) SetGroupLocked(c *fiber.Ctx) error {
})
}
-func (controller *Group) SetGroupAnnounce(c *fiber.Ctx) error {
+func (controller *Group) SetGroupAnnounce(c fiber.Ctx) error {
var request domainGroup.SetGroupAnnounceRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.GroupID)
- err = controller.Service.SetGroupAnnounce(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ err = controller.Service.SetGroupAnnounce(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
message := "Success disable announce mode"
@@ -386,14 +386,14 @@ func (controller *Group) SetGroupAnnounce(c *fiber.Ctx) error {
})
}
-func (controller *Group) SetGroupTopic(c *fiber.Ctx) error {
+func (controller *Group) SetGroupTopic(c fiber.Ctx) error {
var request domainGroup.SetGroupTopicRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.GroupID)
- err = controller.Service.SetGroupTopic(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ err = controller.Service.SetGroupTopic(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
message := "Success update group topic"
@@ -409,14 +409,14 @@ func (controller *Group) SetGroupTopic(c *fiber.Ctx) error {
}
// GroupInfo handles the /group/info endpoint to fetch group information
-func (controller *Group) GroupInfo(c *fiber.Ctx) error {
+func (controller *Group) GroupInfo(c fiber.Ctx) error {
var request domainGroup.GroupInfoRequest
- err := c.QueryParser(&request)
+ err := c.Bind().Query(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.GroupID)
- response, err := controller.Service.GroupInfo(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.GroupInfo(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -427,14 +427,14 @@ func (controller *Group) GroupInfo(c *fiber.Ctx) error {
})
}
-func (controller *Group) GetGroupInviteLink(c *fiber.Ctx) error {
+func (controller *Group) GetGroupInviteLink(c fiber.Ctx) error {
var request domainGroup.GetGroupInviteLinkRequest
- err := c.QueryParser(&request)
+ err := c.Bind().Query(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.GroupID)
- response, err := controller.Service.GetGroupInviteLink(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.GetGroupInviteLink(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
diff --git a/src/ui/rest/message.go b/src/ui/rest/message.go
index 26f6ee37..1a3f61a6 100644
--- a/src/ui/rest/message.go
+++ b/src/ui/rest/message.go
@@ -11,7 +11,7 @@ import (
domainSend "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/send"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
type Message struct {
@@ -35,15 +35,15 @@ func InitRestMessage(app fiber.Router, service domainMessage.IMessageUsecase, se
return rest
}
-func (controller *Message) RevokeMessage(c *fiber.Ctx) error {
+func (controller *Message) RevokeMessage(c fiber.Ctx) error {
var request domainMessage.RevokeRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
request.MessageID = c.Params("message_id")
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.RevokeMessage(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.RevokeMessage(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -54,15 +54,15 @@ func (controller *Message) RevokeMessage(c *fiber.Ctx) error {
})
}
-func (controller *Message) DeleteMessage(c *fiber.Ctx) error {
+func (controller *Message) DeleteMessage(c fiber.Ctx) error {
var request domainMessage.DeleteRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
request.MessageID = c.Params("message_id")
utils.SanitizePhone(&request.Phone)
- err = controller.Service.DeleteMessage(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ err = controller.Service.DeleteMessage(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -73,15 +73,15 @@ func (controller *Message) DeleteMessage(c *fiber.Ctx) error {
})
}
-func (controller *Message) UpdateMessage(c *fiber.Ctx) error {
+func (controller *Message) UpdateMessage(c fiber.Ctx) error {
var request domainMessage.UpdateMessageRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
request.MessageID = c.Params("message_id")
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.UpdateMessage(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.UpdateMessage(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -92,15 +92,15 @@ func (controller *Message) UpdateMessage(c *fiber.Ctx) error {
})
}
-func (controller *Message) ReactMessage(c *fiber.Ctx) error {
+func (controller *Message) ReactMessage(c fiber.Ctx) error {
var request domainMessage.ReactionRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
request.MessageID = c.Params("message_id")
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.ReactMessage(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.ReactMessage(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -111,15 +111,15 @@ func (controller *Message) ReactMessage(c *fiber.Ctx) error {
})
}
-func (controller *Message) MarkAsRead(c *fiber.Ctx) error {
+func (controller *Message) MarkAsRead(c fiber.Ctx) error {
var request domainMessage.MarkAsReadRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
request.MessageID = c.Params("message_id")
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.MarkAsRead(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.MarkAsRead(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -130,16 +130,16 @@ func (controller *Message) MarkAsRead(c *fiber.Ctx) error {
})
}
-func (controller *Message) StarMessage(c *fiber.Ctx) error {
+func (controller *Message) StarMessage(c fiber.Ctx) error {
var request domainMessage.StarRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
request.MessageID = c.Params("message_id")
utils.SanitizePhone(&request.Phone)
request.IsStarred = true
- err = controller.Service.StarMessage(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ err = controller.Service.StarMessage(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -150,15 +150,15 @@ func (controller *Message) StarMessage(c *fiber.Ctx) error {
})
}
-func (controller *Message) UnstarMessage(c *fiber.Ctx) error {
+func (controller *Message) UnstarMessage(c fiber.Ctx) error {
var request domainMessage.StarRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
request.MessageID = c.Params("message_id")
utils.SanitizePhone(&request.Phone)
request.IsStarred = false
- err = controller.Service.StarMessage(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ err = controller.Service.StarMessage(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -169,15 +169,15 @@ func (controller *Message) UnstarMessage(c *fiber.Ctx) error {
})
}
-func (controller *Message) ForwardMessage(c *fiber.Ctx) error {
+func (controller *Message) ForwardMessage(c fiber.Ctx) error {
var request domainSend.ForwardRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
request.MessageID = c.Params("message_id")
utils.SanitizePhone(&request.Phone)
- response, err := controller.SendService.SendForward(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.SendService.SendForward(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -188,14 +188,14 @@ func (controller *Message) ForwardMessage(c *fiber.Ctx) error {
})
}
-func (controller *Message) DownloadMedia(c *fiber.Ctx) error {
+func (controller *Message) DownloadMedia(c fiber.Ctx) error {
var request domainMessage.DownloadMediaRequest
request.MessageID = c.Params("message_id")
request.Phone = c.Query("phone")
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.DownloadMedia(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.DownloadMedia(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
if response.FileURL == "" {
response.FileURL = publicStaticFileURL(c, response.FilePath)
@@ -209,12 +209,12 @@ func (controller *Message) DownloadMedia(c *fiber.Ctx) error {
})
}
-func publicStaticFileURL(c *fiber.Ctx, filePath string) string {
+func publicStaticFileURL(c fiber.Ctx, filePath string) string {
staticPath := publicStaticPath(filePath)
if staticPath == "" {
return ""
}
- return fmt.Sprintf("%s://%s%s%s", c.Protocol(), c.Hostname(), config.AppBasePath, staticPath)
+ return fmt.Sprintf("%s://%s%s%s", c.Scheme(), c.Hostname(), config.AppBasePath, staticPath)
}
func publicStaticPath(filePath string) string {
diff --git a/src/ui/rest/message_test.go b/src/ui/rest/message_test.go
index bb739235..bfab24c8 100644
--- a/src/ui/rest/message_test.go
+++ b/src/ui/rest/message_test.go
@@ -1,6 +1,15 @@
package rest
-import "testing"
+import (
+ "io"
+ "net/http/httptest"
+ "testing"
+
+ "github.com/aldinokemal/go-whatsapp-web-multidevice/config"
+ "github.com/gofiber/fiber/v3"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
func TestPublicStaticPath(t *testing.T) {
tests := []struct {
@@ -43,3 +52,24 @@ func TestPublicStaticPath(t *testing.T) {
})
}
}
+
+func TestPublicStaticFileURLUsesRequestScheme(t *testing.T) {
+ oldBasePath := config.AppBasePath
+ config.AppBasePath = "/api"
+ defer func() {
+ config.AppBasePath = oldBasePath
+ }()
+
+ app := fiber.New()
+ app.Get("/url", func(c fiber.Ctx) error {
+ return c.SendString(publicStaticFileURL(c, "statics/media/photo.jpg"))
+ })
+
+ resp, err := app.Test(httptest.NewRequest("GET", "http://example.com/url", nil))
+ require.NoError(t, err)
+ defer resp.Body.Close()
+
+ body, err := io.ReadAll(resp.Body)
+ require.NoError(t, err)
+ assert.Equal(t, "http://example.com/api/statics/media/photo.jpg", string(body))
+}
diff --git a/src/ui/rest/middleware/basicauth.go b/src/ui/rest/middleware/basicauth.go
index 33e00235..266c2ad0 100644
--- a/src/ui/rest/middleware/basicauth.go
+++ b/src/ui/rest/middleware/basicauth.go
@@ -2,17 +2,17 @@ package middleware
import (
"context"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
type AuthorizationValue string
func BasicAuth() fiber.Handler {
- return func(c *fiber.Ctx) error {
+ return func(c fiber.Ctx) error {
token := string(c.Request().Header.Peek("Authorization"))
if token != "" {
ctx := context.WithValue(c.Context(), AuthorizationValue("BASIC_AUTH"), token)
- c.SetUserContext(ctx)
+ c.SetContext(ctx)
}
return c.Next()
diff --git a/src/ui/rest/middleware/device.go b/src/ui/rest/middleware/device.go
index 3ae857ef..c0f4d0ae 100644
--- a/src/ui/rest/middleware/device.go
+++ b/src/ui/rest/middleware/device.go
@@ -7,7 +7,7 @@ import (
"github.com/aldinokemal/go-whatsapp-web-multidevice/config"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
const DeviceIDHeader = "X-Device-Id"
@@ -15,7 +15,7 @@ const DeviceIDHeader = "X-Device-Id"
// DeviceMiddleware fetches a device instance by header (preferred), path param, or query param
// and injects it into the context. It falls back to the default/only device for single-device mode.
func DeviceMiddleware(dm *whatsapp.DeviceManager) fiber.Handler {
- return func(c *fiber.Ctx) error {
+ return func(c fiber.Ctx) error {
// Allow non-device-scoped public endpoints (e.g., landing page) to pass through.
path := strings.TrimSpace(c.Path())
if path == "/" || path == "" || path == config.AppBasePath || path == config.AppBasePath+"/" {
@@ -62,7 +62,7 @@ func DeviceMiddleware(dm *whatsapp.DeviceManager) fiber.Handler {
c.Locals("device_id", resolvedID)
c.Locals("device", instance)
- c.SetUserContext(whatsapp.ContextWithDevice(c.UserContext(), instance))
+ c.SetContext(whatsapp.ContextWithDevice(c.Context(), instance))
return c.Next()
}
}
diff --git a/src/ui/rest/middleware/recovery.go b/src/ui/rest/middleware/recovery.go
index a66f5ee8..d13a5090 100644
--- a/src/ui/rest/middleware/recovery.go
+++ b/src/ui/rest/middleware/recovery.go
@@ -6,12 +6,12 @@ import (
pkgError "github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/error"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
"github.com/sirupsen/logrus"
)
func Recovery() fiber.Handler {
- return func(ctx *fiber.Ctx) error {
+ return func(ctx fiber.Ctx) error {
defer func() {
err := recover()
if err != nil {
diff --git a/src/ui/rest/middleware/timeout.go b/src/ui/rest/middleware/timeout.go
index ff8526c9..37844616 100644
--- a/src/ui/rest/middleware/timeout.go
+++ b/src/ui/rest/middleware/timeout.go
@@ -4,7 +4,7 @@ import (
"context"
"time"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
// DefaultRequestTimeout is the default timeout for API requests.
@@ -15,10 +15,10 @@ const DefaultRequestTimeout = 45 * time.Second
// If the handler doesn't complete within the timeout, the context is cancelled
// and whatsmeow SDK calls will return context.DeadlineExceeded.
func RequestTimeout(timeout time.Duration) fiber.Handler {
- return func(c *fiber.Ctx) error {
- ctx, cancel := context.WithTimeout(c.UserContext(), timeout)
+ return func(c fiber.Ctx) error {
+ ctx, cancel := context.WithTimeout(c.Context(), timeout)
defer cancel()
- c.SetUserContext(ctx)
+ c.SetContext(ctx)
return c.Next()
}
}
diff --git a/src/ui/rest/middleware/timeout_test.go b/src/ui/rest/middleware/timeout_test.go
index 276c26ec..c7eb5c69 100644
--- a/src/ui/rest/middleware/timeout_test.go
+++ b/src/ui/rest/middleware/timeout_test.go
@@ -7,7 +7,7 @@ import (
"testing"
"time"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
"github.com/stretchr/testify/assert"
)
@@ -16,13 +16,13 @@ func TestRequestTimeout_SetsDeadline(t *testing.T) {
app.Use(RequestTimeout(5 * time.Second))
var capturedCtx context.Context
- app.Get("/test", func(c *fiber.Ctx) error {
- capturedCtx = c.UserContext()
+ app.Get("/test", func(c fiber.Ctx) error {
+ capturedCtx = c.Context()
return c.SendString("ok")
})
req := httptest.NewRequest("GET", "/test", nil)
- resp, err := app.Test(req, -1)
+ resp, err := app.Test(req, fiber.TestConfig{Timeout: 0, FailOnTimeout: false})
assert.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode)
@@ -36,8 +36,8 @@ func TestRequestTimeout_CancelsOnTimeout(t *testing.T) {
app := fiber.New()
app.Use(RequestTimeout(50 * time.Millisecond))
- app.Get("/slow", func(c *fiber.Ctx) error {
- ctx := c.UserContext()
+ app.Get("/slow", func(c fiber.Ctx) error {
+ ctx := c.Context()
select {
case <-time.After(200 * time.Millisecond):
return c.SendString("completed")
@@ -47,7 +47,7 @@ func TestRequestTimeout_CancelsOnTimeout(t *testing.T) {
})
req := httptest.NewRequest("GET", "/slow", nil)
- resp, err := app.Test(req, 500)
+ resp, err := app.Test(req, fiber.TestConfig{Timeout: 500 * time.Millisecond, FailOnTimeout: true})
assert.NoError(t, err)
assert.Equal(t, 504, resp.StatusCode)
diff --git a/src/ui/rest/newsletter.go b/src/ui/rest/newsletter.go
index 2dc8451c..f17df3a0 100644
--- a/src/ui/rest/newsletter.go
+++ b/src/ui/rest/newsletter.go
@@ -4,7 +4,7 @@ import (
domainNewsletter "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/newsletter"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
type Newsletter struct {
@@ -18,12 +18,12 @@ func InitRestNewsletter(app fiber.Router, service domainNewsletter.INewsletterUs
return rest
}
-func (controller *Newsletter) Unfollow(c *fiber.Ctx) error {
+func (controller *Newsletter) Unfollow(c fiber.Ctx) error {
var request domainNewsletter.UnfollowRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
- err = controller.Service.Unfollow(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ err = controller.Service.Unfollow(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -33,12 +33,12 @@ func (controller *Newsletter) Unfollow(c *fiber.Ctx) error {
})
}
-func (controller *Newsletter) GetMessages(c *fiber.Ctx) error {
+func (controller *Newsletter) GetMessages(c fiber.Ctx) error {
var request domainNewsletter.GetMessagesRequest
- err := c.QueryParser(&request)
+ err := c.Bind().Query(&request)
utils.PanicIfNeeded(err)
- response, err := controller.Service.GetMessages(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.GetMessages(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
diff --git a/src/ui/rest/send.go b/src/ui/rest/send.go
index 1aaf39a0..fbcbecbb 100644
--- a/src/ui/rest/send.go
+++ b/src/ui/rest/send.go
@@ -4,7 +4,7 @@ import (
domainSend "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/send"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
type Send struct {
@@ -28,14 +28,14 @@ func InitRestSend(app fiber.Router, service domainSend.ISendUsecase) Send {
return rest
}
-func (controller *Send) SendText(c *fiber.Ctx) error {
+func (controller *Send) SendText(c fiber.Ctx) error {
var request domainSend.MessageRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.SendText(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.SendText(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -46,11 +46,11 @@ func (controller *Send) SendText(c *fiber.Ctx) error {
})
}
-func (controller *Send) SendImage(c *fiber.Ctx) error {
+func (controller *Send) SendImage(c fiber.Ctx) error {
var request domainSend.ImageRequest
request.Compress = true
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
file, err := c.FormFile("image")
@@ -60,7 +60,7 @@ func (controller *Send) SendImage(c *fiber.Ctx) error {
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.SendImage(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.SendImage(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -71,9 +71,9 @@ func (controller *Send) SendImage(c *fiber.Ctx) error {
})
}
-func (controller *Send) SendFile(c *fiber.Ctx) error {
+func (controller *Send) SendFile(c fiber.Ctx) error {
var request domainSend.FileRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
// Try to get file but ignore error if not provided (e.g. file_url is used instead)
@@ -83,7 +83,7 @@ func (controller *Send) SendFile(c *fiber.Ctx) error {
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.SendFile(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.SendFile(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -94,9 +94,9 @@ func (controller *Send) SendFile(c *fiber.Ctx) error {
})
}
-func (controller *Send) SendVideo(c *fiber.Ctx) error {
+func (controller *Send) SendVideo(c fiber.Ctx) error {
var request domainSend.VideoRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
// Try to get file but ignore error if not provided
@@ -106,7 +106,7 @@ func (controller *Send) SendVideo(c *fiber.Ctx) error {
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.SendVideo(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.SendVideo(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -117,9 +117,9 @@ func (controller *Send) SendVideo(c *fiber.Ctx) error {
})
}
-func (controller *Send) SendSticker(c *fiber.Ctx) error {
+func (controller *Send) SendSticker(c fiber.Ctx) error {
var request domainSend.StickerRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
// Try to get file but ignore error if not provided
@@ -129,7 +129,7 @@ func (controller *Send) SendSticker(c *fiber.Ctx) error {
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.SendSticker(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.SendSticker(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -140,14 +140,14 @@ func (controller *Send) SendSticker(c *fiber.Ctx) error {
})
}
-func (controller *Send) SendContact(c *fiber.Ctx) error {
+func (controller *Send) SendContact(c fiber.Ctx) error {
var request domainSend.ContactRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.SendContact(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.SendContact(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -158,14 +158,14 @@ func (controller *Send) SendContact(c *fiber.Ctx) error {
})
}
-func (controller *Send) SendLink(c *fiber.Ctx) error {
+func (controller *Send) SendLink(c fiber.Ctx) error {
var request domainSend.LinkRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.SendLink(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.SendLink(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -176,14 +176,14 @@ func (controller *Send) SendLink(c *fiber.Ctx) error {
})
}
-func (controller *Send) SendLocation(c *fiber.Ctx) error {
+func (controller *Send) SendLocation(c fiber.Ctx) error {
var request domainSend.LocationRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.SendLocation(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.SendLocation(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -194,9 +194,9 @@ func (controller *Send) SendLocation(c *fiber.Ctx) error {
})
}
-func (controller *Send) SendAudio(c *fiber.Ctx) error {
+func (controller *Send) SendAudio(c fiber.Ctx) error {
var request domainSend.AudioRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
// Try to get file but ignore error if not provided
@@ -206,7 +206,7 @@ func (controller *Send) SendAudio(c *fiber.Ctx) error {
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.SendAudio(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.SendAudio(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -217,14 +217,14 @@ func (controller *Send) SendAudio(c *fiber.Ctx) error {
})
}
-func (controller *Send) SendPoll(c *fiber.Ctx) error {
+func (controller *Send) SendPoll(c fiber.Ctx) error {
var request domainSend.PollRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.SendPoll(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.SendPoll(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -235,12 +235,12 @@ func (controller *Send) SendPoll(c *fiber.Ctx) error {
})
}
-func (controller *Send) SendPresence(c *fiber.Ctx) error {
+func (controller *Send) SendPresence(c fiber.Ctx) error {
var request domainSend.PresenceRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
- response, err := controller.Service.SendPresence(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.SendPresence(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -251,14 +251,14 @@ func (controller *Send) SendPresence(c *fiber.Ctx) error {
})
}
-func (controller *Send) SendChatPresence(c *fiber.Ctx) error {
+func (controller *Send) SendChatPresence(c fiber.Ctx) error {
var request domainSend.ChatPresenceRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.Phone)
- response, err := controller.Service.SendChatPresence(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)
+ response, err := controller.Service.SendChatPresence(whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c)), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
diff --git a/src/ui/rest/send_test.go b/src/ui/rest/send_test.go
index b916f991..06d54c98 100644
--- a/src/ui/rest/send_test.go
+++ b/src/ui/rest/send_test.go
@@ -11,7 +11,7 @@ import (
domainSend "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/send"
"github.com/aldinokemal/go-whatsapp-web-multidevice/ui/rest/middleware"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
// sendFileStubUsecase implements domainSend.ISendUsecase by embedding the
diff --git a/src/ui/rest/user.go b/src/ui/rest/user.go
index 3b3b4e2d..2e45aa2d 100644
--- a/src/ui/rest/user.go
+++ b/src/ui/rest/user.go
@@ -4,7 +4,7 @@ import (
domainUser "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/user"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
)
type User struct {
@@ -27,14 +27,14 @@ func InitRestUser(app fiber.Router, service domainUser.IUserUsecase) User {
return rest
}
-func (controller *User) UserInfo(c *fiber.Ctx) error {
+func (controller *User) UserInfo(c fiber.Ctx) error {
var request domainUser.InfoRequest
- err := c.QueryParser(&request)
+ err := c.Bind().Query(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.Phone)
- ctx := whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c))
+ ctx := whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c))
response, err := controller.Service.Info(ctx, request)
utils.PanicIfNeeded(err)
@@ -47,14 +47,14 @@ func (controller *User) UserInfo(c *fiber.Ctx) error {
})
}
-func (controller *User) UserAvatar(c *fiber.Ctx) error {
+func (controller *User) UserAvatar(c fiber.Ctx) error {
var request domainUser.AvatarRequest
- err := c.QueryParser(&request)
+ err := c.Bind().Query(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.Phone)
- ctx := whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c))
+ ctx := whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c))
response, err := controller.Service.Avatar(ctx, request)
utils.PanicIfNeeded(err)
@@ -67,15 +67,15 @@ func (controller *User) UserAvatar(c *fiber.Ctx) error {
})
}
-func (controller *User) UserChangeAvatar(c *fiber.Ctx) error {
+func (controller *User) UserChangeAvatar(c fiber.Ctx) error {
var request domainUser.ChangeAvatarRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
request.Avatar, err = c.FormFile("avatar")
utils.PanicIfNeeded(err)
- ctx := whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c))
+ ctx := whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c))
err = controller.Service.ChangeAvatar(ctx, request)
utils.PanicIfNeeded(err)
@@ -87,8 +87,8 @@ func (controller *User) UserChangeAvatar(c *fiber.Ctx) error {
})
}
-func (controller *User) UserMyPrivacySetting(c *fiber.Ctx) error {
- ctx := whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c))
+func (controller *User) UserMyPrivacySetting(c fiber.Ctx) error {
+ ctx := whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c))
response, err := controller.Service.MyPrivacySetting(ctx)
utils.PanicIfNeeded(err)
@@ -100,9 +100,9 @@ func (controller *User) UserMyPrivacySetting(c *fiber.Ctx) error {
})
}
-func (controller *User) UserMyListGroups(c *fiber.Ctx) error {
+func (controller *User) UserMyListGroups(c fiber.Ctx) error {
deviceVal := c.Locals("device")
- ctx := c.UserContext()
+ ctx := c.Context()
if device, ok := deviceVal.(*whatsapp.DeviceInstance); ok {
ctx = whatsapp.ContextWithDevice(ctx, device)
}
@@ -118,8 +118,8 @@ func (controller *User) UserMyListGroups(c *fiber.Ctx) error {
})
}
-func (controller *User) UserMyListNewsletter(c *fiber.Ctx) error {
- ctx := whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c))
+func (controller *User) UserMyListNewsletter(c fiber.Ctx) error {
+ ctx := whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c))
response, err := controller.Service.MyListNewsletter(ctx)
utils.PanicIfNeeded(err)
@@ -131,8 +131,8 @@ func (controller *User) UserMyListNewsletter(c *fiber.Ctx) error {
})
}
-func (controller *User) UserMyListContacts(c *fiber.Ctx) error {
- ctx := whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c))
+func (controller *User) UserMyListContacts(c fiber.Ctx) error {
+ ctx := whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c))
response, err := controller.Service.MyListContacts(ctx)
utils.PanicIfNeeded(err)
@@ -144,12 +144,12 @@ func (controller *User) UserMyListContacts(c *fiber.Ctx) error {
})
}
-func (controller *User) UserChangePushName(c *fiber.Ctx) error {
+func (controller *User) UserChangePushName(c fiber.Ctx) error {
var request domainUser.ChangePushNameRequest
- err := c.BodyParser(&request)
+ err := c.Bind().Body(&request)
utils.PanicIfNeeded(err)
- err = controller.Service.ChangePushName(c.UserContext(), request)
+ err = controller.Service.ChangePushName(c.Context(), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -159,12 +159,12 @@ func (controller *User) UserChangePushName(c *fiber.Ctx) error {
})
}
-func (controller *User) UserCheck(c *fiber.Ctx) error {
+func (controller *User) UserCheck(c fiber.Ctx) error {
var request domainUser.CheckRequest
- err := c.QueryParser(&request)
+ err := c.Bind().Query(&request)
utils.PanicIfNeeded(err)
- response, err := controller.Service.IsOnWhatsApp(c.UserContext(), request)
+ response, err := controller.Service.IsOnWhatsApp(c.Context(), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
@@ -175,14 +175,14 @@ func (controller *User) UserCheck(c *fiber.Ctx) error {
})
}
-func (controller *User) UserBusinessProfile(c *fiber.Ctx) error {
+func (controller *User) UserBusinessProfile(c fiber.Ctx) error {
var request domainUser.BusinessProfileRequest
- err := c.QueryParser(&request)
+ err := c.Bind().Query(&request)
utils.PanicIfNeeded(err)
utils.SanitizePhone(&request.Phone)
- ctx := whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c))
+ ctx := whatsapp.ContextWithDevice(c.Context(), getDeviceFromCtx(c))
response, err := controller.Service.BusinessProfile(ctx, request)
utils.PanicIfNeeded(err)
@@ -195,7 +195,7 @@ func (controller *User) UserBusinessProfile(c *fiber.Ctx) error {
})
}
-func getDeviceFromCtx(c *fiber.Ctx) *whatsapp.DeviceInstance {
+func getDeviceFromCtx(c fiber.Ctx) *whatsapp.DeviceInstance {
if c == nil {
return nil
}
diff --git a/src/ui/websocket/websocket.go b/src/ui/websocket/websocket.go
index 17ecc10c..e08f7e83 100644
--- a/src/ui/websocket/websocket.go
+++ b/src/ui/websocket/websocket.go
@@ -7,8 +7,8 @@ import (
"github.com/sirupsen/logrus"
domainApp "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/app"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/websocket/v2"
+ "github.com/gofiber/contrib/v3/websocket"
+ "github.com/gofiber/fiber/v3"
)
type client struct{}
@@ -78,7 +78,7 @@ func RunHub() {
}
func RegisterRoutes(app fiber.Router, service domainApp.IAppUsecase) {
- app.Use("/ws", func(c *fiber.Ctx) error {
+ app.Use("/ws", func(c fiber.Ctx) error {
if websocket.IsWebSocketUpgrade(c) {
return c.Next()
}
diff --git a/src/usecase/app.go b/src/usecase/app.go
index 4f50f03f..39524ce8 100644
--- a/src/usecase/app.go
+++ b/src/usecase/app.go
@@ -14,7 +14,7 @@ import (
pkgError "github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/error"
"github.com/aldinokemal/go-whatsapp-web-multidevice/ui/websocket"
"github.com/aldinokemal/go-whatsapp-web-multidevice/validations"
- fiberUtils "github.com/gofiber/fiber/v2/utils"
+ fiberUtils "github.com/gofiber/utils/v2"
"github.com/sirupsen/logrus"
"github.com/skip2/go-qrcode"
"go.mau.fi/libsignal/logger"
diff --git a/src/usecase/send.go b/src/usecase/send.go
index 91c90377..276a91f8 100644
--- a/src/usecase/send.go
+++ b/src/usecase/send.go
@@ -26,7 +26,7 @@ import (
"github.com/aldinokemal/go-whatsapp-web-multidevice/ui/rest/helpers"
"github.com/aldinokemal/go-whatsapp-web-multidevice/validations"
"github.com/disintegration/imaging"
- fiberUtils "github.com/gofiber/fiber/v2/utils"
+ fiberUtils "github.com/gofiber/utils/v2"
"github.com/sirupsen/logrus"
"github.com/valyala/fasthttp"
"go.mau.fi/whatsmeow"