Skip to content

Add username query functionality and utilities with tests#2680

Open
KiroFyzu wants to merge 6 commits into
WhiskeySockets:masterfrom
KiroFyzu:master
Open

Add username query functionality and utilities with tests#2680
KiroFyzu wants to merge 6 commits into
WhiskeySockets:masterfrom
KiroFyzu:master

Conversation

@KiroFyzu

@KiroFyzu KiroFyzu commented Jul 2, 2026

Copy link
Copy Markdown

This pull request introduces support for WhatsApp username lookups and utilities for handling username keys. It adds new API methods for querying usernames, utility functions for generating and validating username keys, and comprehensive tests for these new features. Additionally, it updates the documentation and improves protocol parsing for username fields.

WhatsApp Username Lookup and Utilities

API and Type Additions:

  • Added new types (WAUsernameQuery, WAUsernameLookupResult, WAUsernameInfo) to src/Types/Socket.ts to support username queries and results.
  • Introduced onWhatsAppUsername and fetchUsername methods in makeSocket (in src/Socket/socket.ts) for username-based lookups and fetching usernames by JID. [1] [2]
  • Updated exports in src/Utils/index.ts to include new username utilities.

Username Key Utilities:

  • Added src/Utils/username.ts with utility functions for validating, generating, and working with username keys (e.g., isValidUsernameKey, makeRandomUsernameKey).

Protocol and Parsing Improvements:

  • Improved USyncUsernameProtocol to parse username fields from both string and buffer content, ensuring compatibility with different response formats.

Testing:

  • Added comprehensive tests for username key utilities (src/__tests__/Utils/username.test.ts) and USync username protocol parsing (src/__tests__/WAUSync/username.test.ts). [1] [2]

Documentation:

  • Updated the README.md to reference the new package source.

Summary by cubic

Adds username lookup via new socket APIs and username-key utilities. Improves USync username parsing, adds types, tests, and README docs.

  • New Features
    • Added onWhatsAppUsername and fetchUsername in makeSocket for username lookups and fetching by JID.
    • Added username key utils: isValidUsernameKey, isRepeatedDigitUsernameKey, makeRepeatedDigitUsernameKey, makeRandomUsernameKey (exported via src/Utils/index.ts).
    • Improved USyncUsernameProtocol to parse usernames from strings and buffers; added WAUsernameQuery, WAUsernameLookupResult, and WAUsernameInfo types. Added unit tests and updated README.

Written for commit ffc47a4. Summary will update on new commits.

Review in cubic

@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@KiroFyzu/baileys#master

# Yarn (v2+)
yarn add @whiskeysockets/baileys@KiroFyzu/baileys#master

# PNPM
pnpm add @whiskeysockets/baileys@KiroFyzu/baileys#master

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

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ade31fb6-909f-4cad-9a67-674fc33e4e1d

📥 Commits

Reviewing files that changed from the base of the PR and between 731cd6b and d12c1fc.

📒 Files selected for processing (8)
  • README.md
  • src/Socket/socket.ts
  • src/Types/Socket.ts
  • src/Utils/index.ts
  • src/Utils/username.ts
  • src/WAUSync/Protocols/USyncUsernameProtocol.ts
  • src/__tests__/Utils/username.test.ts
  • src/__tests__/WAUSync/username.test.ts
👮 Files not reviewed due to content moderation or server errors (8)
  • src/Utils/index.ts
  • src/Utils/username.ts
  • src/Types/Socket.ts
  • src/tests/Utils/username.test.ts
  • src/Socket/socket.ts
  • src/tests/WAUSync/username.test.ts
  • src/WAUSync/Protocols/USyncUsernameProtocol.ts
  • README.md

📝 Walkthrough

[!WARNING]

Walkthrough skipped

File diffs could not be summarized.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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.

@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.

1 issue found across 8 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread README.md Outdated
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@KiroFyzu KiroFyzu mentioned this pull request Jul 2, 2026
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.

2 participants