feat(message): add POST /message/markplayed endpoint (played receipt / blue mic)#96
Conversation
Reviewer's GuideAdds a new POST /message/markplayed endpoint that mirrors the existing MarkRead flow to mark audio messages as played, wiring handler, service, and routing with validation and swagger annotations. Sequence diagram for POST /message/markplayed audio played receipt flowsequenceDiagram
actor Client
participant GinRouter as GinRouter
participant JIDValidationMiddleware as JIDValidationMiddleware
participant MessageHandler as MessageHandler
participant MessageService as MessageService
participant WhatsAppClient as WhatsAppClient
Client->>GinRouter: POST /message/markplayed
GinRouter->>JIDValidationMiddleware: ValidateNumberField
JIDValidationMiddleware-->>GinRouter: ok / error
GinRouter->>MessageHandler: MarkPlayed(ctx)
MessageHandler->>MessageService: MarkPlayed(data, instance)
MessageService->>MessageService: ensureClientConnected(instance.Id)
MessageService->>MessageService: utils.ParseJID(data.Number)
MessageService->>WhatsAppClient: MarkRead(context.Background(), data.Id, time.Now(), jid, jid, types.ReceiptTypePlayed)
WhatsAppClient-->>MessageService: result / error
MessageService-->>MessageHandler: timestamp / error
MessageHandler-->>Client: 200 success with timestamp / error JSON
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
MarkPlayed, thetsvariable is declared but never assigned before being returned, so the endpoint will always return the zero time string; consider mirroringMarkReadby assigningts = time.Now()and using that both for the client call and response. - The error log message in
MarkPlayed(Error validating message fields) is slightly misleading since only the phone number is validated at that point; consider making this log clearer or logging the actual invalid value to aid debugging.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `MarkPlayed`, the `ts` variable is declared but never assigned before being returned, so the endpoint will always return the zero time string; consider mirroring `MarkRead` by assigning `ts = time.Now()` and using that both for the client call and response.
- The error log message in `MarkPlayed` (`Error validating message fields`) is slightly misleading since only the phone number is validated at that point; consider making this log clearer or logging the actual invalid value to aid debugging.
## Individual Comments
### Comment 1
<location path="pkg/message/service/message_service.go" line_range="273-264" />
<code_context>
+ return "", err
+ }
+
+ var ts time.Time
+
+ jid, ok := utils.ParseJID(data.Number)
+ if !ok {
+ m.loggerWrapper.GetLogger(instance.Id).LogError("[%s] Error validating message fields", instance.Id)
+ return "", errors.New("invalid phone number")
+ }
+
+ err = client.MarkRead(context.Background(), data.Id, time.Now(), jid, jid, types.ReceiptTypePlayed)
+ if err != nil {
+ m.loggerWrapper.GetLogger(instance.Id).LogError("[%s] error marking message as played: %v", instance.Id, err)
+ return "", errors.New("error marking message as played")
+ }
+
+ return ts.String(), nil
+}
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Return value for timestamp is always zero-time because `ts` is never set.
In `MarkPlayed`, `ts` is declared but never assigned, so `ts.String()` will always return the zero time (`0001-01-01 ...`), which is inconsistent with `MarkRead` and likely incorrect. If you need to return the time the message was marked as played, set `ts := time.Now()` and use it both in the `MarkRead` call and for the return value. If no timestamp is needed, remove `ts` and adjust the return accordingly.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| @@ -258,6 +264,29 @@ func (m *messageService) MarkRead(data *MarkReadStruct, instance *instance_model | |||
| return ts.String(), nil | |||
There was a problem hiding this comment.
issue (bug_risk): Return value for timestamp is always zero-time because ts is never set.
In MarkPlayed, ts is declared but never assigned, so ts.String() will always return the zero time (0001-01-01 ...), which is inconsistent with MarkRead and likely incorrect. If you need to return the time the message was marked as played, set ts := time.Now() and use it both in the MarkRead call and for the return value. If no timestamp is needed, remove ts and adjust the return accordingly.
O que
Adiciona o endpoint
POST /message/markplayed— marca uma mensagem de áudio como reproduzida (mic azul / played receipt), viaclient.MarkRead(..., types.ReceiptTypePlayed).Segue exatamente o padrão do
MarkReadexistente:pkg/message/service/message_service.go—MarkPlayedStruct{Id []string, Number string}+MarkPlayed(...)pkg/message/handler/message_handler.go— handlerMarkPlayed(validanumber+id)pkg/routes/routes.go—POST /markplayedcomValidateNumberField()Por que esta PR substitui a #46
A #46 apontava pra
maina partir de uma base desatualizada e arrastava ~56 arquivos de ruído (rename da org, sync de submódulos, bundles do manager, swagger). Esta PR é a mesma mudança isolada (3 arquivos, +81/−0) rebaseada em cima dedevelop, conforme review do @NeritonDias.Pendente
swag init -g cmd/evolution-go/main.go) — annotation@Router /message/markplayedjá está no handler.Summary by Sourcery
Add support for marking audio messages as played via a new POST /message/markplayed endpoint.
New Features:
Enhancements:
Documentation: