Commit graph whatsapp-web.js/src/util
Author SHA1 Message Date
KH Soh
4532ae94ae
fix: Fix/get contacts for biz contacts (#201680)
* Updated WWebJS.getContacts to handle business or enterprise contacts properly

* Added missing return statement
2026-03-25 10:25:53 -03:00
Adi1231234
016a56bb56
fix: use WA's own LID resolution for block/unblock (#201671)
* fix: use WA's own LID resolution for block/unblock

block() was passing a Chat object to blockContact() which expects a
contact. unblock() was using synchronous Contact.get() which returns
undefined if the contact isn't cached.

with blocklist migration enabled, blocking a PN contact without a chat
fails because the internal S() function needs a LID or an existing chat
to resolve the accountLid. The old getChat() approach worked around this
by creating a chat via findOrCreateLatestChat, but that's a side effect
and passes the wrong type.

use WAWebBlockContactUtils.getContactToBlockOnlyUseIfNoAssociatedChat()
instead, which is WA's own utility for this exact case. It resolves the
contact's LID via getCurrentLidContact() without needing to create a
chat.

* fix: check alternate WID for blocked status in getContactModel

iscontactblocked on PN contacts returns false because the Blocklist
only contains LID entries. Use getAlternateUserWid() to resolve
the PN/LID mapping and check the Blocklist directly, matching WA
web's own $Contact$p_3 fallback logic.

---------

Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com>
2026-03-24 10:42:28 -03:00
Adi1231234
6de0b0dd2b
fix: prevent store model mutation in getContact and getChatModel LID handling (#127098)
* fix: prevent store mutation in getContact/getChatModel LID handling

getcontact() and getChatModel() overwrite .id directly on live Backbone
model references from WhatsApp Web's Contact/Participant store. This
permanently corrupts the store for the lifetime of the session, causing
all subsequent lookups for the same contact to crash with:
- "Cannot read properties of undefined (reading '_serialized')"
- "Data passed to getter must include an id property"

the fix resolves LID to phone on the serialized copy only, never
touching the live store model.

fixes #127054

* perf: use BusinessProfile.find() instead of fetchBizProfile()

businessprofile.find() checks the local cache first and only fetches
from the server when the profile is missing, while fetchBizProfile()
always makes a network call (~85-100ms per contact). This significantly
reduces latency when getContact is called repeatedly for the same
business contacts.

closes #201656

co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: remove unnecessary try/catch around BusinessProfile.find()

businessprofile.find() never throws for non-business contacts - it returns
a BusinessProfile model with profileOptions: null, not an error. The comment
was factually incorrect. The existing profileOptions guard handles the
non-business case correctly without any exception handling.

verified in WhatsApp Web DevTools: find() returns a valid object for regular,
business, LID, and even non-existent contacts. Only throws when called without
an id, which cannot happen here.

co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor: simplify contact/chat model utils via native WA functions

replace the O(n²) LID participant loop with WAWebLidMigrationUtils.toPn()
which resolves LID WIDs via LidPnCache in O(1). Remove the findContact
wrapper since Contact.find() accepts strings directly. Use
wawebwidfactory.createWidFromWidLike() for safe isLid() calls that handle
plain-object contact ids without WID prototype methods.

co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* perf: skip BusinessProfile.find() for non-business contacts

wa's own source guards this behind isBusiness || isEnterprise
(WAWebUseBusinessProfile.react). No point querying business profiles
for regular contacts - saves a wasted IQ roundtrip (~80ms) per call.

* revert: remove block/unblock changes from this PR

moved to a dedicated PR (#201671) with a proper fix using
wawebblockcontactutils.getContactToBlockOnlyUseIfNoAssociatedChat()
for correct LID resolution.

* fix: convert contactId to Wid before collection find() calls

contact.find() and BusinessProfile.find() reject plain strings when
the entry is not cached or stale, throwing "gadd called without an id
attr". Use createWid(contactId) to ensure a proper Wid object is passed.

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 10:00:11 -03:00
2^1
807efd502d
chore: cleanup, ci workflows and formatting (#127064)
* ci: setup workflows, dependabot, labeler and commit linting

* docs: update README, community files and issue templates

* chore: configure prettier, editorconfig and format codebase

* chore: restore changes lost during rebase

* docs: adjust url for new logo

* fix: align badges

* chore: resolve conflicts and re-add temp lint
2026-03-10 01:45:12 +02:00
Rajeh Taher
883d7e4eda
Store: remove all mentions of window.Store (#127077)
* Store: remove all mentions of window.Store

* Apply suggestion from @BenyFilho

Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com>

---------

Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com>
2026-03-01 16:49:21 -03:00
Rajeh Taher
9b1eb76b2b
general: tree-shaking pre-MD and old comet versions (#5675)
Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com>
Co-authored-by: tuyuribr <45042245+tuyuribr@users.noreply.github.com>
2026-02-10 23:24:54 +00:00
BenyFilho
2056ae83e1
Fix getFormattedNumber (#5806) 2026-02-06 21:44:15 -03:00
A. Rifqi Yarzuq Arfani
e66d94efd9
Fix update channel module (#5791)
* Fix getChats (#5779)

* Fix: getChats -> getChatModel -> GroupMetadata and NewsletterMetadata

* Fix module change

* fix: change wrong update module of channel

* fix: correct reference to pupPage in deleteChannel method

---------

Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com>
Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2026-02-03 22:36:16 +02:00
BenyFilho
32e404292b
Fix Channels WhatsApp module change (#5787) 2026-01-30 15:31:07 +02:00
BenyFilho
ce9dd1d678
Removing unused and unavailable module (#5785) 2026-01-30 10:12:41 -03:00
BenyFilho
207a5ad104
Fix getChats (#5779)
* Fix: getChats -> getChatModel -> GroupMetadata and NewsletterMetadata

* Fix module change
2026-01-30 10:50:19 +02:00
noelcarcasesLYN
b03680a70c
Fixes media upload to channels (#5697)
Ensures correct media upload to channels by using the mimetype from mediaInfo, rather than the file, when creating OpaqueData.

Also, it replaces the call to the function getRandomFilehash with the value of the function to retrieve the correct token.

Co-authored-by: Noel Carcases <noel.david.carcases.gomez@ibm.com>
Co-authored-by: Shir Serlui <70711723+shirser121@users.noreply.github.com>
Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com>
2026-01-30 01:55:30 +00:00
Naor
c61a2ef189
fix: send sticker 2026-01-29 19:34:58 -03:00
Naor
fc2e97e5ab
Refactor sendSeen to include threadId parameter 2026-01-29 19:32:41 -03:00
Filipe
dd9df4083a
fix: use markSeen instead of sendSeen to fix markedUnread error (#5719)
Fixes TypeError: Cannot read properties of undefined (reading 'markedUnread')
that occurs in newer WhatsApp Web versions.

The sendSeen method was removed/changed in recent WhatsApp Web updates.
Using markSeen resolves the issue.

Fixes #5718

Co-authored-by: cp1797 <cp1797@users.noreply.github.com>
Co-authored-by: eltonnicolau <eltonnicolau@users.noreply.github.com>
Co-authored-by: telmedola <telmedola@users.noreply.github.com>
Co-authored-by: qw271862028 <qw271862028@users.noreply.github.com>
Co-authored-by: duola8789 <duola8789@users.noreply.github.com>
2026-01-19 15:54:31 +02:00
Pedro S Lopez
c13510e907 chore: fix jsdoc invalid types 2026-01-05 01:40:46 -04:00
RendyCraft047
6aa1bd85ab
feat: whatsapp stories implementation (#3994)
* support sending message from status broadcast

* add to index.d.ts

* add method to contact

* new modules

* Update Utils.js

* add for the examples

* add color assertion function

* finishing..

* added waveforms for audio messages and minor fixes

* fix eslint

* refactor

reorganize the store to include additional modules.

* adapt

* the last one.

---------

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2025-12-13 06:34:55 +02:00
BenyFilho
5438c2042b
Fixing msg.getContact and getContactById (#3978) 2025-11-25 11:25:27 -03:00
RendyCraft047
d815847d3e
fix: addition and improvement of enumerable values on types (#3740)
* Update index.d.ts

* Update Constants.js

* fix

* `code_received` is missing too

* album message types

* add to index.d.ts

* fix types error
2025-11-20 11:30:54 +00:00
Jan Loewe
166dc73c73
feat(ScheduledEvent): add none option for callType (#3838) 2025-11-20 11:28:32 +00:00
Conan Yu
34b787a795
fix: send image rendering blured (#3775)
Co-authored-by: Yu <>
Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2025-11-09 22:39:25 +00:00
RendyCraft047
0c36613cc7
feat+fix: send vote messages & vote update event (#3913)
* add send vote function

* Update index.d.ts

* fix and add required modules

* fix poll update in group chat

* adjustments to improvements

* add example usages

* fix eslint

---------

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2025-11-09 16:37:51 -03:00
BenyFilho
05f651b521
Fix Group setAddMembersAdminsOnly setMessagesAdminsOnly setInfoAdminsOnly (#3933)
* Add module to setGroupProperty

* Update methods setAddMembersAdminsOnly setMessagesAdmin setInfoAdminsOnlysOnly

---------

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2025-11-06 19:34:53 +00:00
BenyFilho
4327a5f681
Fix method openChatWindow (#3936)
Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2025-11-06 21:32:06 +02:00
BenyFilho
0cdfda238f
Fix Reject Calls (#3909) 2025-11-04 19:13:18 +00:00
BenyFilho
829dd7f6d0
Fix Message Forward (#3910) 2025-11-04 16:09:42 -03:00
BenyFilho
472234da53
Fix PushNotifications (#3801) 2025-10-07 19:27:36 +00:00
BenyFilho
90dc8c8ad4
Fix Mention in Large Groups (#3803)
* Fix Mentioning in Large Groups

* Update Utils.js

* Update Utils.js

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
2025-10-07 19:25:48 +00:00
BenyFilho
7c7851f4d4
feat: getPollVotes (#3807)
* Add required module

* Add getPollVotes function

* Add getPollVotes function

* Add getPollVotes function

* Add Message.getPollVotes

* Add Message.getPollVotes
2025-10-07 19:24:05 +00:00
RendyCraft047
9b3d987711
fix: getPinnedMessages() (#3797)
* fix duplicate store

* fix: handle async calls properly

* fix: filter out only pinned messages

Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com>

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com>
2025-10-07 22:11:37 +03:00
alechkos
7304ec2135
feat: get/add/edit customer notes (#3806)
* feat: add required module

* feat: add 'addOrEditCustomerNote' function

* feat: add 'getCustomerNote' function

* fix: check for logic availability

* feat: add 'Chat.addOrEditCustomerNote'

* feat: add Chat.getCustomerNote
2025-09-27 11:35:22 -03:00
BenyFilho
0825033850
Fix Disconnections - **UPDATED REINSTALL IT** (#3811)
* Update window.injectToFunction

* Fix window.injectToFunction

* window.injectToFunction

* Fix window.injectToFunction

* Fix window.injectToFunction

* Removing override isLidMigrated
2025-09-26 00:37:32 +03:00
BenyFilho
ae7bbe7f37
Fix Inject Module Function (#3795)
* fix inject module function

* Update src/util/Injected/Store.js

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
2025-09-10 17:14:20 +03:00
alechkos
d077716315
fix: enforce retrieval lid and phone for previously unknown contacts (#3702)
* fix: check existance if undefined

* fix: handle missing lid/phone in group participant resolution

* refactor: remove duplicated logic
2025-09-06 18:24:19 +03:00
BenyFilho
c9665438f6
Fix method participant on sendMessage (#3778)
* Fix method participant on sendMessage

* Update Utils.js

* Update Utils.js
2025-09-06 00:20:36 +03:00
Seow Zhen Jun
5276e30ac6
fix: Lid is missing in chat table (#3703)
* Use window.Store.FindOrCreateChat.findOrCreateLatestChat to get chat

* refactor: change find to findOrCreateLatestChat

* refactor: update 'injectToFunction' to support nested props in modules

* fix: resolve 'Lid is missing in chat table' error

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
2025-09-05 22:19:15 +03:00
BenyFilho
4ac22c8c37
fix Event Ready Again and SendMessage (#3747)
* fix Event Ready Again

* Fixing SendMessage

* Fixing RejectCall
2025-09-02 03:56:56 +03:00
alechkos
2ac982ee1c
fix: return poll vote reactions (#3694)
* wip: return poll vote reactions

* wip: add module

* wip: return poll vote reactions

* wip: return poll vote reactions

* Update Client.js

* Update PollVote.js

* wip: use async getMessagesById

* Update Client.js

* style: clean shit

* style: reformat code

---------

Co-authored-by: tuyuribr <45042245+tuyuribr@users.noreply.github.com>
2025-08-28 11:32:37 +03:00
Jie
6d3078fd77
fix: Correct method invocation (#3720) 2025-08-27 01:34:43 +03:00
alechkos
bd677a8a66
fix: send message properly (#3692)
* fix: remove high cpu consumption by adding waiting for message logic

 Co-authored-by: Shir Serlui <70711723+shirser121@users.noreply.github.com>

* refactor: use already defined msg id

* refactor: use optional arg for waiting for msg ack
2025-08-12 07:33:02 +03:00
Shir Serlui
ecb50450b7
Fix checking if sending to a group (#3592)
* Fix checking if sending to a group

* chore: mark channels as done feature

* refactor: add safety check for chat.id.isGroup

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
2025-08-09 00:46:18 +03:00
Mob Code 100
b5adf47664
feat: Switch between QR or phone number pairing method (#3180)
* fix(webpack-exodus): Added the new patch

* fix(webpack-exodus): Fixed v2.3000.x and v2.24

* chore(webpack-exodus): eslint

* fix(webpack-exodus): Fixed Store

* fix(webpack-exodus): slight store fix

* chore(webpack-exodus): fix example so that I don't crash on every load

* chore: eslint fix

* fix(webpack-exodus): prevent confusion with build systems

* fix(webpack-exodus): Add proper groups module

* fix(webpack-exodus): Fix order queries

* fix(webpack-exodus): Bad export name

* feat(webpack-exodus): Re-injection, No more selectors, Pairing Code auth

* fix(webpack-exodus): Eslint and better login/logout handling

* fix(webpack-exodus): 2.24 compatibility

* revert testing options

* chore(webpack-exodus): ESLint

* chore(webpack-exodus): final eslint tweak (did not commit with last commit for some reason)

* style: fix broken link in readme file

* fix(webpack-exodus): Fix forwarding messages

* fix(webpack-exodus): finish forwarding function

* Making the ESLint god happy

* Fix window.Store.ProfilePic.profilePicFind is not a function error (#3001)

* Change window.Store.ProfilePic.profilePicFind to window.Store.ProfilePic.requestProfilePicFromServer

* Prevent breaking v2.2x

* refactor: make it more readable

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>

* Sanitize, improves and fixes

* make ESList god happy

* fix getInviteCode for group (#3007) (#3029)

* fix getInviteCode for group (#3007)

* move changes to proper getInviteCode method.

* style fix

* refactor: add try-catch in a case the user is not a group admin

* refactor: handle promise properly

---------

Co-authored-by: Sven Neumann <s.neumann@websix.de>
Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>

* fixes

* Update LocalWebCache.js

* fix delete on 2.3000 (#3048)

* fix delete on 2.3000

* fix compareWwebVersions

* fix: use proper comparison operator

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>

* Implement bot invoking capabilities (#3009)

* Implement bot invoking capabilities

* Update index.d.ts

* Eslint

* Webpack exodus fix message_reaction event (#3099)

* exposed WAWebAddonReactionTableMode

* capture reaction using WAWebAddonReactionTableMode

* move compareWwebVersions and check version before trying to expose new store

* message_reaction on example.js (#3102)

* handle message_reaction event on example.js

* log wweb version on ready

* fix reactions on pvt chats (#3104)

* New group function

* new group settings

* Update Client.js

* Switch pairing method between QR and phone number

* Remove existing pairing code interval

* Modify example.js

* Update docs

* Small improvements in inject function

* Fix ESLint

* example.js correction

* docs: fix docs for 'requestPairingCode' method

Co-authored-by: Leandro Matilla <30844484+wis-dev@users.noreply.github.com>

* Update Utils.js getChatModel because Meta chat object affected Group Chats

* Ajust to set isGroup as false as default

* Remove the need for custom interval

* Fix typo

* Fix intermittent response bug #9864

Co-authored-by: Mob Code 100 <66469454+MobCode100@users.noreply.github.com>

* fix: eslint fix

* Revert "Remove the need for custom interval"

This reverts commit c5d5e5626684742cadbf58f28739c1c2c9dcc582.

* Add wait for PairingCodeLinkUtils on requestPairingCode

* Remove unused vars WhatsWebStaticURL

Co-authored-by: Mob Code 100 <66469454+MobCode100@users.noreply.github.com>

* style: format code

---------

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
Co-authored-by: tuyuribr <45042245+tuyuribr@users.noreply.github.com>
Co-authored-by: Seow Zhen Jun <56989187+seowzhenjun0126@users.noreply.github.com>
Co-authored-by: Sven <sven2neumann@gmail.com>
Co-authored-by: Sven Neumann <s.neumann@websix.de>
Co-authored-by: Jorge Rocha Gualtieri <jorge@jrg.com.br>
Co-authored-by: Mateus Mercer <accounts@matbm.net>
Co-authored-by: Leandro Matilla <30844484+wis-dev@users.noreply.github.com>
Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com>
Co-authored-by: Shir Serlui <70711723+shirser121@users.noreply.github.com>
2025-08-09 00:37:25 +03:00
alechkos
f9db14d185
feat: Event messages (#3345)
* feat: add createCallLink function

* feat: create Event class

* feat: add functionality for sending Events

* feat: add editEvent function

* refactor: send event location prop as wa does

* refactor: combine modules

* feat: add sendResponseToEvent function

* fix: createEventCallLink parameter

* docs: add documentation

* fix: eslint

* refactor: change timestamp to Date for the user's convenience

* refactor: rename 'Event' to 'ScheduledEvent' for more clarity

* style: fix typo in inner function

* refactor: remove unnecessary inner function

* refactor: rename 'sendResponseToEvent' to 'sendResponseToScheduledEvent' for more clarity

* fix: update the module name
2025-08-09 00:36:27 +03:00
alechkos
ab321f3d7e
fix: Message.pin and Message.unpin (#3319)
* fix: update function to wweb version >2.3000.0

* feat: add foolproof check

* fix: override internal function correctly
2025-08-09 00:35:40 +03:00
alechkos
18b1d32825
feat: get pinned messages (#3004)
* feat: add getPinnedMessage method

* docs: add docs for the method

* chore: fix eslint

* refactor: change logic of getting pinned messages

* refactor: combine all PinnedMsgUtils

* chore: remove comments and mark as ready for review

* style: fix typo

Co-authored-by: crazynds <36674096+crazynds@users.noreply.github.com>

---------

Co-authored-by: crazynds <36674096+crazynds@users.noreply.github.com>
2025-08-09 00:34:52 +03:00
BenyFilho
35133a72fc
Fix Message Forward (#3680)
* Fix Message Forward

* Fix Message Forward

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
2025-08-06 15:51:36 +03:00
BenyFilho
81fd090e36
fix: Client.createGroup + GroupChat.addParticipants (#3670)
* Adjustment addParticipants

* createGroup fully refactored, fixed bugs, added creation options and updated docs

* fix: eslint fix

* refactor: GroupChat.addParticipants fully refactored

* fix: eslint fix

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
2025-08-01 06:43:45 +03:00
devlikeapro
bd08b69c87
Fix send seen on chat - Stream markAvailable (#3663)
fix #3540
2025-07-20 11:07:15 +03:00
BenyFilho
90f2222df0
Fix .sendMessage return (#3612)
Fix sendMessage return
2025-06-26 21:16:20 +03:00
BenyFilho
daaa04445f
Fix Send Animated Sticker (#3591)
* Fix Send Animated Sitckers

* Update Utils.js

* Add a condition to ignore channels

Add a condition to ignore channels and keep compatibility.

* chore: mark channels as done feature

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
2025-06-10 09:14:21 +03:00