zaileys 4.8.7 → 4.8.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,8 @@ export interface BuilderSocketLike {
19
19
  export type TextOptions = {
20
20
  rich?: boolean;
21
21
  } & AIRichOptions;
22
+ /** The pseudo-recipient WhatsApp uses for personal statuses (stories). */
23
+ export declare const STATUS_BROADCAST_JID = "status@broadcast";
22
24
  export declare class MessageBuilder<State extends BuilderState> {
23
25
  protected readonly __state?: State;
24
26
  protected readonly socket: BuilderSocketLike;
@@ -55,6 +57,11 @@ export declare class MessageBuilder<State extends BuilderState> {
55
57
  reply(quoted: WAMessage | WAMessageKey): MessageBuilder<State>;
56
58
  mentions(jids: string[]): MessageBuilder<State>;
57
59
  mentionAll(): MessageBuilder<State>;
60
+ /**
61
+ * Sets who sees a status posted to `status@broadcast`. WhatsApp delivers a status only to the jids
62
+ * listed here — an empty list is accepted by the server but reaches nobody, so this is required.
63
+ */
64
+ audience(jids: string[]): MessageBuilder<State>;
58
65
  disappearing(seconds: number): MessageBuilder<State>;
59
66
  then<T = WAMessageKey>(this: MessageBuilder<'content-set'>, onResolved: (key: WAMessageKey) => T, onRejected?: (err: unknown) => T | PromiseLike<T>): Promise<T>;
60
67
  private uploadHeaderMedia;
@@ -8,6 +8,7 @@ export type BuilderInternalState = {
8
8
  quoted?: WAMessage | WAMessageKey;
9
9
  mentions?: string[];
10
10
  mentionAll?: boolean;
11
+ statusJidList?: string[];
11
12
  disappearingSeconds?: number;
12
13
  resolveRecipient?: (raw: string) => Promise<string>;
13
14
  recordSent?: (message: WAMessage) => void;
@@ -10,6 +10,14 @@ import { TypedEventEmitter } from './event-emitter.js';
10
10
  import type { BaileysSocket, ClientEventMap, ClientOptions, ConnectionState, ProviderKind } from './types.js';
11
11
  import { CloudModule } from '../cloud/module.js';
12
12
  import { type WebhookHandler } from '../cloud/webhook.js';
13
+ /**
14
+ * Reads the `<result>` payload of a `w:mex` reply. A jid with no username comes back as an
15
+ * `XWA2ResponseStatus` instead of an `XWA2Username`, so entries without one are skipped.
16
+ */
17
+ export declare const parseMexUsers: (result: unknown) => Array<{
18
+ jid: string;
19
+ username: string;
20
+ }>;
13
21
  export declare class Client extends TypedEventEmitter<ClientEventMap> {
14
22
  readonly sessionId: string;
15
23
  auth: AuthStoreBundle;
@@ -156,10 +164,23 @@ export declare class Client extends TypedEventEmitter<ClientEventMap> {
156
164
  private handleOpen;
157
165
  private resolveMessageForResend;
158
166
  private lidMapping;
167
+ /** One round trip for many jids, so resolving a whole participant list is not N lookups. */
168
+ private lidMapBulk;
159
169
  /** Resolve a `@lid` JID to its phone-number JID (uses WhatsApp's LID mapping; may hit the network). */
160
170
  lidToPn(lid: string): Promise<string | null>;
161
171
  /** Resolve a phone-number JID to its `@lid` JID (uses WhatsApp's LID mapping; may hit the network). */
162
172
  pnToLid(pn: string): Promise<string | null>;
173
+ /** Bulk {@link lidToPn}. Returns a `lid -> pn` map; jids WhatsApp could not resolve are simply absent. */
174
+ lidToPns(lids: string[]): Promise<Map<string, string>>;
175
+ /** Bulk {@link pnToLid}. Returns a `pn -> lid` map; jids WhatsApp could not resolve are simply absent. */
176
+ pnToLids(pns: string[]): Promise<Map<string, string>>;
177
+ /**
178
+ * Looks up WhatsApp usernames (`@handle`) for many jids in one round trip. Returns a `jid -> username`
179
+ * map; jids whose owner has not set a username are simply absent. Works best with `@lid` jids.
180
+ */
181
+ usernames(jids: string[]): Promise<Map<string, string>>;
182
+ /** Single-jid {@link usernames}. `null` when the account has no username or the lookup fails. */
183
+ getUsername(jid: string): Promise<string | null>;
163
184
  /**
164
185
  * Download media bytes for a message stored in the message store (by key).
165
186
  * Tries both `fromMe` variants. `null` when the message is unknown or carries no media.
@@ -22,6 +22,11 @@ export declare class ChatModule {
22
22
  markUnread(jid: string): Promise<void>;
23
23
  star(key: WAMessageKey, starred?: boolean): Promise<void>;
24
24
  unstar(key: WAMessageKey): Promise<void>;
25
+ /**
26
+ * Asks WhatsApp to resend older messages from before `oldest`. Returns the request id; the messages
27
+ * themselves arrive later on the `history-sync` event, not from this call.
28
+ */
29
+ fetchHistory(count: number, oldest: WAMessageKey, oldestTimestamp: number): Promise<string>;
25
30
  delete(jid: string): Promise<void>;
26
31
  clear(jid: string): Promise<void>;
27
32
  }
@@ -1,5 +1,5 @@
1
1
  import type { DomainSocketLike } from './socket-like.js';
2
- import type { PrivacyConfig, PrivacySettings, WAReadReceiptsValue } from './types.js';
2
+ import type { PrivacyConfig, PrivacySettings, WAPrivacyCallValue, WAReadReceiptsValue } from './types.js';
3
3
  export declare class PrivacyModule {
4
4
  private readonly getSocket;
5
5
  constructor(getSocket: () => DomainSocketLike | undefined);
@@ -12,4 +12,6 @@ export declare class PrivacyModule {
12
12
  unblock(jid: string): Promise<void>;
13
13
  blocklist(): Promise<string[]>;
14
14
  disappearingMode(seconds: number): Promise<void>;
15
+ /** Restricts who may call you. `known` blocks calls from anyone outside your contacts. */
16
+ call(value: WAPrivacyCallValue): Promise<void>;
15
17
  }
@@ -1,4 +1,4 @@
1
- import type { ChatModification, GroupMetadata, NewsletterMetadata, ParticipantAction, WAMediaUpload, WAPrivacyGroupAddValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from 'baileys';
1
+ import type { ChatModification, GroupMetadata, NewsletterMetadata, ParticipantAction, WAMediaUpload, WAMessageKey, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from 'baileys';
2
2
  import type { LinkedGroup } from './types.js';
3
3
  export interface DomainSocketLike {
4
4
  groupCreate(subject: string, participants: string[]): Promise<GroupMetadata>;
@@ -60,6 +60,7 @@ export interface DomainSocketLike {
60
60
  updateStatusPrivacy(value: WAPrivacyValue): Promise<void>;
61
61
  updateReadReceiptsPrivacy(value: WAReadReceiptsValue): Promise<void>;
62
62
  updateGroupsAddPrivacy(value: WAPrivacyGroupAddValue): Promise<void>;
63
+ updateCallPrivacy(value: WAPrivacyCallValue): Promise<void>;
63
64
  updateDefaultDisappearingMode(duration: number): Promise<void>;
64
65
  fetchPrivacySettings(force?: boolean): Promise<{
65
66
  [_: string]: string;
@@ -73,6 +74,7 @@ export interface DomainSocketLike {
73
74
  profilePictureUrl(jid: string, type?: 'image' | 'preview', timeoutMs?: number): Promise<string | undefined>;
74
75
  fetchStatus(jid: string): Promise<unknown>;
75
76
  chatModify(mod: ChatModification, jid: string): Promise<void>;
77
+ fetchMessageHistory(count: number, oldestMsgKey: WAMessageKey, oldestMsgTimestamp: number): Promise<string>;
76
78
  newsletterCreate(name: string, description?: string): Promise<NewsletterMetadata>;
77
79
  newsletterFollow(jid: string): Promise<unknown>;
78
80
  newsletterUnfollow(jid: string): Promise<unknown>;
@@ -1,5 +1,5 @@
1
- export type { GroupMetadata, GroupParticipant, ParticipantAction, WAPrivacyValue, WAPrivacyOnlineValue, WAReadReceiptsValue, WAPrivacyGroupAddValue, NewsletterMetadata, WAMediaUpload, } from 'baileys';
2
- import type { WAPrivacyValue, WAPrivacyOnlineValue, WAReadReceiptsValue, WAPrivacyGroupAddValue } from 'baileys';
1
+ export type { GroupMetadata, GroupParticipant, ParticipantAction, WAPrivacyValue, WAPrivacyOnlineValue, WAReadReceiptsValue, WAPrivacyGroupAddValue, WAPrivacyCallValue, NewsletterMetadata, WAMediaUpload, } from 'baileys';
2
+ import type { WAPrivacyValue, WAPrivacyOnlineValue, WAReadReceiptsValue, WAPrivacyGroupAddValue, WAPrivacyCallValue } from 'baileys';
3
3
  export interface ParticipantUpdateResult {
4
4
  jid: string;
5
5
  status: string;
@@ -11,6 +11,8 @@ export interface PrivacyConfig {
11
11
  status?: WAPrivacyValue;
12
12
  readReceipts?: WAReadReceiptsValue;
13
13
  groupAdd?: WAPrivacyGroupAddValue;
14
+ /** Who may call you. `known` limits calls to your contacts. */
15
+ call?: WAPrivacyCallValue;
14
16
  }
15
17
  export type PrivacySettings = {
16
18
  [key: string]: string;
@@ -0,0 +1,7 @@
1
+ import type { CallerInfo } from './types.js';
2
+ /** Reads the caller details WhatsApp puts on a raw `<call>` stanza. Returns false when the node is not an offer. */
3
+ export declare const rememberCallerInfo: (raw: unknown) => boolean;
4
+ /** Pops the caller details captured for a call id, if the raw stanza carried any. */
5
+ export declare const takeCallerInfo: (callId: string) => CallerInfo | undefined;
6
+ /** Test seam: drops everything captured so far. */
7
+ export declare const resetCallerInfo: () => void;
@@ -19,6 +19,12 @@ export interface MediaAttachment {
19
19
  fileName: string | null;
20
20
  fileSize: number | null;
21
21
  ptt: boolean;
22
+ isAnimated: boolean;
23
+ duration: number | null;
24
+ width: number | null;
25
+ height: number | null;
26
+ pages: number | null;
27
+ thumbnail: Buffer | null;
22
28
  buffer(): Promise<Buffer>;
23
29
  stream(): Promise<Readable>;
24
30
  }
@@ -147,6 +153,25 @@ export interface TemplateMedia {
147
153
  buttons: MessageButton[];
148
154
  }
149
155
  export type ContextMedia = MediaAttachment | PollMedia | ContactMedia | LocationMedia | EventMedia | AlbumMedia | GroupInviteMedia | ProductMedia | OrderMedia | PaymentMedia | LinkPreviewMedia | ButtonsMedia | ListMedia | InteractiveMedia | TemplateMedia;
156
+ /** Attribution for a chat that started from a Meta ad (Click-to-WhatsApp). */
157
+ export interface AdAttribution {
158
+ /** The click id to join against Meta Ads reporting. */
159
+ clickId?: string;
160
+ sourceId?: string;
161
+ sourceUrl?: string;
162
+ /** Which Meta surface the ad ran on, e.g. `facebook`, `instagram`. */
163
+ sourceApp?: string;
164
+ sourceType?: string;
165
+ title?: string;
166
+ body?: string;
167
+ thumbnailUrl?: string;
168
+ /** Campaign reference you set on the ad. */
169
+ ref?: string;
170
+ }
171
+ export interface BusinessInfo {
172
+ /** WhatsApp-verified business name. Unlike `senderName` this cannot be set by the sender. */
173
+ verifiedName: string;
174
+ }
150
175
  export interface MessageContext {
151
176
  uniqueId: string;
152
177
  staticId: string;
@@ -158,6 +183,7 @@ export interface MessageContext {
158
183
  senderId: string;
159
184
  senderLid: string | null;
160
185
  senderName: string | null;
186
+ senderUsername: string | null;
161
187
  senderDevice: SenderDevice;
162
188
  timestamp: number;
163
189
  text: string;
@@ -170,6 +196,7 @@ export interface MessageContext {
170
196
  isViewOnce: boolean;
171
197
  isEphemeral: boolean;
172
198
  isForwarded: boolean;
199
+ isOld: boolean;
173
200
  isQuestion: boolean;
174
201
  isPrefix: boolean;
175
202
  isTagMe: boolean;
@@ -184,6 +211,12 @@ export interface MessageContext {
184
211
  isGroupStatusMention: boolean;
185
212
  isGroupStatus: boolean;
186
213
  isStory: boolean;
214
+ forwardCount: number;
215
+ ephemeralDuration: number | null;
216
+ addressingMode: 'pn' | 'lid';
217
+ mentionedGroups: string[];
218
+ ad?: AdAttribution;
219
+ business?: BusinessInfo;
187
220
  roomName(): Promise<string | null>;
188
221
  receiverName(): Promise<string | null>;
189
222
  media?: ContextMedia;
@@ -217,6 +250,13 @@ export interface BuildContextInput {
217
250
  isForwarded: boolean;
218
251
  isBroadcast: boolean;
219
252
  isNewsletter: boolean;
253
+ isOld?: boolean;
254
+ forwardCount?: number;
255
+ ephemeralDuration?: number | null;
256
+ addressingMode?: 'pn' | 'lid';
257
+ mentionedGroups?: string[];
258
+ ad?: AdAttribution;
259
+ business?: BusinessInfo;
220
260
  prefixes: string[];
221
261
  citationConfig?: CitationConfig;
222
262
  lidMap?: Map<string, string>;
@@ -7,6 +7,8 @@ export interface DecodeContext {
7
7
  selfLid?: string;
8
8
  selfName?: string;
9
9
  lidMap?: Map<string, string>;
10
+ /** WhatsApp replays a reconnect's backlog as `append`; live traffic arrives as `notify`. */
11
+ isOld?: boolean;
10
12
  logger?: DownloadLogger;
11
13
  channelId?: string;
12
14
  receiverId?: string;
@@ -4,6 +4,8 @@ import { type LongLike } from './_shared.js';
4
4
  export interface MutationContext {
5
5
  selfJid: string;
6
6
  pushName?: string;
7
+ /** Looks up the original poll so a vote's option hashes can be turned back into their text. */
8
+ resolvePoll?: (id: string, remoteJid: string) => Promise<proto.IWebMessageInfo | null>;
7
9
  }
8
10
  export interface ReactionItem {
9
11
  key: WAMessageKey;
@@ -1,4 +1,4 @@
1
1
  export * from './guards.js';
2
- export type { ButtonClickPayload, CallBase, CallPayload, DeletePayload, EditPayload, GroupJoinPayload, GroupLeavePayload, GroupParticipantInfo, GroupUpdatePayload, HistorySyncPayload, InboundEventMap, InboundEventName, LimitedPayload, ListSelectPayload, MediaDescriptor, MediaDownloadResult, MediaKind, MemberTagPayload, NewsletterPayload, PollVotePayload, PresencePayload, QuotedRef, ReactionPayload, SenderInfo, } from './types.js';
2
+ export type { ButtonClickPayload, CallBase, CallerInfo, CallPayload, DeletePayload, EditPayload, GroupJoinPayload, GroupLeavePayload, GroupParticipantInfo, GroupUpdatePayload, HistorySyncPayload, InboundEventMap, InboundEventName, LimitedPayload, ListSelectPayload, MediaDescriptor, MediaDownloadResult, MediaKind, MemberTagPayload, NewsletterPayload, PollVotePayload, PresencePayload, QuotedRef, ReactionPayload, SenderInfo, } from './types.js';
3
3
  export type { BuildContextInput, ChatType, CitationConfig, CitationPredicates, ContextMedia, MentionAllContext, MentionContext, MessageContext, SenderDevice, } from './context.js';
4
4
  export { buildMessageContext } from './context.js';
@@ -54,7 +54,10 @@ export interface DeletePayload {
54
54
  }
55
55
  export interface PollVotePayload {
56
56
  pollKey: WAMessageKey;
57
+ /** Raw SHA-256 hashes WhatsApp sends. Use {@link PollVotePayload.options} for readable text. */
57
58
  selectedOptions: string[];
59
+ /** The option text the voter picked. Needs the original poll in the store; empty when unavailable. */
60
+ options(): Promise<string[]>;
58
61
  voter: SenderInfo;
59
62
  timestamp: number;
60
63
  }
@@ -109,6 +112,25 @@ export type CallPayload = (CallBase & {
109
112
  }) | (CallBase & {
110
113
  kind: 'ended';
111
114
  });
115
+ export interface CallerInfo {
116
+ /** Caller platform as WhatsApp reports it, e.g. `iphone`, `android`, `smba`. More reliable than a jid device index. */
117
+ platform?: string;
118
+ /** Caller's WhatsApp app version, e.g. `2.26.30.78`. */
119
+ appVersion?: string;
120
+ /** Caller's pushname carried on the call stanza. */
121
+ name?: string;
122
+ /** ISO 3166 country the caller is dialling from, e.g. `ID`. */
123
+ countryCode?: string;
124
+ /** Caller's phone-number jid — present even when the call itself is addressed by LID. */
125
+ phoneJid?: string;
126
+ /** Raw network medium code the caller's device reported. */
127
+ networkMedium?: number;
128
+ /** Screen size the caller's device advertised. Video calls only. */
129
+ screen?: {
130
+ width: number;
131
+ height: number;
132
+ };
133
+ }
112
134
  export interface CallBase {
113
135
  callId: string;
114
136
  from: string;
@@ -116,6 +138,8 @@ export interface CallBase {
116
138
  isVideo: boolean;
117
139
  timestamp: number;
118
140
  status?: string;
141
+ /** Extra caller details from the raw call stanza. Absent when WhatsApp did not send them. */
142
+ caller?: CallerInfo;
119
143
  }
120
144
  export interface HistorySyncPayload {
121
145
  syncType: string;