diff --git a/docs/openapi.yaml b/docs/openapi.yaml index f83081a..0c03677 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: WhatsApp API MultiDevice - version: 3.1.0 + version: 3.2.0 description: This API is used for sending whatsapp via API servers: - url: http://localhost:3000 @@ -194,34 +194,23 @@ paths: schema: type: integer example: '6289685028129@s.whatsapp.net' + - name: is_preview + in: query + schema: + type: boolean + example: true + - name: is_preview + in: query + schema: + type: integer + example: true responses: '200': description: OK - headers: - Date: - schema: - type: string - example: Fri, 11 Feb 2022 03:43:39 GMT - Content-Type: - schema: - type: string - example: application/json - Content-Length: - schema: - type: integer - example: '244' content: application/json: schema: - type: object - example: - code: 200 - message: Success - results: - url: >- - https://pps.whatsapp.net/v/t61.24694-24/181358562_385581386633509_6230178822944778044_n.jpg?ccb=11-4&oh=df36c5b990497b8a5758a0f1ad8118a8&oe=620AA726 - id: '1635239861' - type: image + $ref: '#/components/schemas/UserAvatarResponse' '400': description: Bad Request content: @@ -651,12 +640,67 @@ paths: components: schemas: + UserGroupResponse: + type: object + properties: + message: + type: string + example: Success get list groups + results: + type: object + properties: + data: + type: array + items: + type: object + properties: + JID: + type: string + OwnerJID: + type: string + Name: + type: string + NameSetAt: + type: string + NameSetBy: + type: string + GroupCreated: + type: string + ParticipantVersionID: + type: string + Participants: + type: array + items: + properties: + JID: + type: string + IsAdmin: + type: boolean + IsSuperAdmin: + type: boolean + Error: + type: number + UserAvatarResponse: + type: object + properties: + message: + type: string + example: Success + results: + type: object + properties: + url: + type: string + example: 'https://pps.whatsapp.net/v/t61.24694-24/181358562_385581386633509_6230178822944778044_n.jpg?ccb=11-4&oh=df36c5b990497b8a5758a0f1ad8118a8&oe=620AA726' + id: + type: string + example: '1635239861' + type: + type: string + example: 'image' SendResponse: type: object properties: - code: - type: integer - example: 200 message: type: string example: Success diff --git a/readme.md b/readme.md index 222f2b9..bdce06e 100644 --- a/readme.md +++ b/readme.md @@ -127,7 +127,7 @@ API using [openapi-generator](https://openapi-generator.tech/#try) 8. Send Location ![Send Location](https://i.ibb.co/TWsy09G/send-location.png) 9. Revoke Message ![Revoke Message](https://i.ibb.co/yswhvQY/revoke.png?) 10. User Info ![User Info](https://i.ibb.co/3zjX6Cz/user-info.png) -11. User Avatar ![User Avatar](https://i.ibb.co/cysjmjT/user-avatar.png?) +11. User Avatar ![User Avatar](https://i.ibb.co/ZmJZ4ZW/search-avatar.png) 12. My Privacy ![My Privacy](https://i.ibb.co/Cw1sMQz/my-privacy.png) 13. My Group ![My Group](https://i.ibb.co/B6rW8Sh/list-group.png) 14. Auto Reply ![Auto Reply](https://i.ibb.co/D4rTytX/IMG-20220517-162500.jpg) diff --git a/src/config/settings.go b/src/config/settings.go index 094a56f..19d9b41 100644 --- a/src/config/settings.go +++ b/src/config/settings.go @@ -6,7 +6,7 @@ import ( ) var ( - AppVersion = "v4.3.0" + AppVersion = "v4.4.0" AppPort = "3000" AppDebug = false AppOs = fmt.Sprintf("AldinoKemal") diff --git a/src/domains/user/account.go b/src/domains/user/account.go index 2d6fc75..4d6369c 100644 --- a/src/domains/user/account.go +++ b/src/domains/user/account.go @@ -26,7 +26,9 @@ type InfoResponse struct { } type AvatarRequest struct { - Phone string `json:"phone" query:"phone"` + Phone string `json:"phone" query:"phone"` + IsPreview bool `json:"is_preview" query:"is_preview"` + IsCommunity bool `json:"is_community" query:"is_community"` } type AvatarResponse struct { diff --git a/src/go.mod b/src/go.mod index 7032844..5b9dd98 100644 --- a/src/go.mod +++ b/src/go.mod @@ -1,21 +1,21 @@ module github.com/aldinokemal/go-whatsapp-web-multidevice -go 1.18 +go 1.19 require ( github.com/dustin/go-humanize v1.0.0 github.com/go-ozzo/ozzo-validation/v4 v4.3.0 - github.com/gofiber/fiber/v2 v2.40.0 - github.com/gofiber/template v1.7.2 - github.com/gofiber/websocket/v2 v2.1.1 + github.com/gofiber/fiber/v2 v2.40.1 + github.com/gofiber/template v1.7.3 + github.com/gofiber/websocket/v2 v2.1.2 github.com/h2non/bimg v1.1.9 github.com/markbates/pkger v0.17.1 github.com/mattn/go-sqlite3 v1.14.16 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/spf13/cobra v1.6.1 github.com/stretchr/testify v1.8.0 - github.com/valyala/fasthttp v1.41.0 - go.mau.fi/whatsmeow v0.0.0-20221122081206-059049466d44 + github.com/valyala/fasthttp v1.43.0 + go.mau.fi/whatsmeow v0.0.0-20221213225758-70ef67df3c68 google.golang.org/protobuf v1.28.1 ) @@ -27,8 +27,8 @@ require ( github.com/fasthttp/websocket v1.5.0 // indirect github.com/gobuffalo/here v0.6.7 // indirect github.com/gorilla/websocket v1.5.0 // indirect - github.com/inconshreveable/mousetrap v1.0.1 // indirect - github.com/klauspost/compress v1.15.12 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/klauspost/compress v1.15.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.16 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect @@ -39,7 +39,7 @@ require ( github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect go.mau.fi/libsignal v0.0.0-20221015105917-d970e7c3c9cf // indirect - golang.org/x/crypto v0.3.0 // indirect - golang.org/x/sys v0.2.0 // indirect + golang.org/x/crypto v0.4.0 // indirect + golang.org/x/sys v0.3.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/src/go.sum b/src/go.sum index 64c1235..f6845d3 100644 --- a/src/go.sum +++ b/src/go.sum @@ -142,13 +142,12 @@ github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PL github.com/gobuffalo/here v0.6.7 h1:hpfhh+kt2y9JLDfhYUxxCRxQol540jsVfKUZzjlbp8o= github.com/gobuffalo/here v0.6.7/go.mod h1:vuCfanjqckTuRlqAitJz6QC4ABNnS27wLb816UhsPcc= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gofiber/fiber/v2 v2.39.0/go.mod h1:Cmuu+elPYGqlvQvdKyjtYsjGMi69PDp8a1AY2I5B2gM= -github.com/gofiber/fiber/v2 v2.40.0 h1:fdU7w5hT6PLL7jiWIhtQ+S/k5WEFYoUZidptlPu8GBo= -github.com/gofiber/fiber/v2 v2.40.0/go.mod h1:Gko04sLksnHbzLSRBFWPFdzM9Ws9pRxvvIaohJK1dsk= -github.com/gofiber/template v1.7.2 h1:sCHY5WcvmLtR7t8ihXCs5HRdYv4W9EzgBIMbUl4a5zw= -github.com/gofiber/template v1.7.2/go.mod h1:uk/mUKTXJMBMoETvo/5CA/QlTFERHMooOm0pJPGDGVA= -github.com/gofiber/websocket/v2 v2.1.1 h1:Q88s88UL8B+elZTT/QB+ocDb1REhdMEmnysI0C9zzqs= -github.com/gofiber/websocket/v2 v2.1.1/go.mod h1:F0ES7DhlFrNyHtC2UGey2KYI+zdqIURRMbSF0C4qdGQ= +github.com/gofiber/fiber/v2 v2.40.1 h1:pc7n9VVpGIqNsvg9IPLQhyFEMJL8gCs1kneH5D1pIl4= +github.com/gofiber/fiber/v2 v2.40.1/go.mod h1:Gko04sLksnHbzLSRBFWPFdzM9Ws9pRxvvIaohJK1dsk= +github.com/gofiber/template v1.7.3 h1:ddWRgCB7kDdsgH7Qakwmlj6qM3kjggaT0aIhxLGatD0= +github.com/gofiber/template v1.7.3/go.mod h1:MI/DIYL6czowb8KLkkNAojCifLnAVQcN3KGEUDvlFtU= +github.com/gofiber/websocket/v2 v2.1.2 h1:EulKyLB/fJgui5+6c8irwEnYQ9FRsrLZfkrq9OfTDGc= +github.com/gofiber/websocket/v2 v2.1.2/go.mod h1:S+sKWo0xeC7Wnz5h4/8f6D/NxsrLFIdWDYB3SyVO9pE= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -263,8 +262,9 @@ github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47 github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -275,10 +275,9 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.14.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= -github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM= -github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= +github.com/klauspost/compress v1.15.13 h1:NFn1Wr8cfnenSJSA46lLq4wHCcBzKTSjnBIexDMMOV0= +github.com/klauspost/compress v1.15.13/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -396,9 +395,9 @@ github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqri 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.33.0/go.mod h1:KJRK/MXx0J+yd0c5hlR+s1tIHD72sniU8ZJjl97LIw4= -github.com/valyala/fasthttp v1.40.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I= -github.com/valyala/fasthttp v1.41.0 h1:zeR0Z1my1wDHTRiamBCXVglQdbUwgb9uWG3k1HQz6jY= github.com/valyala/fasthttp v1.41.0/go.mod h1:f6VbjjoI3z1NDOZOv17o6RvtRSWxC77seBFc2uWtgiY= +github.com/valyala/fasthttp v1.43.0 h1:Gy4sb32C98fbzVWZlTM1oTMdLWGyvxR03VhM6cBIU4g= +github.com/valyala/fasthttp v1.43.0/go.mod h1:f6VbjjoI3z1NDOZOv17o6RvtRSWxC77seBFc2uWtgiY= 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/yosssi/ace v0.0.5/go.mod h1:ALfIzm2vT7t5ZE7uoIZqF3TQ7SAOyupFZnkrF5id+K0= @@ -413,8 +412,8 @@ go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3 go.etcd.io/etcd/client/v2 v2.305.1/go.mod h1:pMEacxZW7o8pg4CrFE7pquyCJJzZvkvdD2RibOCCCGs= go.mau.fi/libsignal v0.0.0-20221015105917-d970e7c3c9cf h1:mzPxXBgDPHKDHMVV1tIWh7lwCiRpzCsXC0gNRX+K07c= go.mau.fi/libsignal v0.0.0-20221015105917-d970e7c3c9cf/go.mod h1:XCjaU93vl71YNRPn059jMrK0xRDwVO5gKbxoPxow9mQ= -go.mau.fi/whatsmeow v0.0.0-20221122081206-059049466d44 h1:2VmJLzAZh/yQIt0hmbwBeciHQpC1tyfX9l1gOUGhhTI= -go.mau.fi/whatsmeow v0.0.0-20221122081206-059049466d44/go.mod h1:2yweL8nczvtlIxkrvCb0y8xiO13rveX9lJPambwYV/E= +go.mau.fi/whatsmeow v0.0.0-20221213225758-70ef67df3c68 h1:uieThnMYyFDdUNDrHxauuZOW5ip+igWhHwyWFNjA2Sw= +go.mau.fi/whatsmeow v0.0.0-20221213225758-70ef67df3c68/go.mod h1:2yweL8nczvtlIxkrvCb0y8xiO13rveX9lJPambwYV/E= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -438,8 +437,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A= -golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8= +golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -522,7 +521,6 @@ golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220111093109-d55c255bac03/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220906165146-f3363e06e74c/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -618,13 +616,11 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/src/internal/rest/user.go b/src/internal/rest/user.go index fa3cd25..80d0d2d 100644 --- a/src/internal/rest/user.go +++ b/src/internal/rest/user.go @@ -21,13 +21,6 @@ func InitRestUser(app *fiber.App, service domainUser.IUserService) User { return rest } -func (controller *User) Route(app *fiber.App) { - app.Get("/user/info", controller.UserInfo) - app.Get("/user/avatar", controller.UserAvatar) - app.Get("/user/my/privacy", controller.UserMyPrivacySetting) - app.Get("/user/my/groups", controller.UserMyListGroups) -} - func (controller *User) UserInfo(c *fiber.Ctx) error { var request domainUser.InfoRequest err := c.QueryParser(&request) @@ -35,7 +28,7 @@ func (controller *User) UserInfo(c *fiber.Ctx) error { whatsapp.SanitizePhone(&request.Phone) - response, err := controller.Service.Info(c.Context(), request) + response, err := controller.Service.Info(c.UserContext(), request) utils.PanicIfNeeded(err) return c.JSON(utils.ResponseData{ @@ -52,7 +45,7 @@ func (controller *User) UserAvatar(c *fiber.Ctx) error { whatsapp.SanitizePhone(&request.Phone) - response, err := controller.Service.Avatar(c.Context(), request) + response, err := controller.Service.Avatar(c.UserContext(), request) utils.PanicIfNeeded(err) return c.JSON(utils.ResponseData{ diff --git a/src/pkg/error/generic_error.go b/src/pkg/error/generic_error.go index 0a0ab8d..4665840 100644 --- a/src/pkg/error/generic_error.go +++ b/src/pkg/error/generic_error.go @@ -25,3 +25,20 @@ func (e InternalServerError) ErrCode() string { func (e InternalServerError) StatusCode() int { return http.StatusInternalServerError } + +type ContextError string + +// Error for complying the error interface +func (e ContextError) Error() string { + return string(e) +} + +// ErrCode will return the error code based on the error data type +func (e ContextError) ErrCode() string { + return "CONTEXT_ERROR" +} + +// StatusCode will return the HTTP status code based on the error data type +func (e ContextError) StatusCode() int { + return http.StatusRequestTimeout +} diff --git a/src/pkg/utils/response.go b/src/pkg/utils/response.go index 74331b9..f76b3c2 100644 --- a/src/pkg/utils/response.go +++ b/src/pkg/utils/response.go @@ -1,7 +1,7 @@ package utils type ResponseData struct { - Status int + Status int `json:"-"` Code string `json:"code,omitempty"` Message string `json:"message"` Results any `json:"results"` diff --git a/src/services/user.go b/src/services/user.go index ba24d7b..c87020c 100644 --- a/src/services/user.go +++ b/src/services/user.go @@ -5,10 +5,12 @@ import ( "errors" "fmt" domainUser "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/user" + pkgError "github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/error" "github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/whatsapp" "github.com/aldinokemal/go-whatsapp-web-multidevice/validations" "go.mau.fi/whatsmeow" "go.mau.fi/whatsmeow/types" + "time" ) type userService struct { @@ -65,26 +67,50 @@ func (service userService) Info(ctx context.Context, request domainUser.InfoRequ } func (service userService) Avatar(ctx context.Context, request domainUser.AvatarRequest) (response domainUser.AvatarResponse, err error) { - err = validations.ValidateUserAvatar(ctx, request) - if err != nil { - return response, err - } - dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone) - if err != nil { - return response, err - } - pic, err := service.WaCli.GetProfilePictureInfo(dataWaRecipient, false, "") - if err != nil { - return response, err - } else if pic == nil { - return response, errors.New("no avatar found") - } else { - response.URL = pic.URL - response.ID = pic.ID - response.Type = pic.Type - - return response, nil + + chanResp := make(chan domainUser.AvatarResponse) + chanErr := make(chan error) + waktu := time.Now() + + go func() { + err = validations.ValidateUserAvatar(ctx, request) + if err != nil { + chanErr <- err + } + dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone) + if err != nil { + chanErr <- err + } + pic, err := service.WaCli.GetProfilePictureInfo(dataWaRecipient, &whatsmeow.GetProfilePictureParams{ + Preview: request.IsPreview, + IsCommunity: request.IsCommunity, + }) + if err != nil { + chanErr <- err + } else if pic == nil { + chanErr <- errors.New("no avatar found") + } else { + response.URL = pic.URL + response.ID = pic.ID + response.Type = pic.Type + + chanResp <- response + } + }() + + for { + select { + case err := <-chanErr: + return response, err + case response := <-chanResp: + return response, nil + default: + if waktu.Add(2 * time.Second).Before(time.Now()) { + return response, pkgError.ContextError("Error timeout get avatar !") + } + } } + } func (service userService) MyListGroups(_ context.Context) (response domainUser.MyListGroupsResponse, err error) { diff --git a/src/validations/user_validation.go b/src/validations/user_validation.go index 36a27fe..5f6e359 100644 --- a/src/validations/user_validation.go +++ b/src/validations/user_validation.go @@ -21,6 +21,8 @@ func ValidateUserInfo(ctx context.Context, request domainUser.InfoRequest) error func ValidateUserAvatar(ctx context.Context, request domainUser.AvatarRequest) error { err := validation.ValidateStructWithContext(ctx, &request, validation.Field(&request.Phone, validation.Required), + validation.Field(&request.IsCommunity, validation.When(request.IsCommunity, validation.Required, validation.In(true, false))), + validation.Field(&request.IsPreview, validation.When(request.IsPreview, validation.Required, validation.In(true, false))), ) if err != nil { diff --git a/src/validations/user_validation_test.go b/src/validations/user_validation_test.go index 15f7751..95b7a16 100644 --- a/src/validations/user_validation_test.go +++ b/src/validations/user_validation_test.go @@ -20,14 +20,18 @@ func TestValidateUserAvatar(t *testing.T) { { name: "should success", args: args{request: domainUser.AvatarRequest{ - Phone: "1728937129312@s.whatsapp.net", + Phone: "1728937129312@s.whatsapp.net", + IsPreview: false, + IsCommunity: false, }}, err: nil, }, { name: "should error with empty phone", args: args{request: domainUser.AvatarRequest{ - Phone: "", + Phone: "", + IsPreview: false, + IsCommunity: false, }}, err: pkgError.ValidationError("phone: cannot be blank."), }, diff --git a/src/views/index.html b/src/views/index.html index 28f3d16..5719d69 100644 --- a/src/views/index.html +++ b/src/views/index.html @@ -599,6 +599,22 @@ +
+ +
+ + +
+
+ +
+ +
+ + +
+
+