diff --git a/docs/docs.go b/docs/docs.go index a228f38..816e6d0 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,5 +1,4 @@ -// Package docs GENERATED BY SWAG; DO NOT EDIT -// This file was generated by swaggo/swag +// Package docs Code generated by swaggo/swag. DO NOT EDIT package docs import "github.com/swaggo/swag" @@ -32,7 +31,7 @@ const docTemplate = `{ "summary": "Show The Status of The Server", "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -54,7 +53,7 @@ const docTemplate = `{ "summary": "Generate Authentication Token", "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -71,12 +70,12 @@ const docTemplate = `{ "application/json" ], "tags": [ - "WhatsApp Group" + "WhatsApp Information" ], "summary": "Get Joined Groups Information", "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -115,7 +114,32 @@ const docTemplate = `{ ], "responses": { "200": { - "description": "" + "description": "OK" + } + } + } + }, + "/api/v1/whatsapp/login/pair": { + "post": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Get Pairing Code for WhatsApp Multi-Device Login", + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "WhatsApp Authentication" + ], + "summary": "Pair Phone for WhatsApp Multi-Device Login", + "responses": { + "200": { + "description": "OK" } } } @@ -137,7 +161,7 @@ const docTemplate = `{ "summary": "Logout Device from WhatsApp Multi-Device", "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -154,7 +178,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "WhatsApp Authentication" + "WhatsApp Information" ], "summary": "Check If WhatsApp Personal ID is Registered", "parameters": [ @@ -168,7 +192,7 @@ const docTemplate = `{ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -209,7 +233,7 @@ const docTemplate = `{ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -257,7 +281,7 @@ const docTemplate = `{ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -298,7 +322,7 @@ const docTemplate = `{ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -353,7 +377,7 @@ const docTemplate = `{ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -400,7 +424,7 @@ const docTemplate = `{ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -448,7 +472,7 @@ const docTemplate = `{ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -489,7 +513,7 @@ const docTemplate = `{ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -530,7 +554,7 @@ const docTemplate = `{ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -585,7 +609,7 @@ const docTemplate = `{ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -613,6 +637,8 @@ var SwaggerInfo = &swag.Spec{ Description: "This is WhatsApp Multi-Device Implementation in Go REST API", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", } func init() { diff --git a/docs/swagger.json b/docs/swagger.json index e299633..1d633fd 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -27,7 +27,7 @@ "summary": "Show The Status of The Server", "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -49,7 +49,7 @@ "summary": "Generate Authentication Token", "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -66,12 +66,12 @@ "application/json" ], "tags": [ - "WhatsApp Group" + "WhatsApp Information" ], "summary": "Get Joined Groups Information", "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -110,7 +110,32 @@ ], "responses": { "200": { - "description": "" + "description": "OK" + } + } + } + }, + "/api/v1/whatsapp/login/pair": { + "post": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "Get Pairing Code for WhatsApp Multi-Device Login", + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "WhatsApp Authentication" + ], + "summary": "Pair Phone for WhatsApp Multi-Device Login", + "responses": { + "200": { + "description": "OK" } } } @@ -132,7 +157,7 @@ "summary": "Logout Device from WhatsApp Multi-Device", "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -149,7 +174,7 @@ "application/json" ], "tags": [ - "WhatsApp Authentication" + "WhatsApp Information" ], "summary": "Check If WhatsApp Personal ID is Registered", "parameters": [ @@ -163,7 +188,7 @@ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -204,7 +229,7 @@ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -252,7 +277,7 @@ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -293,7 +318,7 @@ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -348,7 +373,7 @@ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -395,7 +420,7 @@ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -443,7 +468,7 @@ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -484,7 +509,7 @@ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -525,7 +550,7 @@ ], "responses": { "200": { - "description": "" + "description": "OK" } } } @@ -580,7 +605,7 @@ ], "responses": { "200": { - "description": "" + "description": "OK" } } } diff --git a/docs/swagger.yaml b/docs/swagger.yaml index f795184..d7ccbda 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -15,7 +15,7 @@ paths: - application/json responses: "200": - description: "" + description: OK summary: Show The Status of The Server tags: - Root @@ -26,7 +26,7 @@ paths: - application/json responses: "200": - description: "" + description: OK security: - BasicAuth: [] summary: Generate Authentication Token @@ -39,12 +39,12 @@ paths: - application/json responses: "200": - description: "" + description: OK security: - BearerAuth: [] summary: Get Joined Groups Information tags: - - WhatsApp Group + - WhatsApp Information /api/v1/whatsapp/login: post: consumes: @@ -64,12 +64,27 @@ paths: - text/html responses: "200": - description: "" + description: OK security: - BearerAuth: [] summary: Generate QR Code for WhatsApp Multi-Device Login tags: - WhatsApp Authentication + /api/v1/whatsapp/login/pair: + post: + consumes: + - multipart/form-data + description: Get Pairing Code for WhatsApp Multi-Device Login + produces: + - application/json + responses: + "200": + description: OK + security: + - BearerAuth: [] + summary: Pair Phone for WhatsApp Multi-Device Login + tags: + - WhatsApp Authentication /api/v1/whatsapp/logout: post: description: Make Device Logout from WhatsApp Multi-Device @@ -77,7 +92,7 @@ paths: - application/json responses: "200": - description: "" + description: OK security: - BearerAuth: [] summary: Logout Device from WhatsApp Multi-Device @@ -96,12 +111,12 @@ paths: - application/json responses: "200": - description: "" + description: OK security: - BearerAuth: [] summary: Check If WhatsApp Personal ID is Registered tags: - - WhatsApp Authentication + - WhatsApp Information /api/v1/whatsapp/send/audio: post: consumes: @@ -122,7 +137,7 @@ paths: - application/json responses: "200": - description: "" + description: OK security: - BearerAuth: [] summary: Send Audio Message @@ -154,7 +169,7 @@ paths: - application/json responses: "200": - description: "" + description: OK security: - BearerAuth: [] summary: Send Contact Message @@ -181,7 +196,7 @@ paths: - application/json responses: "200": - description: "" + description: OK security: - BearerAuth: [] summary: Send Document Message @@ -217,7 +232,7 @@ paths: - application/json responses: "200": - description: "" + description: OK security: - BearerAuth: [] summary: Send Image Message @@ -247,7 +262,7 @@ paths: - application/json responses: "200": - description: "" + description: OK security: - BearerAuth: [] summary: Send Link Message @@ -279,7 +294,7 @@ paths: - application/json responses: "200": - description: "" + description: OK security: - BearerAuth: [] summary: Send Location Message @@ -306,7 +321,7 @@ paths: - application/json responses: "200": - description: "" + description: OK security: - BearerAuth: [] summary: Send Sticker Message @@ -332,7 +347,7 @@ paths: - application/json responses: "200": - description: "" + description: OK security: - BearerAuth: [] summary: Send Text Message @@ -368,7 +383,7 @@ paths: - application/json responses: "200": - description: "" + description: OK security: - BearerAuth: [] summary: Send Video Message diff --git a/internal/route.go b/internal/route.go index 8be73ca..4ac9aaf 100644 --- a/internal/route.go +++ b/internal/route.go @@ -36,10 +36,10 @@ func Routes(e *echo.Echo) { } e.POST(router.BaseURL+"/login", ctlWhatsApp.Login, middleware.JWTWithConfig(authJWTConfig)) - e.POST(router.BaseURL+"/pair", ctlWhatsApp.PairPhone, middleware.JWTWithConfig(authJWTConfig)) - e.GET(router.BaseURL+"/registered", ctlWhatsApp.Registered, middleware.JWTWithConfig(authJWTConfig)) + e.POST(router.BaseURL+"/login/pair", ctlWhatsApp.LoginPair, middleware.JWTWithConfig(authJWTConfig)) e.POST(router.BaseURL+"/logout", ctlWhatsApp.Logout, middleware.JWTWithConfig(authJWTConfig)) + e.GET(router.BaseURL+"/registered", ctlWhatsApp.Registered, middleware.JWTWithConfig(authJWTConfig)) e.GET(router.BaseURL+"/group", ctlWhatsApp.GetGroup, middleware.JWTWithConfig(authJWTConfig)) e.POST(router.BaseURL+"/send/text", ctlWhatsApp.SendText, middleware.JWTWithConfig(authJWTConfig)) diff --git a/internal/whatsapp/whatsapp.go b/internal/whatsapp/whatsapp.go index 623c09a..f272b4e 100644 --- a/internal/whatsapp/whatsapp.go +++ b/internal/whatsapp/whatsapp.go @@ -102,15 +102,15 @@ func Login(c echo.Context) error { } // PairPhone -// @Summary Pair phone for WhatsApp Multi-Device Login -// @Description Get pairing Code for WhatsApp Multi-Device Login +// @Summary Pair Phone for WhatsApp Multi-Device Login +// @Description Get Pairing Code for WhatsApp Multi-Device Login // @Tags WhatsApp Authentication // @Accept multipart/form-data // @Produce json // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/pair [post] -func PairPhone(c echo.Context) error { +// @Router /api/v1/whatsapp/login/pair [post] +func LoginPair(c echo.Context) error { var err error jid := jwtPayload(c).JID @@ -118,7 +118,7 @@ func PairPhone(c echo.Context) error { pkgWhatsApp.WhatsAppInitClient(nil, jid) // Get WhatsApp pairing Code text - pairCode, pairCodeTimeout, err := pkgWhatsApp.WhatsAppPairPhone(jid) + pairCode, pairCodeTimeout, err := pkgWhatsApp.WhatsAppLoginPair(jid) if err != nil { return router.ResponseInternalError(c, err.Error()) } @@ -136,10 +136,30 @@ func PairPhone(c echo.Context) error { return router.ResponseSuccessWithData(c, "Successfully Generated Pairing Code", resPairing) } +// Logout +// @Summary Logout Device from WhatsApp Multi-Device +// @Description Make Device Logout from WhatsApp Multi-Device +// @Tags WhatsApp Authentication +// @Produce json +// @Success 200 +// @Security BearerAuth +// @Router /api/v1/whatsapp/logout [post] +func Logout(c echo.Context) error { + var err error + jid := jwtPayload(c).JID + + err = pkgWhatsApp.WhatsAppLogout(jid) + if err != nil { + return router.ResponseInternalError(c, err.Error()) + } + + return router.ResponseSuccess(c, "Successfully Logged Out") +} + // Registered // @Summary Check If WhatsApp Personal ID is Registered // @Description Check WhatsApp Personal ID is Registered -// @Tags WhatsApp Authentication +// @Tags WhatsApp Information // @Produce json // @Param msisdn query string true "WhatsApp Personal ID to Check" // @Success 200 @@ -161,24 +181,24 @@ func Registered(c echo.Context) error { return router.ResponseSuccess(c, "WhatsApp Personal ID is Registered") } -// Logout -// @Summary Logout Device from WhatsApp Multi-Device -// @Description Make Device Logout from WhatsApp Multi-Device -// @Tags WhatsApp Authentication +// GetGroup +// @Summary Get Joined Groups Information +// @Description Get Joined Groups Information from WhatsApp +// @Tags WhatsApp Information // @Produce json // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/logout [post] -func Logout(c echo.Context) error { +// @Router /api/v1/whatsapp/group [get] +func GetGroup(c echo.Context) error { var err error jid := jwtPayload(c).JID - err = pkgWhatsApp.WhatsAppLogout(jid) + group, err := pkgWhatsApp.WhatsAppGetGroup(jid) if err != nil { return router.ResponseInternalError(c, err.Error()) } - return router.ResponseSuccess(c, "Successfully Logged Out") + return router.ResponseSuccessWithData(c, "Successfully List Joined Groups", group) } // SendText @@ -520,23 +540,3 @@ func sendMedia(c echo.Context, mediaType string) error { return router.ResponseSuccessWithData(c, "Successfully Send Media Message", resSendMessage) } - -// GetGroup -// @Summary Get Joined Groups Information -// @Description Get Joined Groups Information from WhatsApp -// @Tags WhatsApp Group -// @Produce json -// @Success 200 -// @Security BearerAuth -// @Router /api/v1/whatsapp/group [get] -func GetGroup(c echo.Context) error { - var err error - jid := jwtPayload(c).JID - - group, err := pkgWhatsApp.WhatsAppGetGroup(jid) - if err != nil { - return router.ResponseInternalError(c, err.Error()) - } - - return router.ResponseSuccessWithData(c, "Successfully List Joined Groups", group) -} diff --git a/pkg/whatsapp/whatsapp.go b/pkg/whatsapp/whatsapp.go index 8f236ec..7dbe796 100644 --- a/pkg/whatsapp/whatsapp.go +++ b/pkg/whatsapp/whatsapp.go @@ -239,7 +239,7 @@ func WhatsAppLogin(jid string) (string, int, error) { return "", 0, errors.New("WhatsApp Client is not Valid") } -func WhatsAppPairPhone(jid string) (string, int, error) { +func WhatsAppLoginPair(jid string) (string, int, error) { if WhatsAppClient[jid] != nil { // Make Sure WebSocket Connection is Disconnected WhatsAppClient[jid].Disconnect()