@open-wa/wa-automate 4.23.6 → 4.23.10
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/README.md
CHANGED
@@ -36,7 +36,7 @@
|
|
36
36
|
Use this command to install the library for the first time and to keep the library up to date.
|
37
37
|
|
38
38
|
```bash
|
39
|
-
> npm i --save @open-wa/wa-automate@latest
|
39
|
+
> npm i --save @open-wa/wa-automate@latest --multi-device
|
40
40
|
```
|
41
41
|
|
42
42
|
## Usage
|
@@ -65,6 +65,7 @@ const wa = require('@open-wa/wa-automate');
|
|
65
65
|
|
66
66
|
wa.create({
|
67
67
|
sessionId: "COVID_HELPER",
|
68
|
+
multiDevice: true, //required to enable multiDevice support
|
68
69
|
authTimeout: 60, //wait only 60 seconds to get a connection with the host account device
|
69
70
|
blockCrashLogs: true,
|
70
71
|
disableSpins: true,
|
@@ -97,6 +98,10 @@ Want to convert your WA account to an API instantly? You can now with the CLI. F
|
|
97
98
|
> npx @open-wa/wa-automate --help
|
98
99
|
```
|
99
100
|
|
101
|
+
## Multi Device Support
|
102
|
+
|
103
|
+
We're currently in a weird transitionary period where some people are being forced to adopt Multi Device (MD). Once the transition is complete, the library default will be to turn on MD support. For now, you have to set it yourself explicitly either by using the `--multi-device` flag (with the [CLI](#CLI)) or setting `multiDevice: true` in your config (with your custom code)
|
104
|
+
|
100
105
|
### Latest Changes
|
101
106
|
|
102
107
|
With the constant updates from WA. It is advisable to always use the latest version of `@open-wa/wa-automate`.
|
package/dist/api/Client.d.ts
CHANGED
@@ -158,7 +158,7 @@ export declare class Client {
|
|
158
158
|
* @param fn callback
|
159
159
|
* @fires [[Message]]
|
160
160
|
*/
|
161
|
-
onButton(fn: (
|
161
|
+
onButton(fn: (message: Message) => void): Promise<Listener | boolean>;
|
162
162
|
/**
|
163
163
|
* Listens to battery changes
|
164
164
|
*
|
@@ -773,7 +773,7 @@ export declare class Client {
|
|
773
773
|
* @param messages this can be any mixture of message ids or message objects
|
774
774
|
* @param skipMyMessages This indicates whether or not to skip your own messages from the array
|
775
775
|
*/
|
776
|
-
forwardMessages(to: ChatId, messages: MessageId | MessageId[], skipMyMessages: boolean): Promise<boolean |
|
776
|
+
forwardMessages(to: ChatId, messages: MessageId | MessageId[], skipMyMessages: boolean): Promise<boolean | MessageId[]>;
|
777
777
|
/**
|
778
778
|
* Ghost forwarding is like a normal forward but as if it were sent from the host phone [i.e it doesn't show up as forwarded.]
|
779
779
|
* Any potential abuse of this method will see it become paywalled.
|
@@ -15,6 +15,10 @@ export interface Message {
|
|
15
15
|
* The body of the message. If the message type is `chat` , `body` will be the text of the chat. If the message type is some sort of media, then this body will be the thumbnail of the media.
|
16
16
|
*/
|
17
17
|
body: string;
|
18
|
+
/**
|
19
|
+
* a convenient way to get the main text content from a message.
|
20
|
+
*/
|
21
|
+
text: string;
|
18
22
|
/**
|
19
23
|
* The type of the message, see [[MessageTypes]]
|
20
24
|
*/
|
package/dist/cli/server.js
CHANGED
@@ -235,12 +235,13 @@ const setupTwilioCompatibleWebhook = (cliConfig, client) => {
|
|
235
235
|
exports.setupTwilioCompatibleWebhook = setupTwilioCompatibleWebhook;
|
236
236
|
const setupBotPressHandler = (cliConfig, client) => {
|
237
237
|
const u = cliConfig.botPressUrl;
|
238
|
-
const sendBotPressMessage = (text, chatId) => __awaiter(void 0, void 0, void 0, function* () {
|
238
|
+
const sendBotPressMessage = (text, chatId, message) => __awaiter(void 0, void 0, void 0, function* () {
|
239
239
|
const url = `${u.split("/").slice(0, u.split("/").findIndex(x => x == "converse")).join("/")}/converse/${chatId.replace("@c.us", "").replace("@g.us", "")}`;
|
240
240
|
try {
|
241
241
|
const { data } = yield axios_1.default.post(url, {
|
242
242
|
"type": "text",
|
243
|
-
text
|
243
|
+
text,
|
244
|
+
metadata: message
|
244
245
|
});
|
245
246
|
const { responses } = data;
|
246
247
|
return yield Promise.all(responses.filter(({ type }) => type != "typing").map((response) => {
|
@@ -298,10 +299,10 @@ const setupBotPressHandler = (cliConfig, client) => {
|
|
298
299
|
text = message.cloudUrl;
|
299
300
|
break;
|
300
301
|
default:
|
301
|
-
text = message.body;
|
302
|
+
text = message.body || "__UNHANDLED__";
|
302
303
|
break;
|
303
304
|
}
|
304
|
-
yield sendBotPressMessage(text, message.from);
|
305
|
+
yield sendBotPressMessage(text, message.from, message);
|
305
306
|
}));
|
306
307
|
};
|
307
308
|
exports.setupBotPressHandler = setupBotPressHandler;
|
@@ -117,7 +117,7 @@ function initPage(sessionId, config, customUserAgent, spinner) {
|
|
117
117
|
}
|
118
118
|
spinner === null || spinner === void 0 ? void 0 : spinner.info('Loading session data');
|
119
119
|
let sessionjson = getSessionDataFromFile(sessionId, config, spinner);
|
120
|
-
if (!sessionjson && config.sessionDataBucketAuth) {
|
120
|
+
if (!sessionjson && sessionjson !== "" && config.sessionDataBucketAuth) {
|
121
121
|
try {
|
122
122
|
spinner === null || spinner === void 0 ? void 0 : spinner.info('Unable to find session data file locally, attempting to find session data in cloud storage..');
|
123
123
|
sessionjson = JSON.parse(Buffer.from(yield pico_s3_1.getTextFile(Object.assign(Object.assign({ directory: '_sessionData' }, JSON.parse(Buffer.from(config.sessionDataBucketAuth, 'base64').toString('ascii'))), { filename: `${config.sessionId || 'session'}.data.json` })), 'base64').toString('ascii'));
|
@@ -369,7 +369,9 @@ function create(config = {}) {
|
|
369
369
|
//@ts-ignore
|
370
370
|
const metrics = yield waPage.evaluate(({ config }) => WAPI.launchMetrics(config), { config });
|
371
371
|
const purgedMessage = (metrics === null || metrics === void 0 ? void 0 : metrics.purged) ? Object.entries(metrics.purged).filter(([, e]) => e > 0).map(([k, e]) => `${e} ${k}`).join(" and ") : "";
|
372
|
-
|
372
|
+
if (metrics.isMd && !(config === null || config === void 0 ? void 0 : config.multiDevice))
|
373
|
+
spinner.info("!!!Please set multiDevice: true in the config or use the --mutli-Device flag!!!");
|
374
|
+
spinner.succeed(`Client loaded for ${metrics.isBiz ? "business" : "normal"} account ${metrics.isMd && "[MD] " || ''}with ${metrics.contacts} contacts, ${metrics.chats} chats & ${metrics.messages} messages ${purgedMessage ? `+ purged ${purgedMessage} ` : ``}in ${LAUNCH_TIME_MS / 1000}s`);
|
373
375
|
if ((config === null || config === void 0 ? void 0 : config.deleteSessionDataOnLogout) || (config === null || config === void 0 ? void 0 : config.killClientOnLogout))
|
374
376
|
config.eventMode = true;
|
375
377
|
const client = new Client_1.Client(waPage, config, debugInfo);
|
@@ -377,7 +379,9 @@ function create(config = {}) {
|
|
377
379
|
if ((config === null || config === void 0 ? void 0 : config.licenseKey) || me._serialized !== earlyWid) {
|
378
380
|
yield getAndInjectLicense(waPage, config, me, debugInfo, spinner, me._serialized !== earlyWid ? false : yield licensePromise);
|
379
381
|
}
|
382
|
+
spinner.info("Finalizing web session...");
|
380
383
|
yield init_patch_1.injectInitPatch(waPage);
|
384
|
+
spinner.info("Finalizing client...");
|
381
385
|
yield client.loaded();
|
382
386
|
if (config.ensureHeadfulIntegrity && !attemptingReauth) {
|
383
387
|
spinner.info("QR scanned for the first time. Refreshing...");
|
package/package.json
CHANGED