chat-adapter-wwebjs 0.0.0-stage → 0.1.2
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.
- package/CHANGELOG.md +41 -0
- package/LICENSE +21 -0
- package/README.md +203 -2
- package/dist/index.d.ts +493 -0
- package/dist/index.js +1392 -0
- package/package.json +76 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
import { Attachment, FileUpload, AdapterPostableMessage, CardElement, ChatInstance, Message as Message$1, Logger, Author, Adapter, LockScope, ChannelVisibility, WebhookOptions, RawMessage, EmojiValue, FetchOptions, FetchResult, ThreadInfo, ChannelInfo, ListThreadsResult, UserInfo, FormattedContent, BaseFormatConverter, Root } from 'chat';
|
|
2
|
+
import { MessageMedia, Message, Client, ClientOptions, PollVote, Call, GroupNotification } from 'whatsapp-web.js';
|
|
3
|
+
|
|
4
|
+
/** Describe an inbound message's media as a Chat SDK attachment. */
|
|
5
|
+
declare function toAttachments(message: Message, maxBytes?: number): Attachment[];
|
|
6
|
+
/** Download an inbound message's media as raw bytes, refusing media larger than `maxBytes`. */
|
|
7
|
+
declare function download(message: Message, maxBytes?: number): Promise<Buffer>;
|
|
8
|
+
/** Convert every attachment and file on a postable message into WhatsApp media. */
|
|
9
|
+
declare function toMediaList(message: AdapterPostableMessage, maxBytes?: number): Promise<MessageMedia[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Convert a single attachment or file upload into WhatsApp media. An attachment
|
|
12
|
+
* given only by `url` is fetched from the host's own network, so never pass one
|
|
13
|
+
* an end user chose.
|
|
14
|
+
*/
|
|
15
|
+
declare function toMedia(source: Attachment | FileUpload, maxBytes?: number): Promise<MessageMedia>;
|
|
16
|
+
/** WhatsApp renders a caption on every media kind except audio. */
|
|
17
|
+
declare function isCaptionable(media: MessageMedia): boolean;
|
|
18
|
+
declare function isAudio(media: MessageMedia): boolean;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Where the WhatsApp session stands. Only `connected` can send and receive;
|
|
22
|
+
* `logged_out` needs a new pairing, and `closed` follows `disconnect()`.
|
|
23
|
+
*/
|
|
24
|
+
type WWebJSConnection = "closed" | "connected" | "connecting" | "disconnected" | "idle" | "logged_out" | "reconnecting";
|
|
25
|
+
/** Decoded thread ID components for WhatsApp. */
|
|
26
|
+
interface WWebJSThreadId {
|
|
27
|
+
/** WhatsApp chat ID, e.g. `"15551234567@c.us"` or `"1234567890-1234@g.us"`. */
|
|
28
|
+
chatId: string;
|
|
29
|
+
}
|
|
30
|
+
/** Configuration for the whatsapp-web.js adapter. */
|
|
31
|
+
interface WWebJSAdapterConfig {
|
|
32
|
+
/**
|
|
33
|
+
* Adapter identity used by Chat SDK serialization and thread ID prefixes.
|
|
34
|
+
* Set a unique value per account when several run on one `Chat` instance.
|
|
35
|
+
* Must not contain `:`. Defaults to `"wwebjs"`.
|
|
36
|
+
*/
|
|
37
|
+
adapterName?: string;
|
|
38
|
+
/** Layers that change how cards are sent or messages received; see `numberedActions()`. */
|
|
39
|
+
addons?: WWebJSAddon[];
|
|
40
|
+
/**
|
|
41
|
+
* Messages that arrived while the session was down are delivered once it is
|
|
42
|
+
* back, up to this old, in order and each once. Defaults to 1 day; `false`
|
|
43
|
+
* turns it off.
|
|
44
|
+
*/
|
|
45
|
+
catchUpMs?: number | false;
|
|
46
|
+
/**
|
|
47
|
+
* An existing whatsapp-web.js client to drive. When omitted the adapter
|
|
48
|
+
* constructs one from {@link WWebJSAdapterConfig.clientOptions}.
|
|
49
|
+
*/
|
|
50
|
+
client?: Client;
|
|
51
|
+
/**
|
|
52
|
+
* Options for the client the adapter constructs, Puppeteer's included.
|
|
53
|
+
* `puppeteer.args` are added after {@link RECOMMENDED_CHROMIUM_ARGS}, so a
|
|
54
|
+
* flag given here wins. Ignored when `client` is set.
|
|
55
|
+
*/
|
|
56
|
+
clientOptions?: ClientOptions;
|
|
57
|
+
/**
|
|
58
|
+
* How long opening the session may take before it is abandoned — and, with
|
|
59
|
+
* `reconnect`, tried again. whatsapp-web.js itself never gives up. Once a QR
|
|
60
|
+
* or pairing code is shown it waits on a person instead, without limit.
|
|
61
|
+
* Defaults to 2 minutes.
|
|
62
|
+
*/
|
|
63
|
+
connectTimeoutMs?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Close the session on SIGINT, SIGTERM and SIGHUP, then let the signal end
|
|
66
|
+
* the process as it otherwise would — unless the app listens for it, and
|
|
67
|
+
* shuts down itself. Puppeteer alone closes the browser and leaves the
|
|
68
|
+
* process running. Defaults to `true`.
|
|
69
|
+
*/
|
|
70
|
+
handleSignals?: boolean;
|
|
71
|
+
/** Logger instance. Replaced by the Chat SDK logger once initialized. */
|
|
72
|
+
logger?: Logger;
|
|
73
|
+
/**
|
|
74
|
+
* Acknowledge inbound messages automatically, so the sender sees blue ticks
|
|
75
|
+
* as soon as the bot receives them. Defaults to `false`.
|
|
76
|
+
*/
|
|
77
|
+
markSeen?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Called with the 8-character pairing code when
|
|
80
|
+
* {@link WWebJSAdapterConfig.phoneNumber} is set.
|
|
81
|
+
*/
|
|
82
|
+
onPairingCode?: (code: string) => unknown;
|
|
83
|
+
/**
|
|
84
|
+
* Called with the QR string emitted during login. Render it with a library
|
|
85
|
+
* like `qrcode-terminal`.
|
|
86
|
+
*/
|
|
87
|
+
onQR?: (qr: string) => unknown;
|
|
88
|
+
/**
|
|
89
|
+
* Phone number for pairing-code login, in E.164 format without the leading
|
|
90
|
+
* `+`. Shorthand for `clientOptions.pairWithPhoneNumber`.
|
|
91
|
+
*/
|
|
92
|
+
phoneNumber?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Largest inbound media, in bytes, that `fetchData()` downloads. Larger
|
|
95
|
+
* media is refused before it is read into memory. Defaults to 64 MB.
|
|
96
|
+
*/
|
|
97
|
+
maxMediaBytes?: number;
|
|
98
|
+
/**
|
|
99
|
+
* Deliver messages the paired account sent — from the phone or from this
|
|
100
|
+
* adapter — to the Chat SDK, along with its own edits, deletes and
|
|
101
|
+
* reactions. Defaults to `false`.
|
|
102
|
+
*/
|
|
103
|
+
receiveOwnMessages?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Start Chromium with {@link RECOMMENDED_CHROMIUM_ARGS}, which keep it lean
|
|
106
|
+
* and steady in a container. Defaults to `true`.
|
|
107
|
+
*/
|
|
108
|
+
recommendedArgs?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Open the session again when WhatsApp drops it, waiting longer after each
|
|
111
|
+
* failed attempt. A logout is never retried, since it needs a new pairing.
|
|
112
|
+
* Defaults to `true`.
|
|
113
|
+
*/
|
|
114
|
+
reconnect?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* How often a connected session is asked whether WhatsApp still answers.
|
|
117
|
+
* Two failed checks in a row count as a disconnect, which `reconnect` then
|
|
118
|
+
* handles. Catches a session that died without any event. Defaults to 1
|
|
119
|
+
* minute; `false` turns it off.
|
|
120
|
+
*/
|
|
121
|
+
watchdogIntervalMs?: number | false;
|
|
122
|
+
/** Bot display name. Defaults to `"wwebjs-bot"`. */
|
|
123
|
+
userName?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Send audio as a voice note, played inline with a waveform, rather than as
|
|
126
|
+
* a file. Defaults to `true`.
|
|
127
|
+
*/
|
|
128
|
+
voiceNotes?: boolean;
|
|
129
|
+
}
|
|
130
|
+
/** What an addon is handed alongside each card or message. */
|
|
131
|
+
interface WWebJSAddonContext {
|
|
132
|
+
adapter: WWebJSAdapter;
|
|
133
|
+
/** Absent until the Chat SDK has initialized the adapter. */
|
|
134
|
+
chat: ChatInstance | null;
|
|
135
|
+
threadId: string;
|
|
136
|
+
}
|
|
137
|
+
/** A layer over the adapter; every hook is optional. */
|
|
138
|
+
interface WWebJSAddon {
|
|
139
|
+
/** Text for a card in place of its plain fallback; the first addon to answer wins. */
|
|
140
|
+
renderCard?(card: CardElement, context: WWebJSAddonContext): string | undefined;
|
|
141
|
+
/** Called once a card is on WhatsApp, with the id of the message carrying it. */
|
|
142
|
+
cardSent?(card: CardElement, messageId: string, context: WWebJSAddonContext): unknown;
|
|
143
|
+
/** Return `true` to keep an inbound message from reaching the Chat SDK as one. */
|
|
144
|
+
onMessage?(message: Message$1<Message>, context: WWebJSAddonContext): boolean | Promise<boolean>;
|
|
145
|
+
}
|
|
146
|
+
/** Delivery state of a sent message, reported by {@link WWebJSAdapter.onAck}. */
|
|
147
|
+
type WWebJSAckStatus = "delivered" | "error" | "pending" | "played" | "read" | "sent";
|
|
148
|
+
/** A delivery-state change for a message the bot sent. */
|
|
149
|
+
interface WWebJSAck {
|
|
150
|
+
/** Message ID whose delivery state changed. */
|
|
151
|
+
messageId: string;
|
|
152
|
+
/** Raw whatsapp-web.js message. */
|
|
153
|
+
raw: Message;
|
|
154
|
+
/** New delivery state. */
|
|
155
|
+
status: WWebJSAckStatus;
|
|
156
|
+
/** Encoded thread ID the message belongs to. */
|
|
157
|
+
threadId: string;
|
|
158
|
+
}
|
|
159
|
+
/** A participant returned by {@link WWebJSAdapter.fetchGroupParticipants}. */
|
|
160
|
+
interface WWebJSGroupParticipant {
|
|
161
|
+
/** True for both admin and super-admin roles. */
|
|
162
|
+
isAdmin: boolean;
|
|
163
|
+
/** True only for the group creator. */
|
|
164
|
+
isSuperAdmin: boolean;
|
|
165
|
+
/** The participant's chat ID, e.g. `"15551234567@c.us"`. */
|
|
166
|
+
userId: string;
|
|
167
|
+
}
|
|
168
|
+
/** Membership or metadata change in a group. */
|
|
169
|
+
interface WWebJSGroupEvent {
|
|
170
|
+
/** Chat ID of whoever performed the action, when WhatsApp reports one. */
|
|
171
|
+
authorId?: string;
|
|
172
|
+
/** Raw whatsapp-web.js notification. */
|
|
173
|
+
raw: GroupNotification;
|
|
174
|
+
/** Encoded thread ID of the group. */
|
|
175
|
+
threadId: string;
|
|
176
|
+
/** What happened. */
|
|
177
|
+
type: "admin_changed" | "join" | "leave" | "membership_request" | "update";
|
|
178
|
+
/** Chat IDs the action applies to. */
|
|
179
|
+
userIds: string[];
|
|
180
|
+
}
|
|
181
|
+
/** A vote on a poll the bot sent, delivered to {@link WWebJSAdapter.onPollVote}. */
|
|
182
|
+
interface WWebJSPollVote {
|
|
183
|
+
/** Original poll options, in send order. */
|
|
184
|
+
options: string[];
|
|
185
|
+
/** Message ID of the poll being voted on. */
|
|
186
|
+
pollMessageId: string;
|
|
187
|
+
/** Original poll question. */
|
|
188
|
+
question: string;
|
|
189
|
+
/** Raw whatsapp-web.js vote. */
|
|
190
|
+
raw: PollVote;
|
|
191
|
+
/** Options the voter currently has selected. Empty when the vote was cleared. */
|
|
192
|
+
selectedOptions: string[];
|
|
193
|
+
/** Encoded thread ID where the poll lives. */
|
|
194
|
+
threadId: string;
|
|
195
|
+
/** Author info for the voter. */
|
|
196
|
+
voter: Author;
|
|
197
|
+
}
|
|
198
|
+
/** Named arguments for {@link WWebJSAdapter.sendLocation}. */
|
|
199
|
+
interface WWebJSSendLocationArgs {
|
|
200
|
+
/** Street address shown below the place name. */
|
|
201
|
+
address?: string;
|
|
202
|
+
/** Latitude in decimal degrees (WGS 84). */
|
|
203
|
+
latitude: number;
|
|
204
|
+
/** Longitude in decimal degrees (WGS 84). */
|
|
205
|
+
longitude: number;
|
|
206
|
+
/** Place name shown on the pin. */
|
|
207
|
+
name?: string;
|
|
208
|
+
/** Encoded thread ID that should receive the pin. */
|
|
209
|
+
threadId: string;
|
|
210
|
+
/** URL shown within the location message. */
|
|
211
|
+
url?: string;
|
|
212
|
+
}
|
|
213
|
+
/** Named arguments for {@link WWebJSAdapter.sendPoll}. */
|
|
214
|
+
interface WWebJSSendPollArgs {
|
|
215
|
+
/** Let voters pick more than one option. Defaults to `false`. */
|
|
216
|
+
allowMultipleAnswers?: boolean;
|
|
217
|
+
/** Poll options, between 2 and 12. */
|
|
218
|
+
options: string[];
|
|
219
|
+
/** Poll question. */
|
|
220
|
+
question: string;
|
|
221
|
+
/** Encoded thread ID that should receive the poll. */
|
|
222
|
+
threadId: string;
|
|
223
|
+
}
|
|
224
|
+
/** Named arguments for {@link WWebJSAdapter.sendEvent}. */
|
|
225
|
+
interface WWebJSSendEventArgs {
|
|
226
|
+
/** Type of WhatsApp call link to attach. Defaults to `"none"`. */
|
|
227
|
+
callType?: "none" | "video" | "voice";
|
|
228
|
+
/** Event description. */
|
|
229
|
+
description?: string;
|
|
230
|
+
/** When the event ends. */
|
|
231
|
+
endTime?: Date;
|
|
232
|
+
/** Where the event takes place. */
|
|
233
|
+
location?: string;
|
|
234
|
+
/** Event name. */
|
|
235
|
+
name: string;
|
|
236
|
+
/** When the event starts. */
|
|
237
|
+
startTime: Date;
|
|
238
|
+
/** Encoded thread ID that should receive the event. */
|
|
239
|
+
threadId: string;
|
|
240
|
+
}
|
|
241
|
+
/** Handler for delivery-state changes. */
|
|
242
|
+
type WWebJSAckHandler = (ack: WWebJSAck) => unknown;
|
|
243
|
+
/** Handler for incoming calls. */
|
|
244
|
+
type WWebJSCallHandler = (call: Call) => unknown;
|
|
245
|
+
/** Handler for group membership and metadata changes. */
|
|
246
|
+
type WWebJSGroupEventHandler = (event: WWebJSGroupEvent) => unknown;
|
|
247
|
+
/** Handler for poll votes. */
|
|
248
|
+
type WWebJSPollVoteHandler = (vote: WWebJSPollVote) => unknown;
|
|
249
|
+
|
|
250
|
+
/** What a single WhatsApp Web tab can do without, on top of the flags Puppeteer already passes. */
|
|
251
|
+
declare const RECOMMENDED_CHROMIUM_ARGS: string[];
|
|
252
|
+
declare class WWebJSAdapter implements Adapter<WWebJSThreadId, Message> {
|
|
253
|
+
readonly name: string;
|
|
254
|
+
readonly lockScope: LockScope;
|
|
255
|
+
/** The underlying whatsapp-web.js client, for anything this adapter does not wrap. */
|
|
256
|
+
readonly client: Client;
|
|
257
|
+
userName: string;
|
|
258
|
+
private readonly _config;
|
|
259
|
+
private readonly _converter;
|
|
260
|
+
private readonly _ackHandlers;
|
|
261
|
+
private readonly _callHandlers;
|
|
262
|
+
private readonly _groupHandlers;
|
|
263
|
+
private readonly _pollVoteHandlers;
|
|
264
|
+
private _chat;
|
|
265
|
+
private _logger;
|
|
266
|
+
private _connection;
|
|
267
|
+
private _botLid?;
|
|
268
|
+
private _closed;
|
|
269
|
+
private _retry?;
|
|
270
|
+
private _initialized;
|
|
271
|
+
private _state;
|
|
272
|
+
private _watchdog?;
|
|
273
|
+
private _strikes;
|
|
274
|
+
private _unsignal?;
|
|
275
|
+
private _seen?;
|
|
276
|
+
private _saving;
|
|
277
|
+
constructor(config?: WWebJSAdapterConfig);
|
|
278
|
+
/** Where the session stands; a health check reads `connection === "connected"`. */
|
|
279
|
+
get connection(): WWebJSConnection;
|
|
280
|
+
get botUserId(): string | undefined;
|
|
281
|
+
initialize(chat: ChatInstance): Promise<void>;
|
|
282
|
+
/**
|
|
283
|
+
* Launch the browser session and wait until WhatsApp is ready.
|
|
284
|
+
*
|
|
285
|
+
* Call this after registering handlers on your `Chat` instance, so no
|
|
286
|
+
* message arrives before there is something to receive it. Repeated calls
|
|
287
|
+
* share one connection attempt.
|
|
288
|
+
*/
|
|
289
|
+
connect(): Promise<void>;
|
|
290
|
+
/** Close the browser session. */
|
|
291
|
+
disconnect(): Promise<void>;
|
|
292
|
+
encodeThreadId(platformData: WWebJSThreadId): string;
|
|
293
|
+
decodeThreadId(threadId: string): WWebJSThreadId;
|
|
294
|
+
channelIdFromThreadId(threadId: string): string;
|
|
295
|
+
isDM(threadId: string): boolean;
|
|
296
|
+
getChannelVisibility(threadId: string): ChannelVisibility;
|
|
297
|
+
/**
|
|
298
|
+
* whatsapp-web.js drives a browser session rather than inbound HTTP, so this
|
|
299
|
+
* always answers 501. Call {@link WWebJSAdapter.connect} to receive messages.
|
|
300
|
+
*/
|
|
301
|
+
handleWebhook(_request: Request, _options?: WebhookOptions): Promise<Response>;
|
|
302
|
+
parseMessage(raw: Message): Message$1<Message>;
|
|
303
|
+
postMessage(threadId: string, message: AdapterPostableMessage): Promise<RawMessage<Message>>;
|
|
304
|
+
postChannelMessage(channelId: string, message: AdapterPostableMessage): Promise<RawMessage<Message>>;
|
|
305
|
+
reply(threadId: string, messageId: string, message: AdapterPostableMessage): Promise<RawMessage<Message>>;
|
|
306
|
+
editMessage(threadId: string, messageId: string, message: AdapterPostableMessage): Promise<RawMessage<Message>>;
|
|
307
|
+
deleteMessage(_threadId: string, messageId: string): Promise<void>;
|
|
308
|
+
addReaction(_threadId: string, messageId: string, emoji: EmojiValue | string): Promise<void>;
|
|
309
|
+
removeReaction(_threadId: string, messageId: string, _emoji: EmojiValue | string): Promise<void>;
|
|
310
|
+
fetchMessages(threadId: string, options?: FetchOptions): Promise<FetchResult<Message>>;
|
|
311
|
+
fetchChannelMessages(channelId: string, options?: FetchOptions): Promise<FetchResult<Message>>;
|
|
312
|
+
fetchMessage(_threadId: string, messageId: string): Promise<Message$1<Message> | null>;
|
|
313
|
+
fetchThread(threadId: string): Promise<ThreadInfo>;
|
|
314
|
+
fetchChannelInfo(channelId: string): Promise<ChannelInfo>;
|
|
315
|
+
/** WhatsApp conversations are flat, so a channel never contains sub-threads. */
|
|
316
|
+
listThreads(): Promise<ListThreadsResult<Message>>;
|
|
317
|
+
getUser(userId: string): Promise<UserInfo | null>;
|
|
318
|
+
/** A number, or its `@c.us` id, resolves to the chat WhatsApp uses for it — often a LID — so a DM is one thread whoever opened it. */
|
|
319
|
+
openDM(userId: string): Promise<string>;
|
|
320
|
+
markAsRead(threadId: string): Promise<void>;
|
|
321
|
+
startTyping(threadId: string, status?: string): Promise<void>;
|
|
322
|
+
endTyping(threadId: string): Promise<void>;
|
|
323
|
+
renderFormatted(content: FormattedContent): string;
|
|
324
|
+
rehydrateAttachment(attachment: Attachment): Attachment;
|
|
325
|
+
/** Send a map pin. */
|
|
326
|
+
sendLocation(args: WWebJSSendLocationArgs): Promise<RawMessage<Message>>;
|
|
327
|
+
/** Send a native WhatsApp poll. Between 2 and 12 options. */
|
|
328
|
+
sendPoll(args: WWebJSSendPollArgs): Promise<RawMessage<Message>>;
|
|
329
|
+
/** Send a scheduled event card. */
|
|
330
|
+
sendEvent(args: WWebJSSendEventArgs): Promise<RawMessage<Message>>;
|
|
331
|
+
/** Send an image as a sticker. */
|
|
332
|
+
sendSticker(threadId: string, source: Attachment | Parameters<typeof toMedia>[0]): Promise<RawMessage<Message>>;
|
|
333
|
+
/** Forward an existing message into another thread. */
|
|
334
|
+
forwardMessage(messageId: string, targetThreadId: string): Promise<void>;
|
|
335
|
+
/** Pin a message for the given number of seconds. */
|
|
336
|
+
pinMessage(messageId: string, seconds: number): Promise<boolean>;
|
|
337
|
+
/** Unpin a message. */
|
|
338
|
+
unpinMessage(messageId: string): Promise<boolean>;
|
|
339
|
+
/** Star a message. */
|
|
340
|
+
starMessage(messageId: string): Promise<void>;
|
|
341
|
+
/** Unstar a message. */
|
|
342
|
+
unstarMessage(messageId: string): Promise<void>;
|
|
343
|
+
/** Every pinned message in a thread. */
|
|
344
|
+
fetchPinnedMessages(threadId: string): Promise<Message$1<Message>[]>;
|
|
345
|
+
/** Search messages across every chat, or within one thread. */
|
|
346
|
+
searchMessages(query: string, options?: {
|
|
347
|
+
limit?: number;
|
|
348
|
+
page?: number;
|
|
349
|
+
threadId?: string;
|
|
350
|
+
}): Promise<Message$1<Message>[]>;
|
|
351
|
+
/** Participants of a group thread, with their admin status. */
|
|
352
|
+
fetchGroupParticipants(threadId: string): Promise<WWebJSGroupParticipant[]>;
|
|
353
|
+
/** The profile picture of a contact or group, when privacy settings allow it. */
|
|
354
|
+
getProfilePicUrl(userId: string): Promise<string | undefined>;
|
|
355
|
+
/** Show the bot as online or offline. */
|
|
356
|
+
setPresence(presence: "available" | "unavailable"): Promise<void>;
|
|
357
|
+
/** Mark a thread unread. */
|
|
358
|
+
markAsUnread(threadId: string): Promise<void>;
|
|
359
|
+
/** Mute a thread until the given date, or forever when omitted. */
|
|
360
|
+
muteThread(threadId: string, until?: Date): Promise<void>;
|
|
361
|
+
/** Unmute a thread. */
|
|
362
|
+
unmuteThread(threadId: string): Promise<void>;
|
|
363
|
+
/** Archive a thread. */
|
|
364
|
+
archiveThread(threadId: string): Promise<void>;
|
|
365
|
+
/** Move a thread out of the archive. */
|
|
366
|
+
unarchiveThread(threadId: string): Promise<void>;
|
|
367
|
+
/** Pin a thread to the top of the chat list. */
|
|
368
|
+
pinThread(threadId: string): Promise<boolean>;
|
|
369
|
+
/** Unpin a thread. */
|
|
370
|
+
unpinThread(threadId: string): Promise<boolean>;
|
|
371
|
+
/**
|
|
372
|
+
* Subscribe to votes on polls sent from this account, optionally narrowed to
|
|
373
|
+
* specific poll message IDs.
|
|
374
|
+
*/
|
|
375
|
+
onPollVote(handler: WWebJSPollVoteHandler): void;
|
|
376
|
+
onPollVote(pollMessageIds: string | string[], handler: WWebJSPollVoteHandler): void;
|
|
377
|
+
/** Subscribe to incoming calls. Use `call.reject()` to decline. */
|
|
378
|
+
onCall(handler: WWebJSCallHandler): void;
|
|
379
|
+
/** Subscribe to delivery-state changes for messages this account sent. */
|
|
380
|
+
onAck(handler: WWebJSAckHandler): void;
|
|
381
|
+
/** Subscribe to group membership and metadata changes. */
|
|
382
|
+
onGroupEvent(handler: WWebJSGroupEventHandler): void;
|
|
383
|
+
private _clientOptions;
|
|
384
|
+
private _connect;
|
|
385
|
+
private _open;
|
|
386
|
+
private _listen;
|
|
387
|
+
private _onMessage;
|
|
388
|
+
private _claimed;
|
|
389
|
+
private _addons;
|
|
390
|
+
private _context;
|
|
391
|
+
private _seenKey;
|
|
392
|
+
/** Writes run in turn, so an older position never lands after a newer one. */
|
|
393
|
+
private _save;
|
|
394
|
+
private _remember;
|
|
395
|
+
/** WhatsApp Web loads what arrived while the session was down without announcing every message. */
|
|
396
|
+
private _catchUp;
|
|
397
|
+
private _onEdit;
|
|
398
|
+
private _onRevoke;
|
|
399
|
+
private _onReaction;
|
|
400
|
+
private _onAck;
|
|
401
|
+
private _onGroup;
|
|
402
|
+
private _onVote;
|
|
403
|
+
private _dispatch;
|
|
404
|
+
private _parse;
|
|
405
|
+
private _author;
|
|
406
|
+
private _indicator;
|
|
407
|
+
/** Groups address the bot by its LID or its phone number, whichever they know it by. */
|
|
408
|
+
private _mentionsBot;
|
|
409
|
+
private _botUsers;
|
|
410
|
+
private _mentioned;
|
|
411
|
+
/** WhatsApp writes a mention as `@` and the number or LID; readers expect the name. */
|
|
412
|
+
private _named;
|
|
413
|
+
private _learnLid;
|
|
414
|
+
/** Listeners run unawaited, so a rejection here would end the process. */
|
|
415
|
+
private _guard;
|
|
416
|
+
private _isOwn;
|
|
417
|
+
private _onDisconnected;
|
|
418
|
+
private _reconnect;
|
|
419
|
+
private _watch;
|
|
420
|
+
/** Revives a session that died without an event, or a first connection that failed. */
|
|
421
|
+
private _check;
|
|
422
|
+
private _render;
|
|
423
|
+
/** The card is already on WhatsApp, so an addon failing here must not fail the send. */
|
|
424
|
+
private _cardSent;
|
|
425
|
+
private _send;
|
|
426
|
+
private _sendContent;
|
|
427
|
+
private _raw;
|
|
428
|
+
private _page;
|
|
429
|
+
private _findChat;
|
|
430
|
+
private _requireChat;
|
|
431
|
+
private _requireMessage;
|
|
432
|
+
}
|
|
433
|
+
/** Create a WhatsApp adapter backed by whatsapp-web.js. */
|
|
434
|
+
declare function createWWebJSAdapter(config?: WWebJSAdapterConfig): WWebJSAdapter;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Converts between WhatsApp's markup and the Chat SDK's mdast AST.
|
|
438
|
+
*
|
|
439
|
+
* WhatsApp understands `*bold*`, `_italic_`, `~strikethrough~`, `` `code` ``,
|
|
440
|
+
* ` ```blocks``` `, `> quotes` and simple lists. It has no link syntax, so
|
|
441
|
+
* links render as `text (url)`, and no tables, so tables render as ASCII
|
|
442
|
+
* inside a code block.
|
|
443
|
+
*/
|
|
444
|
+
declare class WWebJSFormatConverter extends BaseFormatConverter {
|
|
445
|
+
/** Text from anyone: past `MAX_MARKDOWN_LENGTH`, or when the parser gives up, it stays plain rather than stalling or throwing. */
|
|
446
|
+
toAst(platformText: string): Root;
|
|
447
|
+
fromAst(ast: Root): string;
|
|
448
|
+
private toWhatsApp;
|
|
449
|
+
private join;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** Narrow an unknown adapter to {@link WWebJSAdapter}. */
|
|
453
|
+
declare function isWWebJSAdapter(value: unknown): value is WWebJSAdapter;
|
|
454
|
+
/**
|
|
455
|
+
* Require that a Chat SDK context belongs to a {@link WWebJSAdapter}.
|
|
456
|
+
*
|
|
457
|
+
* Accepts the adapter itself or anything carrying one, such as a `Thread`,
|
|
458
|
+
* `Channel` or `SentMessage`.
|
|
459
|
+
*/
|
|
460
|
+
declare function requireWWebJSAdapter(value: unknown): WWebJSAdapter;
|
|
461
|
+
|
|
462
|
+
/** True for group chat IDs, e.g. `"1234567890-1234567890@g.us"`. */
|
|
463
|
+
declare function isGroupId(chatId: string): boolean;
|
|
464
|
+
/** True for channel (newsletter) IDs, e.g. `"1234567890@newsletter"`. */
|
|
465
|
+
declare function isNewsletterId(chatId: string): boolean;
|
|
466
|
+
/** True for one-to-one chat IDs, e.g. `"15551234567@c.us"`. */
|
|
467
|
+
declare function isUserId(chatId: string): boolean;
|
|
468
|
+
/** Normalize a bare phone number into a WhatsApp chat ID. */
|
|
469
|
+
declare function toChatId(value: string): string;
|
|
470
|
+
/** The user part of a chat ID, e.g. `"15551234567@c.us"` → `"15551234567"`. */
|
|
471
|
+
declare function toUser(chatId: string): string;
|
|
472
|
+
/**
|
|
473
|
+
* Rewrite Chat SDK mention tokens into WhatsApp's `@number` form and collect
|
|
474
|
+
* the chat IDs WhatsApp needs alongside the body to render them as mentions.
|
|
475
|
+
*/
|
|
476
|
+
declare function extractMentions(text: string): {
|
|
477
|
+
mentions: string[];
|
|
478
|
+
text: string;
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
interface NumberedActionsOptions {
|
|
482
|
+
/** Also deliver the reply that picked an option as a message. Defaults to `false`. */
|
|
483
|
+
keepMessage?: boolean;
|
|
484
|
+
/** How long a card's options answer to their number or label. Defaults to 1 day. */
|
|
485
|
+
ttlMs?: number;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* WhatsApp Web cannot send buttons, so a card's buttons and select options are
|
|
489
|
+
* listed by number, and a reply with one — or its label — reaches `onAction`.
|
|
490
|
+
*/
|
|
491
|
+
declare function numberedActions(options?: NumberedActionsOptions): WWebJSAddon;
|
|
492
|
+
|
|
493
|
+
export { type NumberedActionsOptions, RECOMMENDED_CHROMIUM_ARGS, type WWebJSAck, type WWebJSAckHandler, type WWebJSAckStatus, WWebJSAdapter, type WWebJSAdapterConfig, type WWebJSAddon, type WWebJSAddonContext, type WWebJSCallHandler, type WWebJSConnection, WWebJSFormatConverter, type WWebJSGroupEvent, type WWebJSGroupEventHandler, type WWebJSGroupParticipant, type WWebJSPollVote, type WWebJSPollVoteHandler, type WWebJSSendEventArgs, type WWebJSSendLocationArgs, type WWebJSSendPollArgs, type WWebJSThreadId, createWWebJSAdapter, download, extractMentions, isAudio, isCaptionable, isGroupId, isNewsletterId, isUserId, isWWebJSAdapter, numberedActions, requireWWebJSAdapter, toAttachments, toChatId, toMedia, toMediaList, toUser };
|