GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.
Go botgogolanggolang-whatsappgolang-whatsapp-apirestrest-apiwhatsappwhatsapp-apiwhatsapp-api-gowhatsapp-multi-devicewhatsapp-web-multi-device
feat: add api for update message (#32)
Aldino Kemaldfd8e5a642c0
diff --git a/docs/openapi.yaml b/docs/openapi.yamlindex f0e380f9..31c47938 100644--- a/docs/openapi.yaml+++ b/docs/openapi.yaml@@ -1,7 +1,7 @@openapi: 3.0.0info:title: WhatsApp API MultiDevice- version: 2.4.0+ version: 2.5.0description: This API is used for sending whatsapp via APIservers:- url: http://localhost:3000@@ -46,6 +46,12 @@ paths:qr_duration: 30qr_link: >-http://localhost:3000/statics/images/qrcode/scan-qr-b0b7bb43-9a22-455a-814f-5a225c743310.png+ '500':+ description: Internal Server Error+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/ErrorInternalServer'/app/logout:get:operationId: authLogout@@ -78,24 +84,10 @@ paths:results: null'500':description: Internal Server Error- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 02:39:02 GMT- Content-Type:- schema:- type: string- example: text/plain; charset=utf-8- Content-Length:- schema:- type: integer- example: '38'content:- text/plain:+ application/json:schema:- type: string- example: the store doesn't contain a device JID+ $ref: '#/components/schemas/ErrorInternalServer'/app/reconnect:get:operationId: authReconnect@@ -105,27 +97,16 @@ paths:responses:'200':description: OK- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 02:38:10 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:+ content:+ application/json:schema:- type: integer- example: '57'+ $ref: '#/components/schemas/SendResponse'+ '500':+ description: Internal Server Errorcontent:application/json:schema:- type: object- example:- code: 200- message: Reconnect success- results: null+ $ref: '#/components/schemas/ErrorInternalServer'/user/info:get:operationId: userInfo@@ -191,58 +172,16 @@ paths:AD: true'400':description: Bad Request- headers:- Date:- schema:- type: string- example: Sun, 13 Feb 2022 05:04:20 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '63'- Vary:- schema:- type: string- example: Origin- Access-Control-Allow-Origin:- schema:- type: string- example: '*'content:application/json:schema:- type: object- example:- code: 400- message: 'phone: cannot be blank.'- results: null+ $ref: '#/components/schemas/ErrorBadRequest''500':description: Internal Server Error- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:03:21 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '58'content:application/json:schema:- type: object- example:- code: 500- message: you are not loggin- results: null+ $ref: '#/components/schemas/ErrorInternalServer'/user/avatar:get:operationId: userAvatar@@ -283,29 +222,18 @@ paths:https://pps.whatsapp.net/v/t61.24694-24/181358562_385581386633509_6230178822944778044_n.jpg?ccb=11-4&oh=df36c5b990497b8a5758a0f1ad8118a8&oe=620AA726id: '1635239861'type: image+ '400':+ description: Bad Request+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/ErrorBadRequest''500':description: Internal Server Error- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:03:29 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '58'content:application/json:schema:- type: object- example:- code: 500- message: you are not loggin- results: null+ $ref: '#/components/schemas/ErrorInternalServer'/user/my/privacy:get:operationId: userMyPrivacy@@ -351,27 +279,10 @@ paths:read_receipts: all'500':description: Internal Server Error- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:03:29 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '58'content:application/json:schema:- type: object- example:- code: 500- message: you are not loggin- results: null+ $ref: '#/components/schemas/ErrorInternalServer'/user/my/groups:get:operationId: userMyGroups@@ -381,27 +292,10 @@ paths:responses:'500':description: Internal Server Error- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:03:29 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '58'content:application/json:schema:- type: object- example:- code: 500- message: you are not loggin- results: null+ $ref: '#/components/schemas/ErrorInternalServer'/send/message:post:operationId: sendMessage@@ -427,76 +321,22 @@ paths:responses:'200':description: OK- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:43:28 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '118'content:application/json:schema:- type: object- example:- code: 200- message: Success- results:- status: >-- Message sent (server timestamp: 2022-02-11 10:43:29 +0700- WIB)+ $ref: '#/components/schemas/SendResponse''400':description: Bad Request- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:02:58 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '70'content:application/json:schema:- type: object- example:- code: 400- message: 'phone: cannot be blank.'- results: null+ $ref: '#/components/schemas/ErrorBadRequest''500':description: Internal Server Error- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:02:22 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '58'content:application/json:schema:- type: object- example:- code: 500- message: you are not loggin- results: null+ $ref: '#/components/schemas/ErrorInternalServer'/send/image:post:operationId: sendImage@@ -531,76 +371,22 @@ paths:responses:'200':description: OK- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:26:22 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '124'content:application/json:schema:- type: object- example:- code: 200- message: Success- results:- status: >-- Image message sent (server timestamp: 2022-02-11 10:26:22- +0700 WIB)+ $ref: '#/components/schemas/SendResponse''400':description: Bad Request- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:02:17 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '70'content:application/json:schema:- type: object- example:- code: 400- message: 'phone: cannot be blank.'- results: null+ $ref: '#/components/schemas/ErrorBadRequest''500':description: Internal Server Error- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:02:48 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '58'content:application/json:schema:- type: object- example:- code: 500- message: you are not loggin- results: null+ $ref: '#/components/schemas/ErrorInternalServer'/send/file:post:operationId: sendFile@@ -629,76 +415,22 @@ paths:responses:'200':description: OK- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:42:57 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '123'content:application/json:schema:- type: object- example:- code: 200- message: Success- results:- status: >-- File message sent (server timestamp: 2022-02-11 10:42:57- +0700 WIB)+ $ref: '#/components/schemas/SendResponse''400':description: Bad Request- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:02:17 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '70'content:application/json:schema:- type: object- example:- code: 400- message: 'phone: cannot be blank.'- results: null+ $ref: '#/components/schemas/ErrorBadRequest''500':description: Internal Server Error- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:02:48 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '58'content:application/json:schema:- type: object- example:- code: 500- message: you are not loggin- results: null+ $ref: '#/components/schemas/ErrorInternalServer'/send/video:post:operationId: sendVideo@@ -733,75 +465,22 @@ paths:responses:'200':description: OK- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:42:57 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '123'content:application/json:schema:- type: object- example:- code: 200- message: Success- results:- status: >-- Video sent to [email protected] (server timestamp: 2022-05-17 14:39:29 +0700 WIB)+ $ref: '#/components/schemas/SendResponse''400':description: Bad Request- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:02:17 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '70'content:application/json:schema:- type: object- example:- code: 400- message: 'phone: cannot be blank.'- results: null+ $ref: '#/components/schemas/ErrorBadRequest''500':description: Internal Server Error- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:02:48 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '58'content:application/json:schema:- type: object- example:- code: 500- message: you are not loggin- results: null+ $ref: '#/components/schemas/ErrorInternalServer'/send/contact:post:operationId: sendContact@@ -830,75 +509,22 @@ paths:responses:'200':description: OK- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:42:57 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '123'content:application/json:schema:- type: object- example:- code: 200- message: Success- results:- status: >-- Contact sent to [email protected] (server timestamp: 2022-05-17 14:39:29 +0700 WIB)+ $ref: '#/components/schemas/SendResponse''400':description: Bad Request- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:02:17 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '70'content:application/json:schema:- type: object- example:- code: 400- message: 'phone: cannot be blank.'- results: null+ $ref: '#/components/schemas/ErrorBadRequest''500':description: Internal Server Error- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:02:48 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '58'content:application/json:schema:- type: object- example:- code: 500- message: you are not loggin- results: null+ $ref: '#/components/schemas/ErrorInternalServer'/send/link:post:operationId: sendLink@@ -927,73 +553,68 @@ paths:responses:'200':description: OK- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:42:57 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '123'content:application/json:schema:- type: object- example:- code: 200- message: Success- results:- status: >-- Link sent to [email protected] (server timestamp: 2022-05-17 14:39:29 +0700 WIB)+ $ref: '#/components/schemas/SendResponse''400':description: Bad Request- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:02:17 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '70'content:application/json:schema:- type: object- example:- code: 400- message: 'phone: cannot be blank.'- results: null+ $ref: '#/components/schemas/ErrorBadRequest''500':description: Internal Server Error- headers:- Date:- schema:- type: string- example: Fri, 11 Feb 2022 03:02:48 GMT- Content-Type:- schema:- type: string- example: application/json- Content-Length:- schema:- type: integer- example: '58'content:application/json:schema:- type: object- example:- code: 500- message: you are not loggin- results: null+ $ref: '#/components/schemas/ErrorInternalServer'+components:+ schemas:+ SendResponse:+ type: object+ properties:+ code:+ type: integer+ example: 200+ message:+ type: string+ example: Success+ results:+ type: object+ properties:+ message_id:+ type: string+ example: '3EB0B430B6F8F1D0E053AC120E0A9E5C'+ status:+ type: string+ example: '<feature> success ....'+ ErrorInternalServer:+ properties:+ code:+ type: integer+ example: 500+ description: 'HTTP Status Code'+ message:+ type: string+ example: you are not loggin+ description: 'Detail error message'+ results:+ type: object+ example: null+ description: 'additional data'+ ErrorBadRequest:+ properties:+ code:+ type: integer+ example: 400+ description: 'HTTP Status Code'+ message:+ type: string+ example: phone cannot be blank+ description: 'Detail error message'+ results:+ type: object+ example: null+ description: 'additional data'\ No newline at end of filediff --git a/src/config/settings.go b/src/config/settings.goindex 4589fed4..e7d22095 100644--- a/src/config/settings.go+++ b/src/config/settings.go@@ -6,7 +6,7 @@ import ()var (- AppVersion = "v3.10.0"+ AppVersion = "v3.11.0"AppPort = "3000"AppDebug = falseAppOs = fmt.Sprintf("AldinoKemal")diff --git a/src/domains/send/message.go b/src/domains/send/message.goindex 7844dc1e..deadd40f 100644--- a/src/domains/send/message.go+++ b/src/domains/send/message.go@@ -10,3 +10,15 @@ type RevokeResponse struct {MessageID string `json:"message_id"`Status string `json:"status"`}++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 {+ MessageID string `json:"message_id"`+ Status string `json:"status"`+}diff --git a/src/domains/send/send.go b/src/domains/send/send.goindex eb478696..0a282a5c 100644--- a/src/domains/send/send.go+++ b/src/domains/send/send.go@@ -17,4 +17,5 @@ type ISendService interface {SendContact(ctx context.Context, request ContactRequest) (response ContactResponse, err error)SendLink(ctx context.Context, request LinkRequest) (response LinkResponse, err error)Revoke(ctx context.Context, request RevokeRequest) (response RevokeResponse, err error)+ UpdateMessage(ctx context.Context, request UpdateMessageRequest) (response UpdateMessageResponse, err error)}diff --git a/src/internal/rest/send_controller.go b/src/internal/rest/send_controller.goindex 42ce429d..bec37d10 100644--- a/src/internal/rest/send_controller.go+++ b/src/internal/rest/send_controller.go@@ -21,6 +21,7 @@ func InitRestSend(app *fiber.App, service domainSend.ISendService) Send {app.Post("/send/contact", rest.SendContact)app.Post("/send/link", rest.SendLink)app.Post("/message/:message_id/revoke", rest.RevokeMessage)+ app.Post("/message/:message_id/update", rest.UpdateMessage)return rest}@@ -204,3 +205,23 @@ func (controller *Send) RevokeMessage(c *fiber.Ctx) error {Results: response,})}++func (controller *Send) UpdateMessage(c *fiber.Ctx) error {+ var request domainSend.UpdateMessageRequest+ err := c.BodyParser(&request)+ utils.PanicIfNeeded(err)+ request.MessageID = c.Params("message_id")++ err = validations.ValidateUpdateMessage(request)+ utils.PanicIfNeeded(err)+ fmt.Println(request)++ response, err := controller.Service.UpdateMessage(c.UserContext(), request)+ utils.PanicIfNeeded(err)++ return c.JSON(utils.ResponseData{+ Code: 200,+ Message: response.Status,+ Results: response,+ })+}diff --git a/src/services/send_service.go b/src/services/send_service.goindex 08cdcd0a..2c54e476 100644--- a/src/services/send_service.go+++ b/src/services/send_service.go@@ -369,3 +369,23 @@ func (service serviceSend) Revoke(_ context.Context, request domainSend.RevokeReresponse.Status = fmt.Sprintf("Revoke success %s (server timestamp: %s)", request.Phone, ts)return response, nil}++func (service serviceSend) UpdateMessage(ctx context.Context, request domainSend.UpdateMessageRequest) (response domainSend.UpdateMessageResponse, err error) {+ utils.MustLogin(service.WaCli)++ recipient, ok := utils.ParseJID(request.Phone)+ if !ok {+ return response, errors.New("invalid JID " + request.Phone)+ }++ msgId := whatsmeow.GenerateMessageID()+ msg := &waProto.Message{Conversation: proto.String(request.Message)}+ ts, err := service.WaCli.SendMessage(context.Background(), recipient, msgId, service.WaCli.BuildEdit(recipient, request.MessageID, msg))+ if err != nil {+ return response, err+ }++ response.MessageID = msgId+ response.Status = fmt.Sprintf("Update message success %s (server timestamp: %s)", request.Phone, ts)+ return response, nil+}diff --git a/src/validations/send_validation.go b/src/validations/send_validation.goindex f3f92a67..02c4042e 100644--- a/src/validations/send_validation.go+++ b/src/validations/send_validation.go@@ -144,3 +144,19 @@ func ValidateRevokeMessage(request domainSend.RevokeRequest) error {return nil}++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)),+ )++ if err != nil {+ return utils.ValidationError{+ Message: err.Error(),+ }+ }++ return nil+}