diff --git a/.dockerignore b/.dockerignore index 6e2d670..4b31a5f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,7 @@ dist vendor dbs/* +.bin/ .env **/.DS_Store **/.gitkeep \ No newline at end of file diff --git a/.env.default b/.env.default index e6a6f17..dbfcbb2 100644 --- a/.env.default +++ b/.env.default @@ -19,11 +19,11 @@ HTTP_BASE_URL=/api/v1/whatsapp # ----------------------------------- # Authentication Configuration # ----------------------------------- -# AUTH_BASIC_USERNAME=admin -# AUTH_BASIC_PASSWORD=password +AUTH_BASIC_USERNAME=admin +AUTH_BASIC_PASSWORD=password -# AUTH_JWT_SECRET=secret -# AUTH_JWT_EXPIRED_HOUR=24 +AUTH_JWT_SECRET=secret +AUTH_JWT_EXPIRED_HOUR=24 # ----------------------------------- # WhatsApp Configuration @@ -37,3 +37,8 @@ WHATSAPP_MEDIA_IMAGE_CONVERT_WEBP=true # WHATSAPP_VERSION_MAJOR=2 # WHATSAPP_VERSION_MINOR=2216 # WHATSAPP_VERSION_PATCH=8 + +# ----------------------------------- +# 3rd Party Configuration +# ----------------------------------- +LIBWEBP_VERSION=0.6.1 diff --git a/.env.development b/.env.development index de05f62..4ca3fe8 100644 --- a/.env.development +++ b/.env.development @@ -37,3 +37,8 @@ WHATSAPP_MEDIA_IMAGE_CONVERT_WEBP=true # WHATSAPP_VERSION_MAJOR=2 # WHATSAPP_VERSION_MINOR=2216 # WHATSAPP_VERSION_PATCH=8 + +# ----------------------------------- +# 3rd Party Configuration +# ----------------------------------- +LIBWEBP_VERSION=0.6.1 diff --git a/.env.production b/.env.production index 2220735..1d3d8f8 100644 --- a/.env.production +++ b/.env.production @@ -37,3 +37,8 @@ WHATSAPP_MEDIA_IMAGE_CONVERT_WEBP=true # WHATSAPP_VERSION_MAJOR=2 # WHATSAPP_VERSION_MINOR=2216 # WHATSAPP_VERSION_PATCH=8 + +# ----------------------------------- +# 3rd Party Configuration +# ----------------------------------- +LIBWEBP_VERSION=0.6.1 diff --git a/.gitignore b/.gitignore index 6f67b53..e82245c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ dist vendor dbs/* +.bin/ .env *.DS_Store !*.gitkeep \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml index 0e43807..8e08616 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -6,7 +6,8 @@ builds: env: - CGO_ENABLED=0 ldflags: - - -s -w + - -s + - -w goos: - darwin - linux diff --git a/Dockerfile b/Dockerfile index 8068384..28c015f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN go mod download \ # Final Image # --------------------------------------------------- -FROM dimaskiddo/alpine:base +FROM dimaskiddo/debian-buster:base MAINTAINER Dimas Restu Hidayanto ARG SERVICE_NAME="go-whatsapp-multidevice-rest" @@ -21,8 +21,8 @@ ENV PATH $PATH:/usr/app/${SERVICE_NAME} WORKDIR /usr/app/${SERVICE_NAME} -RUN mkdir -p dbs \ - && chmod 755 dbs +RUN mkdir -p {.bin/webp,dbs} \ + && chmod 775 {.bin/webp,dbs} COPY --from=go-builder /usr/src/app/.env.default ./.env COPY --from=go-builder /usr/src/app/main ./main diff --git a/Makefile b/Makefile index a522d78..8d08a6a 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,9 @@ gen-docs: rm -rf docs/* swag init -g cmd/main/main.go --output docs +clean-dbs: + rm -f dbs/WhatsApp.db + clean-dist: rm -rf dist @@ -53,6 +56,7 @@ clean-build: rm -f $(SERVICE_NAME) clean: + make clean-dbs make clean-dist make clean-build rm -rf vendor diff --git a/docs/docs.go b/docs/docs.go index 03639f4..bd45e8c 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -400,6 +400,47 @@ const docTemplate = `{ } } }, + "/api/v1/whatsapp/send/sticker": { + "post": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Send Sticker Message to Spesific Phone Number", + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "WhatsApp Message" + ], + "summary": "Send Sticker Message", + "parameters": [ + { + "type": "string", + "description": "Destination Phone Number", + "name": "msisdn", + "in": "formData", + "required": true + }, + { + "type": "file", + "description": "Sticker File", + "name": "sticker", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "" + } + } + } + }, "/api/v1/whatsapp/send/text": { "post": { "security": [ diff --git a/docs/swagger.json b/docs/swagger.json index f821794..0091a0c 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -395,6 +395,47 @@ } } }, + "/api/v1/whatsapp/send/sticker": { + "post": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Send Sticker Message to Spesific Phone Number", + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "WhatsApp Message" + ], + "summary": "Send Sticker Message", + "parameters": [ + { + "type": "string", + "description": "Destination Phone Number", + "name": "msisdn", + "in": "formData", + "required": true + }, + { + "type": "file", + "description": "Sticker File", + "name": "sticker", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "" + } + } + } + }, "/api/v1/whatsapp/send/text": { "post": { "security": [ diff --git a/docs/swagger.yaml b/docs/swagger.yaml index fec9e54..fe7953a 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -250,6 +250,32 @@ paths: summary: Send Location Message tags: - WhatsApp Message + /api/v1/whatsapp/send/sticker: + post: + consumes: + - multipart/form-data + description: Send Sticker Message to Spesific Phone Number + parameters: + - description: Destination Phone Number + in: formData + name: msisdn + required: true + type: string + - description: Sticker File + in: formData + name: sticker + required: true + type: file + produces: + - application/json + responses: + "200": + description: "" + security: + - BearerAuth: [] + summary: Send Sticker Message + tags: + - WhatsApp Message /api/v1/whatsapp/send/text: post: consumes: diff --git a/go.mod b/go.mod index 1d4fc50..82716bc 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/golang-jwt/jwt v3.2.2+incompatible github.com/joho/godotenv v1.3.0 github.com/labstack/echo/v4 v4.7.2 + github.com/nickalie/go-webpbin v0.0.0-20220110095747-f10016bf2dc1 github.com/sirupsen/logrus v1.8.1 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/sunshineplan/imgconv v1.0.5 @@ -24,12 +25,14 @@ require ( github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/disintegration/imaging v1.6.2 // indirect + github.com/dsnet/compress v0.0.1 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.19.6 // indirect github.com/go-openapi/spec v0.20.4 // indirect github.com/go-openapi/swag v0.19.15 // indirect github.com/go-playground/locales v0.13.0 // indirect github.com/go-playground/universal-translator v0.17.0 // indirect + github.com/golang/snappy v0.0.4 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/hhrutter/lzw v0.0.0-20190829144645-6f07a24e8650 // indirect @@ -41,14 +44,20 @@ require ( github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.11 // indirect github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mholt/archiver v3.1.1+incompatible // indirect + github.com/nickalie/go-binwrapper v0.0.0-20190114141239-525121d43c84 // indirect + github.com/nwaples/rardecode v1.1.0 // indirect github.com/pdfcpu/pdfcpu v0.3.13 // indirect + github.com/pierrec/lz4 v2.6.1+incompatible // indirect github.com/pkg/errors v0.9.1 // indirect github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect github.com/sunshineplan/pdf v1.0.2 // indirect github.com/sunshineplan/tiff v0.0.0-20220128141034-29b9d69bd906 // indirect github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 // indirect + github.com/ulikunitz/xz v0.5.10 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.1 // indirect + github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect go.mau.fi/libsignal v0.0.0-20220425070825-c40c839ee6a0 // indirect golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect diff --git a/go.sum b/go.sum index 92d98ec..d3fe018 100644 --- a/go.sum +++ b/go.sum @@ -31,6 +31,9 @@ github.com/dgryski/go-rendezvous v0.0.0-20200609043717-5ab96a526299/go.mod h1:cu github.com/dgryski/go-rendezvous v0.0.0-20200624174652-8d2f3be8b2d9/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= +github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q= +github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo= +github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -76,6 +79,8 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -102,8 +107,10 @@ github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFF github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= +github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.10.5/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -132,8 +139,16 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= +github.com/mholt/archiver v3.1.1+incompatible h1:1dCVxuqs0dJseYEhi5pl7MYPH9zDa1wBi7mF09cbNkU= +github.com/mholt/archiver v3.1.1+incompatible/go.mod h1:Dh2dOXnSdiLxRiPoVfIr/fI1TwETms9B8CTWfeh7ROU= github.com/mmcloughlin/avo v0.0.0-20200504053806-fa88270b07e4/go.mod h1:wqKykBG2QzQDJEzvRkcS8x6MiSJkF52hXZsXcjaB3ls= +github.com/nickalie/go-binwrapper v0.0.0-20190114141239-525121d43c84 h1:/6MoQlTdk1eAi0J9O89ypO8umkp+H7mpnSF2ggSL62Q= +github.com/nickalie/go-binwrapper v0.0.0-20190114141239-525121d43c84/go.mod h1:Eeech2fhQ/E4bS8cdc3+SGABQ+weQYGyWBvZ/mNr5uY= +github.com/nickalie/go-webpbin v0.0.0-20220110095747-f10016bf2dc1 h1:9awJsNP+gYOGCr3pQu9i217bCNsVwoQCmD3h7CYwxOw= +github.com/nickalie/go-webpbin v0.0.0-20220110095747-f10016bf2dc1/go.mod h1:m5oz0fmp+uyRBxxFkvciIpe1wd2JZ3pDVJ3x/D8/EGw= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/nwaples/rardecode v1.1.0 h1:vSxaY8vQhOcVr4mm5e8XllHWTiM4JF507A0Katqw7MQ= +github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= @@ -145,6 +160,8 @@ github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT9 github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc= github.com/pdfcpu/pdfcpu v0.3.13 h1:VFon2Yo1PJt+sA57vPAeXWGLSZ7Ux3Jl4h02M0+s3dg= github.com/pdfcpu/pdfcpu v0.3.13/go.mod h1:UJc5xsXg0fpmjp1zOPdyYcAQArc/Zf3V0nv5URe+9fg= +github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= +github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -179,6 +196,9 @@ github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 h1:+iNTcqQJy0OZ5jk6a5 github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2/go.mod h1:lKJPbtWzJ9JhsTN1k1gZgleJWY/cqq0psdoMmaThG3w= github.com/swaggo/swag v1.8.1 h1:JuARzFX1Z1njbCGz+ZytBR15TFJwF2Q7fu8puJHhQYI= github.com/swaggo/swag v1.8.1/go.mod h1:ugemnJsPZm/kRwFUnzBlbHRd0JY9zE1M4F+uy2pAaPQ= +github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8= +github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8= +github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= @@ -192,6 +212,8 @@ github.com/vmihailenco/msgpack/v4 v4.3.11/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+ github.com/vmihailenco/msgpack/v5 v5.0.0-alpha.2/go.mod h1:LDfrk4wJpSFwkzNOJxrCWiSm8c7Iqw/hXNPT2fzQfE8= github.com/vmihailenco/msgpack/v5 v5.0.0-beta.1/go.mod h1:xlngVLeyQ/Qi05oQxhQ+oTuqa03RjMwMfk/7/TCs+QI= github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= +github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= +github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= @@ -215,6 +237,7 @@ golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/image v0.0.0-20190823064033-3a9bac650e44/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ= golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/internal/route.go b/internal/route.go index 837718e..ee5b86f 100644 --- a/internal/route.go +++ b/internal/route.go @@ -44,5 +44,6 @@ func Routes(e *echo.Echo) { e.POST(router.BaseURL+"/send/image", ctlWhatsApp.SendImage, middleware.JWTWithConfig(authJWTConfig)) e.POST(router.BaseURL+"/send/audio", ctlWhatsApp.SendAudio, middleware.JWTWithConfig(authJWTConfig)) e.POST(router.BaseURL+"/send/video", ctlWhatsApp.SendVideo, middleware.JWTWithConfig(authJWTConfig)) + e.POST(router.BaseURL+"/send/sticker", ctlWhatsApp.SendSticker, middleware.JWTWithConfig(authJWTConfig)) e.POST(router.BaseURL+"/logout", ctlWhatsApp.Logout, middleware.JWTWithConfig(authJWTConfig)) } diff --git a/internal/whatsapp/whatsapp.go b/internal/whatsapp/whatsapp.go index efd009c..06c6298 100644 --- a/internal/whatsapp/whatsapp.go +++ b/internal/whatsapp/whatsapp.go @@ -343,6 +343,21 @@ func SendVideo(c echo.Context) error { return sendMedia(c, "video") } +// SendSticker +// @Summary Send Sticker Message +// @Description Send Sticker Message to Spesific Phone Number +// @Tags WhatsApp Message +// @Accept multipart/form-data +// @Produce json +// @Param msisdn formData string true "Destination Phone Number" +// @Param sticker formData file true "Sticker File" +// @Success 200 +// @Security BearerAuth +// @Router /api/v1/whatsapp/send/sticker [post] +func SendSticker(c echo.Context) error { + return sendMedia(c, "sticker") +} + func sendMedia(c echo.Context, mediaType string) error { var err error jid := jwtPayload(c).JID @@ -369,6 +384,9 @@ func sendMedia(c echo.Context, mediaType string) error { case "video": fileStream, fileHeader, err = c.Request().FormFile("video") reqSendMessage.Message = strings.TrimSpace(c.FormValue("caption")) + + case "sticker": + fileStream, fileHeader, err = c.Request().FormFile("sticker") } // Don't Forget to Close The File Stream @@ -428,6 +446,9 @@ func sendMedia(c echo.Context, mediaType string) error { case "video": resSendMessage.MsgID, err = pkgWhatsApp.WhatsAppSendVideo(jid, reqSendMessage.RJID, fileBytes, fileType, reqSendMessage.Message, reqSendMessage.ViewOnce) + + case "sticker": + resSendMessage.MsgID, err = pkgWhatsApp.WhatsAppSendSticker(jid, reqSendMessage.RJID, fileBytes) } // Return Internal Server Error diff --git a/pkg/whatsapp/whatsapp.go b/pkg/whatsapp/whatsapp.go index 60e9014..8796636 100644 --- a/pkg/whatsapp/whatsapp.go +++ b/pkg/whatsapp/whatsapp.go @@ -8,6 +8,7 @@ import ( "fmt" "strings" + webp "github.com/nickalie/go-webpbin" "github.com/sunshineplan/imgconv" qrCode "github.com/skip2/go-qrcode" @@ -721,3 +722,68 @@ func WhatsAppSendLink(jid string, rjid string, linkCaption string, linkURL strin // Return Error WhatsApp Client is not Valid return "", errors.New("WhatsApp Client is not Valid") } + +func WhatsAppSendSticker(jid string, rjid string, stickerBytes []byte) (string, error) { + if WhatsAppClient[jid] != nil { + var err error + + // Make Sure WhatsApp Client is OK + err = WhatsAppClientIsOK(jid) + if err != nil { + return "", err + } + + // Make Sure Remote JID is Proper JID Type + remoteJID := WhatsAppComposeJID(rjid) + + // Set Chat Presence + WhatsAppComposeStatus(jid, remoteJID, true, false) + defer WhatsAppComposeStatus(jid, remoteJID, false, false) + + stickerConvDecode, err := imgconv.Decode(bytes.NewReader(stickerBytes)) + if err != nil { + return "", errors.New("Error While Decoding Convert Sticker Stream") + } + + stickerConvResize := imgconv.Resize(stickerConvDecode, imgconv.ResizeOption{Width: 512, Height: 512}) + stickerConvEncode := new(bytes.Buffer) + + err = webp.Encode(stickerConvEncode, stickerConvResize) + if err != nil { + return "", errors.New("Error While Encoding Convert Sticker Stream") + } + + stickerBytes = stickerConvEncode.Bytes() + + // Upload Image to WhatsApp Storage Server + stickerUploaded, err := WhatsAppClient[jid].Upload(context.Background(), stickerBytes, whatsmeow.MediaImage) + if err != nil { + return "", errors.New("Error While Uploading Media to WhatsApp Server") + } + + // Compose WhatsApp Proto + msgId := whatsmeow.GenerateMessageID() + msgContent := &waproto.Message{ + StickerMessage: &waproto.StickerMessage{ + Url: proto.String(stickerUploaded.URL), + DirectPath: proto.String(stickerUploaded.DirectPath), + Mimetype: proto.String("image/webp"), + FileLength: proto.Uint64(stickerUploaded.FileLength), + FileSha256: stickerUploaded.FileSHA256, + FileEncSha256: stickerUploaded.FileEncSHA256, + MediaKey: stickerUploaded.MediaKey, + }, + } + + // Send WhatsApp Message Proto + _, err = WhatsAppClient[jid].SendMessage(remoteJID, msgId, msgContent) + if err != nil { + return "", err + } + + return msgId, nil + } + + // Return Error WhatsApp Client is not Valid + return "", errors.New("WhatsApp Client is not Valid") +}