Browse Source

update openapi / swagger docs and change route name for pairing function

pull/61/head v1.6.0
Dimas Restu H 2 years ago
parent
commit
0f95f0e678
  1. 64
      docs/docs.go
  2. 59
      docs/swagger.json
  3. 49
      docs/swagger.yaml
  4. 4
      internal/route.go
  5. 68
      internal/whatsapp/whatsapp.go
  6. 2
      pkg/whatsapp/whatsapp.go

64
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 package docs
import "github.com/swaggo/swag" import "github.com/swaggo/swag"
@ -32,7 +31,7 @@ const docTemplate = `{
"summary": "Show The Status of The Server", "summary": "Show The Status of The Server",
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -54,7 +53,7 @@ const docTemplate = `{
"summary": "Generate Authentication Token", "summary": "Generate Authentication Token",
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -71,12 +70,12 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"WhatsApp Group"
"WhatsApp Information"
], ],
"summary": "Get Joined Groups Information", "summary": "Get Joined Groups Information",
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -115,7 +114,32 @@ const docTemplate = `{
], ],
"responses": { "responses": {
"200": { "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", "summary": "Logout Device from WhatsApp Multi-Device",
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -154,7 +178,7 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"WhatsApp Authentication"
"WhatsApp Information"
], ],
"summary": "Check If WhatsApp Personal ID is Registered", "summary": "Check If WhatsApp Personal ID is Registered",
"parameters": [ "parameters": [
@ -168,7 +192,7 @@ const docTemplate = `{
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -209,7 +233,7 @@ const docTemplate = `{
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -257,7 +281,7 @@ const docTemplate = `{
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -298,7 +322,7 @@ const docTemplate = `{
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -353,7 +377,7 @@ const docTemplate = `{
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -400,7 +424,7 @@ const docTemplate = `{
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -448,7 +472,7 @@ const docTemplate = `{
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -489,7 +513,7 @@ const docTemplate = `{
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -530,7 +554,7 @@ const docTemplate = `{
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -585,7 +609,7 @@ const docTemplate = `{
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -613,6 +637,8 @@ var SwaggerInfo = &swag.Spec{
Description: "This is WhatsApp Multi-Device Implementation in Go REST API", Description: "This is WhatsApp Multi-Device Implementation in Go REST API",
InfoInstanceName: "swagger", InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate, SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
} }
func init() { func init() {

59
docs/swagger.json

@ -27,7 +27,7 @@
"summary": "Show The Status of The Server", "summary": "Show The Status of The Server",
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -49,7 +49,7 @@
"summary": "Generate Authentication Token", "summary": "Generate Authentication Token",
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -66,12 +66,12 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"WhatsApp Group"
"WhatsApp Information"
], ],
"summary": "Get Joined Groups Information", "summary": "Get Joined Groups Information",
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -110,7 +110,32 @@
], ],
"responses": { "responses": {
"200": { "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", "summary": "Logout Device from WhatsApp Multi-Device",
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -149,7 +174,7 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"WhatsApp Authentication"
"WhatsApp Information"
], ],
"summary": "Check If WhatsApp Personal ID is Registered", "summary": "Check If WhatsApp Personal ID is Registered",
"parameters": [ "parameters": [
@ -163,7 +188,7 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -204,7 +229,7 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -252,7 +277,7 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -293,7 +318,7 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -348,7 +373,7 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -395,7 +420,7 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -443,7 +468,7 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -484,7 +509,7 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -525,7 +550,7 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }
@ -580,7 +605,7 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": ""
"description": "OK"
} }
} }
} }

49
docs/swagger.yaml

@ -15,7 +15,7 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: ""
description: OK
summary: Show The Status of The Server summary: Show The Status of The Server
tags: tags:
- Root - Root
@ -26,7 +26,7 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: ""
description: OK
security: security:
- BasicAuth: [] - BasicAuth: []
summary: Generate Authentication Token summary: Generate Authentication Token
@ -39,12 +39,12 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: ""
description: OK
security: security:
- BearerAuth: [] - BearerAuth: []
summary: Get Joined Groups Information summary: Get Joined Groups Information
tags: tags:
- WhatsApp Group
- WhatsApp Information
/api/v1/whatsapp/login: /api/v1/whatsapp/login:
post: post:
consumes: consumes:
@ -64,12 +64,27 @@ paths:
- text/html - text/html
responses: responses:
"200": "200":
description: ""
description: OK
security: security:
- BearerAuth: [] - BearerAuth: []
summary: Generate QR Code for WhatsApp Multi-Device Login summary: Generate QR Code for WhatsApp Multi-Device Login
tags: tags:
- WhatsApp Authentication - 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: /api/v1/whatsapp/logout:
post: post:
description: Make Device Logout from WhatsApp Multi-Device description: Make Device Logout from WhatsApp Multi-Device
@ -77,7 +92,7 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: ""
description: OK
security: security:
- BearerAuth: [] - BearerAuth: []
summary: Logout Device from WhatsApp Multi-Device summary: Logout Device from WhatsApp Multi-Device
@ -96,12 +111,12 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: ""
description: OK
security: security:
- BearerAuth: [] - BearerAuth: []
summary: Check If WhatsApp Personal ID is Registered summary: Check If WhatsApp Personal ID is Registered
tags: tags:
- WhatsApp Authentication
- WhatsApp Information
/api/v1/whatsapp/send/audio: /api/v1/whatsapp/send/audio:
post: post:
consumes: consumes:
@ -122,7 +137,7 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: ""
description: OK
security: security:
- BearerAuth: [] - BearerAuth: []
summary: Send Audio Message summary: Send Audio Message
@ -154,7 +169,7 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: ""
description: OK
security: security:
- BearerAuth: [] - BearerAuth: []
summary: Send Contact Message summary: Send Contact Message
@ -181,7 +196,7 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: ""
description: OK
security: security:
- BearerAuth: [] - BearerAuth: []
summary: Send Document Message summary: Send Document Message
@ -217,7 +232,7 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: ""
description: OK
security: security:
- BearerAuth: [] - BearerAuth: []
summary: Send Image Message summary: Send Image Message
@ -247,7 +262,7 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: ""
description: OK
security: security:
- BearerAuth: [] - BearerAuth: []
summary: Send Link Message summary: Send Link Message
@ -279,7 +294,7 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: ""
description: OK
security: security:
- BearerAuth: [] - BearerAuth: []
summary: Send Location Message summary: Send Location Message
@ -306,7 +321,7 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: ""
description: OK
security: security:
- BearerAuth: [] - BearerAuth: []
summary: Send Sticker Message summary: Send Sticker Message
@ -332,7 +347,7 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: ""
description: OK
security: security:
- BearerAuth: [] - BearerAuth: []
summary: Send Text Message summary: Send Text Message
@ -368,7 +383,7 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: ""
description: OK
security: security:
- BearerAuth: [] - BearerAuth: []
summary: Send Video Message summary: Send Video Message

4
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+"/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.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.GET(router.BaseURL+"/group", ctlWhatsApp.GetGroup, middleware.JWTWithConfig(authJWTConfig))
e.POST(router.BaseURL+"/send/text", ctlWhatsApp.SendText, middleware.JWTWithConfig(authJWTConfig)) e.POST(router.BaseURL+"/send/text", ctlWhatsApp.SendText, middleware.JWTWithConfig(authJWTConfig))

68
internal/whatsapp/whatsapp.go

@ -102,15 +102,15 @@ func Login(c echo.Context) error {
} }
// PairPhone // 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 // @Tags WhatsApp Authentication
// @Accept multipart/form-data // @Accept multipart/form-data
// @Produce json // @Produce json
// @Success 200 // @Success 200
// @Security BearerAuth // @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 var err error
jid := jwtPayload(c).JID jid := jwtPayload(c).JID
@ -118,7 +118,7 @@ func PairPhone(c echo.Context) error {
pkgWhatsApp.WhatsAppInitClient(nil, jid) pkgWhatsApp.WhatsAppInitClient(nil, jid)
// Get WhatsApp pairing Code text // Get WhatsApp pairing Code text
pairCode, pairCodeTimeout, err := pkgWhatsApp.WhatsAppPairPhone(jid)
pairCode, pairCodeTimeout, err := pkgWhatsApp.WhatsAppLoginPair(jid)
if err != nil { if err != nil {
return router.ResponseInternalError(c, err.Error()) 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) 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 // Registered
// @Summary Check If WhatsApp Personal ID is Registered // @Summary Check If WhatsApp Personal ID is Registered
// @Description Check WhatsApp Personal ID is Registered // @Description Check WhatsApp Personal ID is Registered
// @Tags WhatsApp Authentication
// @Tags WhatsApp Information
// @Produce json // @Produce json
// @Param msisdn query string true "WhatsApp Personal ID to Check" // @Param msisdn query string true "WhatsApp Personal ID to Check"
// @Success 200 // @Success 200
@ -161,24 +181,24 @@ func Registered(c echo.Context) error {
return router.ResponseSuccess(c, "WhatsApp Personal ID is Registered") 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 // @Produce json
// @Success 200 // @Success 200
// @Security BearerAuth // @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 var err error
jid := jwtPayload(c).JID jid := jwtPayload(c).JID
err = pkgWhatsApp.WhatsAppLogout(jid)
group, err := pkgWhatsApp.WhatsAppGetGroup(jid)
if err != nil { if err != nil {
return router.ResponseInternalError(c, err.Error()) return router.ResponseInternalError(c, err.Error())
} }
return router.ResponseSuccess(c, "Successfully Logged Out")
return router.ResponseSuccessWithData(c, "Successfully List Joined Groups", group)
} }
// SendText // SendText
@ -520,23 +540,3 @@ func sendMedia(c echo.Context, mediaType string) error {
return router.ResponseSuccessWithData(c, "Successfully Send Media Message", resSendMessage) 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)
}

2
pkg/whatsapp/whatsapp.go

@ -239,7 +239,7 @@ func WhatsAppLogin(jid string) (string, int, error) {
return "", 0, errors.New("WhatsApp Client is not Valid") 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 { if WhatsAppClient[jid] != nil {
// Make Sure WebSocket Connection is Disconnected // Make Sure WebSocket Connection is Disconnected
WhatsAppClient[jid].Disconnect() WhatsAppClient[jid].Disconnect()

Loading…
Cancel
Save