diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 31c4793..2b61892 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: WhatsApp API MultiDevice - version: 2.5.0 + version: 3.0.0 description: This API is used for sending whatsapp via API servers: - url: http://localhost:3000 @@ -10,8 +10,8 @@ tags: description: Initial Connection to Whatsapp server - name: user description: Getting information - - name: send - description: Send Message (Text/Image/File/Video) + - name: message + description: Send or Manipulate Message (Text/Image/File/Video). paths: /app/login: get: @@ -118,7 +118,7 @@ paths: in: query schema: type: integer - example: '6289685024091' + example: '6289685028129@s.whatsapp.net' responses: '200': description: OK @@ -155,17 +155,17 @@ paths: status: you are blocked picture_id: '1635239861' devices: - - User: '6289685024091' + - User: '6289685028129@s.whatsapp.net' Agent: 0 Device: UNKNOWN Server: s.whatsapp.net AD: true - - User: '6289685024091' + - User: '6289685028129@s.whatsapp.net' Agent: 0 Device: SAFARI Server: s.whatsapp.net AD: true - - User: '6289685024091' + - User: '6289685028129@s.whatsapp.net' Agent: 0 Device: IPAD Server: s.whatsapp.net @@ -193,7 +193,7 @@ paths: in: query schema: type: integer - example: '6289685024091' + example: '6289685028129@s.whatsapp.net' responses: '200': description: OK @@ -300,7 +300,7 @@ paths: post: operationId: sendMessage tags: - - send + - message summary: Send Message requestBody: content: @@ -310,14 +310,12 @@ paths: properties: phone: type: integer - example: '6289685024091' + example: '6289685028129@s.whatsapp.net' + description: Phone number with country code message: type: string example: selamat malam - type: - type: string - example: 'user' - description: 'user/group | default: user' + description: Message to send responses: '200': description: OK @@ -341,7 +339,7 @@ paths: post: operationId: sendImage tags: - - send + - message summary: Send Image requestBody: content: @@ -351,23 +349,24 @@ paths: properties: phone: type: integer - example: '6289685024091' + example: '6289685028129@s.whatsapp.net' + description: Phone number with country code caption: type: string example: selamat malam + description: Caption to send view_once: type: boolean example: false + description: View once image: type: string format: binary - type: - type: string - example: 'user' - description: 'user/group | default: user' + description: Image to send compress: type: boolean example: false + description: Compress image responses: '200': description: OK @@ -391,7 +390,7 @@ paths: post: operationId: sendFile tags: - - send + - message summary: Send File requestBody: content: @@ -401,17 +400,16 @@ paths: properties: phone: type: integer - example: '6289685024091' + example: '6289685028129@s.whatsapp.net' + description: Phone number with country code caption: type: string example: selamat malam + description: Caption to send file: type: string format: binary - type: - type: string - example: 'user' - description: 'user/group | default: user' + description: File to send responses: '200': description: OK @@ -435,7 +433,7 @@ paths: post: operationId: sendVideo tags: - - send + - message summary: Send Video requestBody: content: @@ -445,23 +443,24 @@ paths: properties: phone: type: integer - example: '6289685024091' + example: '6289685028129@s.whatsapp.net' + description: Phone number with country code caption: type: string example: ini contoh caption video + description: Caption to send view_once: type: boolean example: 'false' + description: View once video: type: string format: binary - type: - type: string - example: 'user' - description: 'user/group | default: user' + description: Video to send compress: type: boolean example: 'false' + description: Compress video responses: '200': description: OK @@ -485,7 +484,7 @@ paths: post: operationId: sendContact tags: - - send + - message summary: Send Contact requestBody: content: @@ -495,17 +494,16 @@ paths: properties: phone: type: integer - example: '6289685024051' + example: '6289685024051@s.whatsapp.net' + description: Phone number with country code contact_name: type: string example: Aldino Kemal + description: Contact name contact_phone: type: string example: '6289685024992' - type: - type: string - example: 'user' - description: 'user/group | default: user' + description: Contact phone number responses: '200': description: OK @@ -529,7 +527,7 @@ paths: post: operationId: sendLink tags: - - send + - message summary: Send Link requestBody: content: @@ -539,17 +537,55 @@ paths: properties: phone: type: integer - example: '6289685024051' + example: '6289685024051@s.whatsapp.net' + description: Phone number with country code link: type: string example: "https://google.com" + description: Link to send caption: type: string example: 'Halo ini contoh caption' - type: + description: Caption to send + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/SendResponse' + '400': + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorBadRequest' + '500': + description: Internal Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorInternalServer' + /message/:message_id/revoke: + post: + operationId: revokeMessage + tags: + - message + summary: Send Link + requestBody: + content: + multipart/form-data: + schema: + type: object + properties: + phone: + type: integer + example: '6289685024051@s.whatsapp.net' + description: Phone number with country code + message_id: type: string - example: 'user' - description: 'user/group | default: user' + example: "3EB007D87686670344D7" + description: Message ID responses: '200': description: OK diff --git a/readme.md b/readme.md index a89de54..1af8b2b 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,8 @@ ## Go Whatsapp API Multi Device Version [![buddy pipeline](https://app.buddy.works/aldinokemal/go-whatsapp-web-multidevice/pipelines/pipeline/423077/badge.svg?token=a951a4546fe3f54079e678cc9d0eea12069fbdc21f8ed5ea22e1e95c4f63215f "buddy pipeline")](https://app.buddy.works/aldinokemal/go-whatsapp-web-multidevice/pipelines/pipeline/423077) +[![release version](https://img.shields.io/github/v/release/aldinokemal/go-whatsapp-web-multidevice "release version")](https://github.com/aldinokemal/go-whatsapp-web-multidevice/releases) +
[![release windows](https://github.com/aldinokemal/go-whatsapp-web-multidevice/actions/workflows/deploy-windows.yml/badge.svg "release windows")](https://github.com/aldinokemal/go-whatsapp-web-multidevice/actions/workflows/deploy-windows.yml) [![release linux](https://github.com/aldinokemal/go-whatsapp-web-multidevice/actions/workflows/deploy-linux.yml/badge.svg "release linux")](https://github.com/aldinokemal/go-whatsapp-web-multidevice/actions/workflows/deploy-linux.yml) [![release macos](https://github.com/aldinokemal/go-whatsapp-web-multidevice/actions/workflows/deploy-mac.yml/badge.svg "release macos")](https://github.com/aldinokemal/go-whatsapp-web-multidevice/actions/workflows/deploy-mac.yml) @@ -86,23 +88,25 @@ You can fork or edit this source code ! ### Current API -You can check [docs/openapi.yml](./docs/openapi.yaml) for detail API - -| Feature | Menu | Method | URL | -|---------|-------------------------|--------|------------------| -| ✅ | Login | GET | /app/login | -| ✅ | Logout | GET | /app/logout | -| ✅ | Reconnect | GET | /app/reconnect | -| ✅ | User Info | GET | /user/info | -| ✅ | User Avatar | GET | /user/avatar | -| ✅ | User My Group List | GET | /user/my/groups | -| ✅ | User My Privacy Setting | GET | /user/my/privacy | -| ✅ | Send Message | POST | /send/message | -| ✅ | Send Image | POST | /send/image | -| ✅ | Send File | POST | /send/file | -| ✅ | Send Video | POST | /send/video | -| ✅ | Send Contact | POST | /send/contact | -| ✅ | Send Link | POST | /send/link | +You can check [docs/openapi.yml](./docs/openapi.yaml) for detail API, furthermore you can generate HTTP Client from this +API using [openapi-generator](https://openapi-generator.tech/#try) + +| Feature | Menu | Method | URL | +|---------|-------------------------|--------|-----------------------------| +| ✅ | Login | GET | /app/login | +| ✅ | Logout | GET | /app/logout | +| ✅ | Reconnect | GET | /app/reconnect | +| ✅ | User Info | GET | /user/info | +| ✅ | User Avatar | GET | /user/avatar | +| ✅ | User My Group List | GET | /user/my/groups | +| ✅ | User My Privacy Setting | GET | /user/my/privacy | +| ✅ | Send Message | POST | /send/message | +| ✅ | Send Image | POST | /send/image | +| ✅ | Send File | POST | /send/file | +| ✅ | Send Video | POST | /send/video | +| ✅ | Send Contact | POST | /send/contact | +| ✅ | Send Link | POST | /send/link | +| ✅ | Revoke Messave | POST | /message/:message_id/revoke | ``` ✅ = Available @@ -111,19 +115,20 @@ You can check [docs/openapi.yml](./docs/openapi.yaml) for detail API ### App User Interface -1. Homepage ![Homepage](https://i.ibb.co/xjZ7KLr/Screenshot-2022-11-20-at-20-54-52.png) -2. Login ![Login](https://i.ibb.co/Yp3YJKM/Screen-Shot-2022-02-13-at-12-55-54.png) -3. Send Message ![Send Message](https://i.ibb.co/Bng57Ry/Screen-Shot-2022-05-22-at-13-51-13.png) -4. Send Image ![Send Image](https://i.ibb.co/gJj3SrQ/Screen-Shot-2022-05-22-at-13-49-21.png) -5. Send File ![Send File](https://i.ibb.co/nCwhysd/Screen-Shot-2022-05-22-at-13-43-16.png) -6. Send Video ![Send File](https://i.ibb.co/yBXsWXX/Screen-Shot-2022-05-22-at-13-43-24.png) -7. Send Contact ![Send File](https://i.ibb.co/fqwwGK5/Screen-Shot-2022-07-07-at-07-59-26.png) -8. User Info ![User Info](https://i.ibb.co/BC0mNT7/Screen-Shot-2022-02-13-at-13-00-57.png) -9. User Avatar ![User Avatar](https://i.ibb.co/TkzPbLZ/Screen-Shot-2022-02-13-at-13-01-39.png) -10. User Privacy ![User My Privacy](https://i.ibb.co/RQcC5m9/Screen-Shot-2022-02-13-at-12-58-47.png) -11. User Group ![List Group](https://i.ibb.co/jfkgKdG/Screen-Shot-2022-05-12-at-21-12-06.png) -12. Auto Reply ![Auto Reply](https://i.ibb.co/D4rTytX/IMG-20220517-162500.jpg) -13. Basic Auth Prompt ![Basic Auth](https://i.ibb.co/PDjQ92W/Screenshot-2022-11-06-at-14-06-29.png) +1. Homepage ![Homepage](https://i.ibb.co/NNX2wWY/home.png) +2. Login ![Login](https://i.ibb.co/jkcB15R/login.png) +3. Send Message ![Send Message](https://i.ibb.co/DrCVXS7/send-message.png) +4. Send Image ![Send Image](https://i.ibb.co/WykfQc8/send-image.png) +5. Send File ![Send File](https://i.ibb.co/wC4SfRp/send-file.png) +6. Send Video ![Send Video](https://i.ibb.co/VDCRH3G/send-video.png) +7. Send Contact ![Send Contact](https://i.ibb.co/4810H7N/send-contact.png) +8. Revoke Message ![Revoke Message](https://i.ibb.co/yswhvQY/revoke.png) +9. User Info ![User Info](https://i.ibb.co/3zjX6Cz/user-info.png) +10. User Avatar ![User Avatar](https://i.ibb.co/cysjmjT/user-avatar.png) +11. My Privacy ![My Privacy](https://i.ibb.co/Cw1sMQz/my-privacy.png) +12. My Group ![My Group](https://i.ibb.co/B6rW8Sh/list-group.png) +13. Auto Reply ![Auto Reply](https://i.ibb.co/D4rTytX/IMG-20220517-162500.jpg) +14. Basic Auth Prompt ![Basic Auth](https://i.ibb.co/PDjQ92W/Screenshot-2022-11-06-at-14-06-29.png) ### Mac OS NOTE diff --git a/src/cmd/root.go b/src/cmd/root.go index 200e378..8f12a56 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -113,7 +113,7 @@ func runRest(_ *cobra.Command, _ []string) { }) }) - websocket.RegisterRoutes(app) + websocket.RegisterRoutes(app, appService) go websocket.RunHub() // Set auto reconnect to whatsapp server after booting diff --git a/src/config/settings.go b/src/config/settings.go index 71d55a0..d9e45d7 100644 --- a/src/config/settings.go +++ b/src/config/settings.go @@ -6,7 +6,7 @@ import ( ) var ( - AppVersion = "v3.11.0" + AppVersion = "v4.0.0" AppPort = "3000" AppDebug = false AppOs = fmt.Sprintf("AldinoKemal") diff --git a/src/domains/app/devices.go b/src/domains/app/devices.go index cfe9fc2..34c6406 100644 --- a/src/domains/app/devices.go +++ b/src/domains/app/devices.go @@ -1,6 +1,6 @@ package app type FetchDevicesResponse struct { - Name string - Device string + Name string `json:"name"` + Device string `json:"device"` } diff --git a/src/domains/send/contact.go b/src/domains/send/contact.go index fdd275f..86292ba 100644 --- a/src/domains/send/contact.go +++ b/src/domains/send/contact.go @@ -4,7 +4,6 @@ type ContactRequest struct { Phone string `json:"phone" form:"phone"` ContactName string `json:"contact_name" form:"contact_name"` ContactPhone string `json:"contact_phone" form:"contact_phone"` - Type Type `json:"type" form:"type"` } type ContactResponse struct { diff --git a/src/domains/send/file.go b/src/domains/send/file.go index 9288522..5e55347 100644 --- a/src/domains/send/file.go +++ b/src/domains/send/file.go @@ -5,7 +5,6 @@ import "mime/multipart" type FileRequest struct { Phone string `json:"phone" form:"phone"` File *multipart.FileHeader `json:"file" form:"file"` - Type Type `json:"type" form:"type"` } type FileResponse struct { diff --git a/src/domains/send/image.go b/src/domains/send/image.go index 3bffd7d..2beea53 100644 --- a/src/domains/send/image.go +++ b/src/domains/send/image.go @@ -7,7 +7,6 @@ type ImageRequest struct { Caption string `json:"caption" form:"caption"` Image *multipart.FileHeader `json:"image" form:"image"` ViewOnce bool `json:"view_once" form:"view_once"` - Type Type `json:"type" form:"type"` Compress bool `json:"compress"` } diff --git a/src/domains/send/link.go b/src/domains/send/link.go index 83bb68e..75a10c4 100644 --- a/src/domains/send/link.go +++ b/src/domains/send/link.go @@ -4,7 +4,6 @@ type LinkRequest struct { Phone string `json:"phone" form:"phone"` Caption string `json:"caption"` Link string `json:"link"` - Type Type `json:"type" form:"type"` } type LinkResponse struct { diff --git a/src/domains/send/message.go b/src/domains/send/message.go index deadd40..441ce95 100644 --- a/src/domains/send/message.go +++ b/src/domains/send/message.go @@ -3,7 +3,6 @@ package send type RevokeRequest struct { MessageID string `json:"message_id" uri:"message_id"` Phone string `json:"phone" form:"phone"` - Type Type `json:"type" form:"type"` } type RevokeResponse struct { @@ -15,7 +14,6 @@ type UpdateMessageRequest struct { MessageID string `json:"message_id" uri:"message_id"` Message string `json:"message" form:"message"` Phone string `json:"phone" form:"phone"` - Type Type `json:"type" form:"type"` } type UpdateMessageResponse struct { diff --git a/src/domains/send/send.go b/src/domains/send/send.go index 0a282a5..c6fe122 100644 --- a/src/domains/send/send.go +++ b/src/domains/send/send.go @@ -4,11 +4,6 @@ import ( "context" ) -type Type string - -const TypeUser Type = "user" -const TypeGroup Type = "group" - type ISendService interface { SendText(ctx context.Context, request MessageRequest) (response MessageResponse, err error) SendImage(ctx context.Context, request ImageRequest) (response ImageResponse, err error) diff --git a/src/domains/send/text.go b/src/domains/send/text.go index f115fa4..90484b0 100644 --- a/src/domains/send/text.go +++ b/src/domains/send/text.go @@ -3,7 +3,6 @@ package send type MessageRequest struct { Phone string `json:"phone" form:"phone"` Message string `json:"message" form:"message"` - Type Type `json:"type" form:"type"` } type MessageResponse struct { diff --git a/src/domains/send/video.go b/src/domains/send/video.go index 66281db..2e9c644 100644 --- a/src/domains/send/video.go +++ b/src/domains/send/video.go @@ -6,7 +6,6 @@ type VideoRequest struct { Phone string `json:"phone" form:"phone"` Caption string `json:"caption" form:"caption"` Video *multipart.FileHeader `json:"video" form:"video"` - Type Type `json:"type" form:"type"` ViewOnce bool `json:"view_once" form:"view_once"` Compress bool `json:"compress"` } diff --git a/src/internal/rest/app_rest.go b/src/internal/rest/app_rest.go index f8e0ebc..8164960 100644 --- a/src/internal/rest/app_rest.go +++ b/src/internal/rest/app_rest.go @@ -28,7 +28,7 @@ func (controller *App) Login(c *fiber.Ctx) error { return c.JSON(utils.ResponseData{ Code: 200, Message: "Success", - Results: map[string]interface{}{ + Results: map[string]any{ "qr_link": fmt.Sprintf("%s://%s/%s", c.Protocol(), c.Hostname(), response.ImagePath), "qr_duration": response.Duration, }, diff --git a/src/internal/rest/send_rest.go b/src/internal/rest/send_rest.go index bec37d1..29a7c1e 100644 --- a/src/internal/rest/send_rest.go +++ b/src/internal/rest/send_rest.go @@ -1,7 +1,6 @@ package rest import ( - "fmt" domainSend "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/send" "github.com/aldinokemal/go-whatsapp-web-multidevice/utils" "github.com/aldinokemal/go-whatsapp-web-multidevice/validations" @@ -33,12 +32,6 @@ func (controller *Send) SendText(c *fiber.Ctx) error { // add validation send message validations.ValidateSendMessage(request) - if request.Type == domainSend.TypeGroup { - request.Phone = request.Phone + "@g.us" - } else { - request.Phone = request.Phone + "@s.whatsapp.net" - } - response, err := controller.Service.SendText(c.UserContext(), request) utils.PanicIfNeeded(err) @@ -64,12 +57,6 @@ func (controller *Send) SendImage(c *fiber.Ctx) error { //add validation send image validations.ValidateSendImage(request) - if request.Type == domainSend.TypeGroup { - request.Phone = request.Phone + "@g.us" - } else { - request.Phone = request.Phone + "@s.whatsapp.net" - } - response, err := controller.Service.SendImage(c.UserContext(), request) utils.PanicIfNeeded(err) @@ -93,12 +80,6 @@ func (controller *Send) SendFile(c *fiber.Ctx) error { //add validation send image validations.ValidateSendFile(request) - if request.Type == domainSend.TypeGroup { - request.Phone = request.Phone + "@g.us" - } else { - request.Phone = request.Phone + "@s.whatsapp.net" - } - response, err := controller.Service.SendFile(c.UserContext(), request) utils.PanicIfNeeded(err) @@ -122,12 +103,6 @@ func (controller *Send) SendVideo(c *fiber.Ctx) error { //add validation send image validations.ValidateSendVideo(request) - if request.Type == domainSend.TypeGroup { - request.Phone = request.Phone + "@g.us" - } else { - request.Phone = request.Phone + "@s.whatsapp.net" - } - response, err := controller.Service.SendVideo(c.UserContext(), request) utils.PanicIfNeeded(err) @@ -146,12 +121,6 @@ func (controller *Send) SendContact(c *fiber.Ctx) error { // add validation send contect validations.ValidateSendContact(request) - if request.Type == domainSend.TypeGroup { - request.Phone = request.Phone + "@g.us" - } else { - request.Phone = request.Phone + "@s.whatsapp.net" - } - response, err := controller.Service.SendContact(c.UserContext(), request) utils.PanicIfNeeded(err) @@ -170,12 +139,6 @@ func (controller *Send) SendLink(c *fiber.Ctx) error { err = validations.ValidateSendLink(request) utils.PanicIfNeeded(err) - if request.Type == domainSend.TypeGroup { - request.Phone = request.Phone + "@g.us" - } else { - request.Phone = request.Phone + "@s.whatsapp.net" - } - response, err := controller.Service.SendLink(c.UserContext(), request) utils.PanicIfNeeded(err) @@ -194,7 +157,6 @@ func (controller *Send) RevokeMessage(c *fiber.Ctx) error { err = validations.ValidateRevokeMessage(request) utils.PanicIfNeeded(err) - fmt.Println(request) response, err := controller.Service.Revoke(c.UserContext(), request) utils.PanicIfNeeded(err) @@ -214,7 +176,6 @@ func (controller *Send) UpdateMessage(c *fiber.Ctx) error { err = validations.ValidateUpdateMessage(request) utils.PanicIfNeeded(err) - fmt.Println(request) response, err := controller.Service.UpdateMessage(c.UserContext(), request) utils.PanicIfNeeded(err) diff --git a/src/internal/rest/user_rest.go b/src/internal/rest/user_rest.go index 94a0472..dfa7700 100644 --- a/src/internal/rest/user_rest.go +++ b/src/internal/rest/user_rest.go @@ -35,8 +35,7 @@ func (controller *User) UserInfo(c *fiber.Ctx) error { // add validation send message validations.ValidateUserInfo(request) - - request.Phone = request.Phone + "@s.whatsapp.net" + response, err := controller.Service.Info(c.Context(), request) utils.PanicIfNeeded(err) @@ -55,7 +54,6 @@ func (controller *User) UserAvatar(c *fiber.Ctx) error { // add validation send message validations.ValidateUserAvatar(request) - request.Phone = request.Phone + "@s.whatsapp.net" response, err := controller.Service.Avatar(c.Context(), request) utils.PanicIfNeeded(err) diff --git a/src/internal/websocket/websocket.go b/src/internal/websocket/websocket.go index bf5098f..15f337c 100644 --- a/src/internal/websocket/websocket.go +++ b/src/internal/websocket/websocket.go @@ -1,7 +1,9 @@ package websocket import ( + "context" "encoding/json" + domainApp "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/app" "github.com/gofiber/fiber/v2" "github.com/gofiber/websocket/v2" "log" @@ -11,6 +13,7 @@ type client struct{} // Add more data to this type if needed type BroadcastMessage struct { Code string `json:"code"` Message string `json:"message"` + Result any `json:"result"` } var Clients = make(map[*websocket.Conn]client) // Note: although large maps with pointer-like types (e.g. strings) as keys are slow, using pointers themselves as keys is acceptable and fast @@ -61,7 +64,7 @@ func RunHub() { } } -func RegisterRoutes(app *fiber.App) { +func RegisterRoutes(app *fiber.App, service domainApp.IAppService) { app.Use("/ws", func(c *fiber.Ctx) error { if websocket.IsWebSocketUpgrade(c) { // Returns true if the client requested upgrade to the WebSocket protocol return c.Next() @@ -96,7 +99,15 @@ func RegisterRoutes(app *fiber.App) { log.Println("error unmarshal message:", err) return } - Broadcast <- messageData + if messageData.Code == "FETCH_DEVICES" { + devices, _ := service.FetchDevices(context.Background()) + Broadcast <- BroadcastMessage{ + Code: "LIST_DEVICES", + Message: "Device found", + Result: devices, + } + } + } else { log.Println("websocket message received of type", messageType) } diff --git a/src/services/app_service.go b/src/services/app_service.go index 4f8f09a..04fed66 100644 --- a/src/services/app_service.go +++ b/src/services/app_service.go @@ -119,7 +119,7 @@ func (service serviceApp) Reconnect(_ context.Context) (err error) { return service.WaCli.Connect() } -func (service serviceApp) FetchDevices(ctx context.Context) (response []domainApp.FetchDevicesResponse, err error) { +func (service serviceApp) FetchDevices(_ context.Context) (response []domainApp.FetchDevicesResponse, err error) { if service.WaCli == nil { return response, errors.New("wa cli nil cok") } diff --git a/src/utils/errors.go b/src/utils/errors.go index cec7f77..78c2840 100644 --- a/src/utils/errors.go +++ b/src/utils/errors.go @@ -2,7 +2,7 @@ package utils import "fmt" -func PanicIfNeeded(err interface{}, message ...string) { +func PanicIfNeeded(err any, message ...string) { if err != nil { if fmt.Sprintf("%s", err) == "record not found" && len(message) > 0 { panic(message[0]) diff --git a/src/utils/response.go b/src/utils/response.go index 02c155a..29a674f 100644 --- a/src/utils/response.go +++ b/src/utils/response.go @@ -1,7 +1,7 @@ package utils type ResponseData struct { - Code int `json:"code"` - Message string `json:"message"` - Results interface{} `json:"results"` + Code int `json:"code"` + Message string `json:"message"` + Results any `json:"results"` } diff --git a/src/utils/whatsapp.go b/src/utils/whatsapp.go index 4bba2ac..5a19498 100644 --- a/src/utils/whatsapp.go +++ b/src/utils/whatsapp.go @@ -140,6 +140,11 @@ func handler(rawEvt interface{}) { Code: "LOGIN_SUCCESS", Message: fmt.Sprintf("Successfully pair with %s", evt.ID.String()), } + case *events.LoggedOut: + websocket.Broadcast <- websocket.BroadcastMessage{ + Code: "LIST_DEVICES", + Result: nil, + } case *events.Connected, *events.PushNameSetting: if len(cli.Store.PushName) == 0 { return @@ -238,7 +243,7 @@ func handler(rawEvt interface{}) { func sendAutoReplyWebhook(evt *events.Message) error { client := &http.Client{Timeout: 10 * time.Second} - body := map[string]interface{}{ + body := map[string]any{ "from": evt.Info.SourceString(), "message": evt.Message.GetConversation(), "image": evt.Message.GetImageMessage(), diff --git a/src/validations/send_validation.go b/src/validations/send_validation.go index 02c4042..eb6cb6f 100644 --- a/src/validations/send_validation.go +++ b/src/validations/send_validation.go @@ -11,8 +11,7 @@ import ( func ValidateSendMessage(request domainSend.MessageRequest) { err := validation.ValidateStruct(&request, - validation.Field(&request.Phone, validation.Required, validation.Length(10, 25)), - validation.Field(&request.Message, validation.Required, validation.Length(1, 1000)), + validation.Field(&request.Message, validation.Required), ) if err != nil { @@ -24,8 +23,6 @@ func ValidateSendMessage(request domainSend.MessageRequest) { func ValidateSendImage(request domainSend.ImageRequest) { err := validation.ValidateStruct(&request, - validation.Field(&request.Phone, validation.Required, validation.Length(10, 25)), - validation.Field(&request.Caption, validation.When(true, validation.Length(1, 1000))), validation.Field(&request.Image, validation.Required), ) @@ -50,7 +47,6 @@ func ValidateSendImage(request domainSend.ImageRequest) { func ValidateSendFile(request domainSend.FileRequest) { err := validation.ValidateStruct(&request, - validation.Field(&request.Phone, validation.Required, validation.Length(10, 25)), validation.Field(&request.File, validation.Required), ) @@ -70,7 +66,6 @@ func ValidateSendFile(request domainSend.FileRequest) { func ValidateSendVideo(request domainSend.VideoRequest) { err := validation.ValidateStruct(&request, - validation.Field(&request.Phone, validation.Required, validation.Length(10, 25)), validation.Field(&request.Video, validation.Required), ) @@ -102,7 +97,6 @@ func ValidateSendVideo(request domainSend.VideoRequest) { func ValidateSendContact(request domainSend.ContactRequest) { err := validation.ValidateStruct(&request, - validation.Field(&request.Phone, validation.Required, validation.Length(10, 25)), validation.Field(&request.ContactName, validation.Required), validation.Field(&request.ContactPhone, validation.Required), ) @@ -116,7 +110,6 @@ func ValidateSendContact(request domainSend.ContactRequest) { func ValidateSendLink(request domainSend.LinkRequest) error { err := validation.ValidateStruct(&request, - validation.Field(&request.Phone, validation.Required, validation.Length(10, 25)), validation.Field(&request.Link, validation.Required), validation.Field(&request.Caption, validation.Required), ) @@ -132,8 +125,7 @@ func ValidateSendLink(request domainSend.LinkRequest) error { func ValidateRevokeMessage(request domainSend.RevokeRequest) error { err := validation.ValidateStruct(&request, - validation.Field(&request.Phone, validation.Required, validation.Length(10, 25)), - validation.Field(&request.MessageID, validation.Required, validation.Length(20, 25)), + validation.Field(&request.MessageID, validation.Required), ) if err != nil { @@ -147,9 +139,8 @@ func ValidateRevokeMessage(request domainSend.RevokeRequest) error { func ValidateUpdateMessage(request domainSend.UpdateMessageRequest) error { err := validation.ValidateStruct(&request, - validation.Field(&request.Phone, validation.Required, validation.Length(10, 25)), - validation.Field(&request.MessageID, validation.Required, validation.Length(20, 25)), - validation.Field(&request.Message, validation.Required, validation.Length(1, 1000)), + validation.Field(&request.MessageID, validation.Required), + validation.Field(&request.Message, validation.Required), ) if err != nil { diff --git a/src/validations/send_validation_test.go b/src/validations/send_validation_test.go index ef6da97..32bab2f 100644 --- a/src/validations/send_validation_test.go +++ b/src/validations/send_validation_test.go @@ -13,12 +13,12 @@ func TestValidateSendMessage(t *testing.T) { tests := []struct { name string args args - err interface{} + err any }{ { name: "success phone & message normal", args: args{request: domainSend.MessageRequest{ - Phone: "6289685024091", + Phone: "1728937129312@s.whatsapp.net", Message: "Hello this is testing", }}, err: nil, diff --git a/src/validations/user_validation.go b/src/validations/user_validation.go index 31d46b8..4060f56 100644 --- a/src/validations/user_validation.go +++ b/src/validations/user_validation.go @@ -4,12 +4,11 @@ import ( domainUser "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/user" "github.com/aldinokemal/go-whatsapp-web-multidevice/utils" validation "github.com/go-ozzo/ozzo-validation/v4" - "github.com/go-ozzo/ozzo-validation/v4/is" ) func ValidateUserInfo(request domainUser.InfoRequest) { err := validation.ValidateStruct(&request, - validation.Field(&request.Phone, validation.Required, is.E164, validation.Length(10, 15)), + validation.Field(&request.Phone, validation.Required), ) if err != nil { @@ -20,7 +19,7 @@ func ValidateUserInfo(request domainUser.InfoRequest) { } func ValidateUserAvatar(request domainUser.AvatarRequest) { err := validation.ValidateStruct(&request, - validation.Field(&request.Phone, validation.Required, is.E164, validation.Length(10, 15)), + validation.Field(&request.Phone, validation.Required), ) if err != nil { diff --git a/src/views/index.html b/src/views/index.html index 428e5fc..6689029 100644 --- a/src/views/index.html +++ b/src/views/index.html @@ -27,6 +27,15 @@

[[ app_name ]]

+
+
+ Device is connected +
+

+ Device ID: [[ connected_devices[0].device ]] +

+
+
App
@@ -60,22 +69,22 @@
- Send Private Message + Message
-
+
- Private + Send
Send Message
Send any message to any whatsapp number
-
+
- Private + Send
Send Image
Send image with @@ -84,9 +93,9 @@
-
+
- Private + Send
Send File
Send any file up to @@ -94,9 +103,9 @@
-
+
- Private + Send
Send Video
Send video @@ -106,99 +115,50 @@
-
+
- Private + Send
Send Contact
Send contact to any whatsapp number
-
- -
- Send Group Message -
- -
-
+
- Group -
Send Message
+ Revoke +
Revoke Message
- Send any message to any whatsapp number -
-
-
-
-
- Group -
Send Image
-
- Send image with -
jpg/jpeg/png
- type -
-
-
-
-
- Group -
Send File
-
- Send any file up to -
{{ .MaxFileSize }}
-
-
-
-
-
- Group -
Send Video
-
- Send video -
mp4
- up to -
{{ .MaxVideoSize }}
-
-
-
-
-
- Group -
Send Contact
-
- Send contact to any whatsapp number + Revoke any message in private or group chat
- User + Account
-
+
-
User Info
+
Avatar
- You can search someone user info by phone + You can search someone avatar by phone
-
+
-
User Avatar
+
User Info
- You can search someone avatar by phone + You can search someone user info by phone
-
User List Groups
+
My List Groups
Display all groups you joined
@@ -206,7 +166,7 @@
-
User Privacy Setting
+
My Privacy Setting
Get your privacy settings
@@ -249,10 +209,18 @@
+
+ + +
+
@@ -262,7 +230,8 @@
-
+
Send
@@ -277,10 +246,18 @@
+
+ + +
+
@@ -313,7 +290,8 @@
-
+
Send
@@ -328,10 +306,18 @@
+
+ + +
+
@@ -349,14 +335,15 @@
-
+
Send
- +