feat(events): add isLatest and progress to messages.set event
O evento messages.set não enviava as propriedades isLatest e progress do Baileys, perdendo informações importantes sobre a sincronização do histórico.
O comportamento ocorria porque o método sendDataWebhook enviava apenas o array de mensagens:
this.sendDataWebhook(Events.MESSAGES_SET, [...messagesRaw]);
Com a sincronização de histórico do WhatsApp, é importante saber quando o sync está completo (isLatest=true) e o progresso percentual (progress).
Ajuste realizado:
ANTES:
{
"event": "messages.set",
"instance": "minha-instancia",
"data": [...]
}
DEPOIS:
{
"event": "messages.set",
"instance": "minha-instancia",
"isLatest": true,
"progress": 85,
"data": [...]
}
Com essa alteração, consumidores do webhook podem identificar quando a sincronização está completa e acompanhar o progresso.
📋 Description
Add support for extra fields in event payload root, specifically isLatest and progress from Baileys' messaging-history.set event.
🔗 Related Issue
N/A
🧪 Type of Change
- [ ] 🐛 Bug fix (non-breaking change which fixes an issue)
- [x] ✨ New feature (non-breaking change which adds functionality)
- [ ] 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] 📚 Documentation update
- [ ] 🔧 Refactoring (no functional changes)
- [ ] ⚡ Performance improvement
- [ ] 🧹 Code cleanup
- [ ] 🔒 Security fix
🧪 Testing
- [x] Manual testing completed
- [x] Functionality verified in development environment
- [x] No breaking changes introduced
- [x] Tested with different connection types (if applicable)
📸 Screenshots (if applicable)
N/A
✅ Checklist
- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have manually tested my changes thoroughly
- [x] I have verified the changes work with different scenarios
- [x] Any dependent changes have been merged and published
📝 Additional Notes
- Added
extra?: Record<string, any>field toEmitDatatype - Updated
EventManager.emit()to accept extra parameters - Updated
sendDataWebhook()to accept and pass extra fields - Updated all 7 event controllers to spread extra fields in payload (webhook, rabbitmq, sqs, websocket, pusher, kafka, nats)
- Used
(extra ?? {})to handle undefined safely - Spread extra first to prevent overriding core fields like
event,instance,data - Fully backward compatible - the
extraparameter is optional
Reviewer's Guide
Adds support for passing arbitrary extra metadata through the event pipeline so that Baileys messaging-history.set events can expose isLatest and progress on the messages.set payload across all delivery mechanisms (webhook, queues, websockets, etc.).
Sequence diagram for messages.set event with isLatest and progress propagation
sequenceDiagram
participant BaileysStartupService
participant ChannelStartupService
participant EventManager
participant WebhookController
actor WebhookConsumer
BaileysStartupService->>BaileysStartupService: receive messaging_history_set(messages, isLatest, progress)
BaileysStartupService->>ChannelStartupService: sendDataWebhook(MESSAGES_SET, messagesRaw, true, undefined, {isLatest, progress})
ChannelStartupService->>ChannelStartupService: build EmitData with extra = {isLatest, progress}
ChannelStartupService->>EventManager: emit(eventData)
EventManager->>WebhookController: emit(eventData)
WebhookController->>WebhookController: build payload {
WebhookController->>WebhookController: event, instance, data, server_url, apikey, ...extra
WebhookController->>WebhookConsumer: POST messages.set payload including isLatest and progress
WebhookConsumer->>WebhookConsumer: process messages with history sync metadata
Class diagram for updated event pipeline with extra metadata support
classDiagram
class EmitData {
+string instanceName
+string origin
+string event
+any data
+string serverUrl
+string dateTime
+string sender
+string apiKey
+boolean local
+string_array integration
+Record_string_any extra
}
class EventManager {
+emit(eventData: EmitData) Promise_void
}
class EventControllerInterface {
<<interface>>
+set(instanceName: string, data: any) Promise_any
+get(instanceName: string) Promise_any
+emit(emitData: EmitData) Promise_void
}
class EventController {
+set(instanceName: string, data: any) Promise_any
+get(instanceName: string) Promise_any
+emit(emitData: EmitData) Promise_void
}
class WebhookController {
+emit(emitData: EmitData) Promise_void
}
class RabbitmqController {
+emit(emitData: EmitData) Promise_void
}
class SqsController {
+emit(emitData: EmitData) Promise_void
}
class WebsocketController {
+emit(emitData: EmitData) Promise_void
}
class PusherController {
+emit(emitData: EmitData) Promise_void
}
class KafkaController {
+emit(emitData: EmitData) Promise_void
}
class NatsController {
+emit(emitData: EmitData) Promise_void
}
class ChannelStartupService {
+sendDataWebhook(event: Events, data: object, local: boolean, integration: string_array, extra: Record_string_any) Promise_void
}
class BaileysStartupService {
+sendDataWebhook(event: Events, data: object, local: boolean, integration: string_array, extra: Record_string_any) Promise_void
}
EventControllerInterface <|.. EventController
EventController <|-- WebhookController
EventController <|-- RabbitmqController
EventController <|-- SqsController
EventController <|-- WebsocketController
EventController <|-- PusherController
EventController <|-- KafkaController
EventController <|-- NatsController
EventManager --> WebhookController : uses
EventManager --> RabbitmqController : uses
EventManager --> SqsController : uses
EventManager --> WebsocketController : uses
EventManager --> PusherController : uses
EventManager --> KafkaController : uses
EventManager --> NatsController : uses
ChannelStartupService --> EventManager : emit events
BaileysStartupService --|> ChannelStartupService
EmitData <.. EventManager : parameter
EmitData <.. EventController : parameter
EmitData <.. WebhookController : parameter
EmitData <.. RabbitmqController : parameter
EmitData <.. SqsController : parameter
EmitData <.. WebsocketController : parameter
EmitData <.. PusherController : parameter
EmitData <.. KafkaController : parameter
EmitData <.. NatsController : parameter
note for WebhookController "In emit, builds payload with event, instance, data, and spreads extra into root"
note for KafkaController "In emit, spreads extra into Kafka message payload"
note for NatsController "In emit, spreads extra into NATS message payload"
note for RabbitmqController "In emit, spreads extra into RabbitMQ message payload"
note for SqsController "In emit, spreads extra into SQS message payload"
note for WebsocketController "In emit, spreads extra into WebSocket message payload"
note for PusherController "In emit, spreads extra into Pusher event payload"
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Extend event emission types and plumbing to carry optional extra fields through the system. |
|
src/api/integrations/event/event.controller.tssrc/api/integrations/event/event.manager.tssrc/api/services/channel.service.ts |
| Propagate extra metadata onto outbound messages for all event transports. |
|
src/api/integrations/event/kafka/kafka.controller.tssrc/api/integrations/event/nats/nats.controller.tssrc/api/integrations/event/pusher/pusher.controller.tssrc/api/integrations/event/rabbitmq/rabbitmq.controller.tssrc/api/integrations/event/sqs/sqs.controller.tssrc/api/integrations/event/webhook/webhook.controller.tssrc/api/integrations/event/websocket/websocket.controller.ts |
Emit Baileys messages.set events with isLatest and progress metadata. |
|
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts |
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
Please, fix the lint with npm run lint