zaileys 4.8.6 → 4.8.8

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,9 +57,20 @@ 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;
68
+ /**
69
+ * Uploads the status media and returns it at the TOP level, not inside the envelope. baileys derives
70
+ * the stanza's `mediatype` attribute from the raw message before `patchMessageBeforeSending` runs, and
71
+ * the server drops a media status that lacks it — so the wrapping happens later, in that hook.
72
+ */
73
+ private buildStatusMedia;
61
74
  /** Relay skips baileys' contextInfo pass, so mentions and mentionAll are applied to the unwrapped node here. */
62
75
  private applyRelayMentions;
63
76
  private sendRelay;
@@ -4,6 +4,14 @@ export declare const RELAY_CONTENT_KEY = "__zaileysRelayMessage";
4
4
  export declare const RELAY_MEDIA_KEY = "__zaileysHeaderMedia";
5
5
  /** Marks relay content that may only target a group jid; the value is the method label used in the error. */
6
6
  export declare const RELAY_REQUIRE_GROUP_KEY = "__zaileysRequireGroupJid";
7
+ /** Carries a downloaded media buffer that `sendRelay` re-uploads and injects into the status envelope. */
8
+ export declare const RELAY_STATUS_MEDIA_KEY = "__zaileysStatusMedia";
9
+ export type StatusMedia = {
10
+ kind: 'image' | 'video' | 'audio';
11
+ buffer: Buffer;
12
+ caption?: string;
13
+ ptt?: boolean;
14
+ };
7
15
  export type HeaderMedia = {
8
16
  kind: 'image' | 'video';
9
17
  src: MediaSource;
@@ -8,5 +8,8 @@ export declare const parseStatusArgb: (value: string | number) => number;
8
8
  /** Resolves a named font to its WhatsApp `FontType`; raw integers pass through for forward compatibility. */
9
9
  export declare const resolveStatusFont: (value: GroupStatusFont | number) => number;
10
10
  export declare const buildGroupStatusContent: (text: string, opts?: GroupStatusOptions) => AnyMessageContent;
11
- /** Reposts an existing text message as a group status. Media sources are rejected — see `MEDIA_KEYS`. */
12
- export declare const buildGroupStatusRepost: (source: GroupStatusSource, opts?: GroupStatusRepostOptions) => AnyMessageContent;
11
+ /**
12
+ * Reposts an existing message as a group status. Media cannot be carried by copying pointers — the
13
+ * bytes are downloaded here and re-uploaded at dispatch, because a status needs its own upload.
14
+ */
15
+ export declare const buildGroupStatusRepost: (source: GroupStatusSource, opts?: GroupStatusRepostOptions) => Promise<AnyMessageContent>;
@@ -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;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Marks a media message to be wrapped into a group status envelope at send time.
3
+ *
4
+ * baileys reads `getMediaType()` from the raw message to set the stanza's `mediatype` attribute, and
5
+ * only calls `patchMessageBeforeSending` afterwards. A media message nested inside
6
+ * `groupStatusMessageV2` is therefore invisible to that check and the server drops it. Relaying the
7
+ * media at the top level and wrapping it in the patch hook gets both the attribute and the envelope.
8
+ */
9
+ export declare const markAsGroupStatus: (message: object) => void;
10
+ /** Wraps a marked message into the group status envelope; returns it untouched otherwise. */
11
+ export declare const applyGroupStatusWrap: <T extends object>(message: T) => T;
@@ -163,10 +163,19 @@ export type GroupStatusOptions = {
163
163
  /** Font face. Accepts a named font or a raw FontType integer for forward compatibility. */
164
164
  font?: GroupStatusFont | number;
165
165
  };
166
- /** A message to repost as a group status a `MessageContext` or a raw `WAMessage`. */
166
+ /** Media posted directly as a group status, without an existing message to repost. */
167
+ export type GroupStatusMedia = {
168
+ image?: MediaSource;
169
+ video?: MediaSource;
170
+ audio?: MediaSource;
171
+ caption?: string;
172
+ /** Send an audio status as a voice note. */
173
+ ptt?: boolean;
174
+ };
175
+ /** What a group status can be built from: a `MessageContext`, a raw `WAMessage`, or fresh media. */
167
176
  export type GroupStatusSource = WAMessage | {
168
177
  message: () => WAMessage;
169
- };
178
+ } | GroupStatusMedia;
170
179
  export type GroupStatusRepostOptions = {
171
180
  /** Replaces the original caption. Ignored for voice notes, which have none. */
172
181
  caption?: string;
@@ -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;
@@ -142,6 +150,8 @@ export declare class Client extends TypedEventEmitter<ClientEventMap> {
142
150
  pin(key: WAMessageKey, opts?: PinOptions): Promise<WAMessageKey>;
143
151
  unpin(key: WAMessageKey): Promise<WAMessageKey>;
144
152
  setDisappearing(to: string, seconds: number): Promise<void>;
153
+ /** Group status media must be wrapped after baileys computes the stanza's mediatype; see status-wrap. */
154
+ private readonly patchOutgoing;
145
155
  private resolveRecipient;
146
156
  private requireSocket;
147
157
  /** Messaging seam: baileys socket or the cloud transport, whichever the provider dictates. */
@@ -154,10 +164,23 @@ export declare class Client extends TypedEventEmitter<ClientEventMap> {
154
164
  private handleOpen;
155
165
  private resolveMessageForResend;
156
166
  private lidMapping;
167
+ /** One round trip for many jids, so resolving a whole participant list is not N lookups. */
168
+ private lidMapBulk;
157
169
  /** Resolve a `@lid` JID to its phone-number JID (uses WhatsApp's LID mapping; may hit the network). */
158
170
  lidToPn(lid: string): Promise<string | null>;
159
171
  /** Resolve a phone-number JID to its `@lid` JID (uses WhatsApp's LID mapping; may hit the network). */
160
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>;
161
184
  /**
162
185
  * Download media bytes for a message stored in the message store (by key).
163
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,16 @@ export interface MediaAttachment {
19
19
  fileName: string | null;
20
20
  fileSize: number | null;
21
21
  ptt: boolean;
22
+ /** Playback length in seconds, for audio and video. */
23
+ duration: number | null;
24
+ width: number | null;
25
+ height: number | null;
26
+ /** Page count, for documents. */
27
+ pages: number | null;
28
+ /** `true` for an animated sticker or a GIF-playback video. */
29
+ isAnimated: boolean;
30
+ /** Inline JPEG preview, when WhatsApp sent one. Lets you show a thumbnail without downloading. */
31
+ thumbnail: Buffer | null;
22
32
  buffer(): Promise<Buffer>;
23
33
  stream(): Promise<Readable>;
24
34
  }
@@ -147,6 +157,25 @@ export interface TemplateMedia {
147
157
  buttons: MessageButton[];
148
158
  }
149
159
  export type ContextMedia = MediaAttachment | PollMedia | ContactMedia | LocationMedia | EventMedia | AlbumMedia | GroupInviteMedia | ProductMedia | OrderMedia | PaymentMedia | LinkPreviewMedia | ButtonsMedia | ListMedia | InteractiveMedia | TemplateMedia;
160
+ /** Attribution for a chat that started from a Meta ad (Click-to-WhatsApp). */
161
+ export interface AdAttribution {
162
+ /** The click id to join against Meta Ads reporting. */
163
+ clickId?: string;
164
+ sourceId?: string;
165
+ sourceUrl?: string;
166
+ /** Which Meta surface the ad ran on, e.g. `facebook`, `instagram`. */
167
+ sourceApp?: string;
168
+ sourceType?: string;
169
+ title?: string;
170
+ body?: string;
171
+ thumbnailUrl?: string;
172
+ /** Campaign reference you set on the ad. */
173
+ ref?: string;
174
+ }
175
+ export interface BusinessInfo {
176
+ /** WhatsApp-verified business name. Unlike `senderName` this cannot be set by the sender. */
177
+ verifiedName: string;
178
+ }
150
179
  export interface MessageContext {
151
180
  uniqueId: string;
152
181
  staticId: string;
@@ -158,6 +187,8 @@ export interface MessageContext {
158
187
  senderId: string;
159
188
  senderLid: string | null;
160
189
  senderName: string | null;
190
+ /** WhatsApp username (the `@handle`), without the `@`. Only sent for accounts that set one. */
191
+ senderUsername: string | null;
161
192
  senderDevice: SenderDevice;
162
193
  timestamp: number;
163
194
  text: string;
@@ -170,6 +201,20 @@ export interface MessageContext {
170
201
  isViewOnce: boolean;
171
202
  isEphemeral: boolean;
172
203
  isForwarded: boolean;
204
+ /** `true` for a backlog message replayed after a reconnect. Skip these to avoid answering twice. */
205
+ isOffline: boolean;
206
+ /** How many hops this message has been forwarded. `>= 5` is WhatsApp's "forwarded many times". */
207
+ forwardCount: number;
208
+ /** The chat's disappearing timer in seconds, or `null` when messages are kept. */
209
+ ephemeralDuration: number | null;
210
+ /** Whether WhatsApp addressed this message by phone number or by LID. */
211
+ addressingMode: 'pn' | 'lid';
212
+ /** JIDs of groups tagged in the message (community `@group` mentions). */
213
+ mentionedGroups: string[];
214
+ /** Present only on the first message of a chat opened from a Meta ad. */
215
+ ad?: AdAttribution;
216
+ /** Present only when the sender is a verified WhatsApp Business account. */
217
+ business?: BusinessInfo;
173
218
  isQuestion: boolean;
174
219
  isPrefix: boolean;
175
220
  isTagMe: boolean;
@@ -217,6 +262,13 @@ export interface BuildContextInput {
217
262
  isForwarded: boolean;
218
263
  isBroadcast: boolean;
219
264
  isNewsletter: boolean;
265
+ isOffline?: boolean;
266
+ forwardCount?: number;
267
+ ephemeralDuration?: number | null;
268
+ addressingMode?: 'pn' | 'lid';
269
+ mentionedGroups?: string[];
270
+ ad?: AdAttribution;
271
+ business?: BusinessInfo;
220
272
  prefixes: string[];
221
273
  citationConfig?: CitationConfig;
222
274
  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
+ isOffline?: 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;