GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.
Go botgogolanggolang-whatsappgolang-whatsapp-apirestrest-apiwhatsappwhatsapp-apiwhatsapp-api-gowhatsapp-multi-devicewhatsapp-web-multi-device
refactor: Update Dockerfile build process and improve metadata handling in utils
Aldino Kemal20df78506ab8
diff --git a/docker-compose.yml b/docker-compose.ymlindex 888a1d01..c49d8871 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -8,7 +8,7 @@ services:build:context: .dockerfile: ./docker/golang.Dockerfile- restart: 'always'+ restart: "on-failure"ports:- "3000:3000"env_file:diff --git a/docker/golang.Dockerfile b/docker/golang.Dockerfileindex 155605e7..cc919aa9 100644--- a/docker/golang.Dockerfile+++ b/docker/golang.Dockerfile@@ -8,14 +8,14 @@ COPY ./src .# Fetch dependencies.RUN go mod download-# Build the binary.-RUN go build -o /app/whatsapp+# Build the binary with optimizations+RUN go build -a -ldflags="-w -s" -o /app/whatsapp############################### STEP 2 build a smaller image#############################FROM alpine:3.20-RUN apk update && apk add --no-cache ffmpeg+RUN apk add --no-cache ffmpegWORKDIR /app# Copy compiled from builder.COPY --from=builder /app/whatsapp /app/whatsappdiff --git a/src/go.mod b/src/go.modindex d930503e..d7cd0495 100644--- a/src/go.mod+++ b/src/go.mod@@ -1,11 +1,11 @@module github.com/aldinokemal/go-whatsapp-web-multidevice-go 1.23+go 1.23.0-toolchain go1.23.1+toolchain go1.24.0require (- github.com/PuerkitoBio/goquery v1.10.1+ github.com/PuerkitoBio/goquery v1.10.2github.com/disintegration/imaging v1.6.2github.com/dustin/go-humanize v1.0.1github.com/go-ozzo/ozzo-validation/v4 v4.3.0@@ -17,12 +17,12 @@ require (github.com/mattn/go-sqlite3 v1.14.24github.com/sirupsen/logrus v1.9.3github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e- github.com/spf13/cobra v1.8.1+ github.com/spf13/cobra v1.9.1github.com/spf13/viper v1.19.0github.com/stretchr/testify v1.10.0- github.com/valyala/fasthttp v1.58.0- go.mau.fi/libsignal v0.1.1- go.mau.fi/whatsmeow v0.0.0-20250210124836-838d5eeaf73e+ github.com/valyala/fasthttp v1.59.0+ go.mau.fi/libsignal v0.1.2+ go.mau.fi/whatsmeow v0.0.0-20250221160813-35b965ceadf1google.golang.org/protobuf v1.36.5)@@ -39,7 +39,7 @@ require (github.com/gorilla/websocket v1.5.3 // indirectgithub.com/hashicorp/hcl v1.0.0 // indirectgithub.com/inconshreveable/mousetrap v1.1.0 // indirect- github.com/klauspost/compress v1.17.11 // indirect+ github.com/klauspost/compress v1.18.0 // indirectgithub.com/magiconair/properties v1.8.9 // indirectgithub.com/mattn/go-colorable v0.1.14 // indirectgithub.com/mattn/go-isatty v0.0.20 // indirect@@ -59,12 +59,12 @@ require (github.com/subosito/gotenv v1.6.0 // indirectgithub.com/valyala/bytebufferpool v1.0.0 // indirectgithub.com/valyala/tcplisten v1.0.0 // indirect- go.mau.fi/util v0.8.4 // indirect+ go.mau.fi/util v0.8.5 // indirectgo.uber.org/multierr v1.11.0 // indirect- golang.org/x/crypto v0.33.0 // indirect- golang.org/x/exp v0.0.0-20250207012021-f9890c6ad9f3 // indirect+ golang.org/x/crypto v0.34.0 // indirect+ golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa // indirectgolang.org/x/image v0.24.0 // indirect- golang.org/x/net v0.34.0 // indirect+ golang.org/x/net v0.35.0 // indirectgolang.org/x/sys v0.30.0 // indirectgolang.org/x/text v0.22.0 // indirectgopkg.in/ini.v1 v1.67.0 // indirectdiff --git a/src/go.sum b/src/go.sumindex d92a42be..b3721dd9 100644--- a/src/go.sum+++ b/src/go.sum@@ -2,6 +2,8 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=github.com/PuerkitoBio/goquery v1.10.1 h1:Y8JGYUkXWTGRB6Ars3+j3kN0xg1YqqlwvdTV8WTFQcU=github.com/PuerkitoBio/goquery v1.10.1/go.mod h1:IYiHrOMps66ag56LEH7QYDDupKXyo5A8qrjIx3ZtujY=+github.com/PuerkitoBio/goquery v1.10.2 h1:7fh2BdHcG6VFZsK7toXBT/Bh1z5Wmy8Q9MV9HqT2AM8=+github.com/PuerkitoBio/goquery v1.10.2/go.mod h1:0guWGjcLu9AYC7C1GHnpysHy056u9aEkUHwhdnePMCU=github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=@@ -11,6 +13,7 @@ github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dgithub.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=+github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=@@ -50,6 +53,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=+github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=+github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=@@ -104,6 +109,8 @@ github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=+github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=+github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=@@ -120,6 +127,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzawgithub.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=github.com/valyala/fasthttp v1.58.0 h1:GGB2dWxSbEprU9j0iMJHgdKYJVDyjrOwF9RE59PbRuE=github.com/valyala/fasthttp v1.58.0/go.mod h1:SYXvHHaFp7QZHGKSHmoMipInhrI5StHrhDTYVEjK/Kw=+github.com/valyala/fasthttp v1.59.0 h1:Qu0qYHfXvPk1mSLNqcFtEk6DpxgA26hy6bmydotDpRI=+github.com/valyala/fasthttp v1.59.0/go.mod h1:GTxNb9Bc6r2a9D0TWNSPwDz78UxnTGBViY3xZNEqyYU=github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=@@ -127,10 +136,16 @@ github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3igithub.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=go.mau.fi/libsignal v0.1.1 h1:m/0PGBh4QKP/I1MQ44ti4C0fMbLMuHb95cmDw01FIpI=go.mau.fi/libsignal v0.1.1/go.mod h1:QLs89F/OA3ThdSL2Wz2p+o+fi8uuQUz0e1BRa6ExdBw=+go.mau.fi/libsignal v0.1.2 h1:Vs16DXWxSKyzVtI+EEXLCSy5pVWzzCzp/2eqFGvLyP0=+go.mau.fi/libsignal v0.1.2/go.mod h1:JpnLSSJptn/s1sv7I56uEMywvz8x4YzxeF5OzdPb6PE=go.mau.fi/util v0.8.4 h1:mVKlJcXWfVo8ZW3f4vqtjGpqtZqJvX4ETekxawt2vnQ=go.mau.fi/util v0.8.4/go.mod h1:MOfGTs1CBuK6ERTcSL4lb5YU7/ujz09eOPVEDckuazY=+go.mau.fi/util v0.8.5 h1:PwCAAtcfK0XxZ4sdErJyfBMkTEWoQU33aB7QqDDzQRI=+go.mau.fi/util v0.8.5/go.mod h1:Ycug9mrbztlahHPEJ6H5r8Nu/xqZaWbE5vPHVWmfz6M=go.mau.fi/whatsmeow v0.0.0-20250210124836-838d5eeaf73e h1:29JB5UMhd3kzLj0GpKUnZM8ZpyP3o9Kd0iDRtXgLvog=go.mau.fi/whatsmeow v0.0.0-20250210124836-838d5eeaf73e/go.mod h1:PG1x7fBW66I9q/e8a9mU2qF9M94+kK32MceMWgxBoiw=+go.mau.fi/whatsmeow v0.0.0-20250221160813-35b965ceadf1 h1:mqlGS29j1rtg4Wl7VbRyd6yHBqLLgvUN2EMnNQ6ZiSY=+go.mau.fi/whatsmeow v0.0.0-20250221160813-35b965ceadf1/go.mod h1:6hRrUtDWI2wTRClOd6m17GwrFE2a8/p5R4pjJsIVn+U=go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=@@ -141,8 +156,12 @@ golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0vgolang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=+golang.org/x/crypto v0.34.0 h1:+/C6tk6rf/+t5DhUketUbD1aNGqiSX3j15Z6xuIDlBA=+golang.org/x/crypto v0.34.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=golang.org/x/exp v0.0.0-20250207012021-f9890c6ad9f3 h1:qNgPs5exUA+G0C96DrPwNrvLSj7GT/9D+3WMWUcUg34=golang.org/x/exp v0.0.0-20250207012021-f9890c6ad9f3/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU=+golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa h1:t2QcU6V556bFjYgu4L6C+6VrCPyJZ+eyRsABUPs1mz4=+golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa/go.mod h1:BHOTPb3L19zxehTsLoJXVaTktb06DFgmdW6Wb9s8jqk=golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=golang.org/x/image v0.24.0 h1:AN7zRgVsbvmTfNyqIbbOraYL8mSwcKncEj8ofjgzcMQ=golang.org/x/image v0.24.0/go.mod h1:4b/ITuLfqYq1hqZcjofwctIhi7sZh2WaCjvsBNjjya8=@@ -162,6 +181,8 @@ golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=+golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=+golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=diff --git a/src/pkg/utils/general.go b/src/pkg/utils/general.goindex 90c8b80d..99faff94 100644--- a/src/pkg/utils/general.go+++ b/src/pkg/utils/general.go@@ -69,20 +69,22 @@ type Metadata struct {Description stringImage stringImageThumb []byte+ Height *uint32+ Width *uint32}-func GetMetaDataFromURL(url string) (meta Metadata) {+func GetMetaDataFromURL(url string) (meta Metadata, err error) {// Send an HTTP GET request to the websiteresponse, err := http.Get(url)if err != nil {- log.Fatal(err)+ return meta, err}defer response.Body.Close()// Parse the HTML documentdocument, err := goquery.NewDocumentFromReader(response.Body)if err != nil {- log.Fatal(err)+ return meta, err}document.Find("meta[name='description']").Each(func(index int, element *goquery.Selection) {@@ -98,6 +100,22 @@ func GetMetaDataFromURL(url string) (meta Metadata) {meta.Image, _ = element.Attr("content")})+ document.Find("meta[property='og:image:width']").Each(func(index int, element *goquery.Selection) {+ if content, exists := element.Attr("content"); exists {+ width, _ := strconv.Atoi(content)+ widthUint32 := uint32(width)+ meta.Width = &widthUint32+ }+ })++ document.Find("meta[property='og:image:height']").Each(func(index int, element *goquery.Selection) {+ if content, exists := element.Attr("content"); exists {+ height, _ := strconv.Atoi(content)+ heightUint32 := uint32(height)+ meta.Height = &heightUint32+ }+ })+// If an og:image is found, download it and store its content in ImageThumbif meta.Image != "" {imageResponse, err := http.Get(meta.Image)@@ -114,7 +132,7 @@ func GetMetaDataFromURL(url string) (meta Metadata) {}}- return meta+ return meta, nil}// ContainsMention is checking if message contains mention, then return only mention without @diff --git a/src/pkg/utils/general_test.go b/src/pkg/utils/general_test.goindex b16c2bfd..88834547 100644--- a/src/pkg/utils/general_test.go+++ b/src/pkg/utils/general_test.go@@ -93,7 +93,8 @@ func (suite *UtilsTestSuite) TestGetMetaDataFromURL() {}))defer server.Close() // Ensure the server is closed when the test ends- meta := utils.GetMetaDataFromURL(server.URL)+ meta, err := utils.GetMetaDataFromURL(server.URL)+ assert.NoError(suite.T(), err)assert.Equal(suite.T(), "Test Title", meta.Title)assert.Equal(suite.T(), "Test Description", meta.Description)assert.Equal(suite.T(), "http://example.com/image.jpg", meta.Image)diff --git a/src/pkg/whatsapp/webhook.go b/src/pkg/whatsapp/webhook.goindex 307b79d3..5a1dc249 100644--- a/src/pkg/whatsapp/webhook.go+++ b/src/pkg/whatsapp/webhook.go@@ -41,7 +41,7 @@ func createPayload(evt *events.Message) (map[string]interface{}, error) {if from := evt.Info.SourceString(); from != "" {body["from"] = from}- if message.Text != "" {+ if message.ID != "" {body["message"] = message}if pushname := evt.Info.PushName; pushname != "" {diff --git a/src/services/send.go b/src/services/send.goindex 0e829616..9a9afa25 100644--- a/src/services/send.go+++ b/src/services/send.go@@ -430,14 +430,19 @@ func (service serviceSend) SendLink(ctx context.Context, request domainSend.Linkreturn response, err}- getMetaDataFromURL := utils.GetMetaDataFromURL(request.Link)+ getMetaDataFromURL, err := utils.GetMetaDataFromURL(request.Link)+ if err != nil {+ return response, err+ }msg := &waE2E.Message{ExtendedTextMessage: &waE2E.ExtendedTextMessage{- Text: proto.String(fmt.Sprintf("%s\n%s", request.Caption, request.Link)),- Title: proto.String(getMetaDataFromURL.Title),- MatchedText: proto.String(request.Link),- Description: proto.String(getMetaDataFromURL.Description),- JPEGThumbnail: getMetaDataFromURL.ImageThumb,+ Text: proto.String(fmt.Sprintf("%s\n%s", request.Caption, request.Link)),+ Title: proto.String(getMetaDataFromURL.Title),+ MatchedText: proto.String(request.Link),+ Description: proto.String(getMetaDataFromURL.Description),+ JPEGThumbnail: getMetaDataFromURL.ImageThumb,+ ThumbnailHeight: getMetaDataFromURL.Height,+ ThumbnailWidth: getMetaDataFromURL.Width,}}content := "🔗 " + request.Link