Skip to content

fix(example): convert messageTimestamp to ms in fetchMessageHistory call#2616

Open
zomars wants to merge 1 commit into
WhiskeySockets:masterfrom
zomars:fix/example-fetchmessagehistory-ms
Open

fix(example): convert messageTimestamp to ms in fetchMessageHistory call#2616
zomars wants to merge 1 commit into
WhiskeySockets:masterfrom
zomars:fix/example-fetchmessagehistory-ms

Conversation

@zomars

@zomars zomars commented Jun 2, 2026

Copy link
Copy Markdown

Summary

  • The HistorySyncOnDemandRequest proto field is oldestMsgTimestampMs (ms), but WAMessage.messageTimestamp is seconds.
  • Example/example.ts was passing seconds directly into that field, silently mismatching units.
  • Convert to ms before the call.

Found while investigating #2452.

Test plan

  • yarn example still type-checks and runs
  • Sending onDemandHistSync from an old chat now logs a tsMs value in the ~1.7e12 range (correct ms) instead of ~1.7e9 (seconds)

Note: this fix alone does not resolve #2452 — the on-demand history response from WA still doesn't arrive (see comment thread on that issue). But the canonical example should be correct so others investigating don't burn time on this red herring.


Summary by cubic

Convert WAMessage.messageTimestamp (seconds) to milliseconds before calling sock.fetchMessageHistory in Example/example.ts, matching HistorySyncOnDemandRequest.oldestMsgTimestampMs. This fixes the seconds/ms mismatch so on‑demand history requests send a valid timestamp.

Written for commit 61f0ca3. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Fixed message timestamp format in history synchronization to correctly handle timestamp conversions, ensuring proper data retrieval and display.

The `HistorySyncOnDemandRequest` proto field is `oldestMsgTimestampMs`
(milliseconds) but `WAMessage.messageTimestamp` is seconds. The canonical
example was passing seconds where milliseconds are expected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Example/example.ts file updates the onDemandHistSync message handler to normalize and convert msg.messageTimestamp into milliseconds before passing it to sock.fetchMessageHistory. The timestamp is now multiplied by 1000 to ensure correct time-unit alignment with the API expectation.

Changes

Timestamp Conversion for Message History Fetch

Layer / File(s) Summary
Message timestamp millisecond conversion
Example/example.ts
The onDemandHistSync handler converts msg.messageTimestamp to milliseconds (via normalization and multiplication by 1000) before calling fetchMessageHistory, correcting the timestamp unit passed to the API.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A timestamp tripped in seconds true,
Now milliseconds shine right through,
The history sync now gets its pace,
With proper time in every place! ⏳✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: converting messageTimestamp to milliseconds in the fetchMessageHistory call, matching the code change in Example/example.ts.
Linked Issues check ✅ Passed The PR correctly addresses a bug in the example code: converting messageTimestamp from seconds to milliseconds before calling fetchMessageHistory, which is a required fix to properly use the API as documented in issue #2452.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the Example/example.ts file to correctly demonstrate the fetchMessageHistory API usage by converting timestamp units, which is directly related to the objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@whiskeysockets-bot

Copy link
Copy Markdown
Contributor

Thanks for opening this pull request and contributing to the project!

The next step is for the maintainers to review your changes. If everything looks good, it will be approved and merged into the main branch.

In the meantime, anyone in the community is encouraged to test this pull request and provide feedback.

✅ How to confirm it works

If you’ve tested this PR, please comment below with:

Tested and working ✅

This helps us speed up the review and merge process.

📦 To test this PR locally:

# NPM
npm install @whiskeysockets/baileys@zomars/Baileys#fix/example-fetchmessagehistory-ms

# Yarn (v2+)
yarn add @whiskeysockets/baileys@zomars/Baileys#fix/example-fetchmessagehistory-ms

# PNPM
pnpm add @whiskeysockets/baileys@zomars/Baileys#fix/example-fetchmessagehistory-ms

If you encounter any issues or have feedback, feel free to comment as well.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Example/example.ts`:
- Around line 150-152: Guard against a null/undefined messageTimestamp before
converting: replace the non-null assertion on msg.messageTimestamp with a
nullish check (e.g., if (msg.messageTimestamp == null) { /* handle missing
timestamp: skip, log, or return */ }) and only then assign tsRaw and compute
tsMs using the existing conversion logic ((typeof tsRaw === 'number' ? tsRaw :
tsRaw.toNumber()) * 1000); update the call to sock.fetchMessageHistory to use
that validated tsMs; reference msg.messageTimestamp, tsRaw, tsMs,
sock.fetchMessageHistory and msg.key when making the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6ec596b7-083d-4b9c-a7f9-956b758fd0fe

📥 Commits

Reviewing files that changed from the base of the PR and between 78e7e4e and 61f0ca3.

📒 Files selected for processing (1)
  • Example/example.ts

Comment thread Example/example.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

[BUG] fetchMessageHistory: on-demand history sync request succeeds but no response received

2 participants