@jsm-mit/whatsapp-package 0.0.2 → 0.0.3
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"whatsapp.service.d.ts","sourceRoot":"","sources":["../src/whatsapp.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAW,MAAM,MAAM,CAAC;AAE3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAItD,qBAAa,eAAe;IAWpB,OAAO,CAAC,MAAM;IATlB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,QAAQ,CAAM;IACtB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAwB;IAEvD,IAAW,SAAS,IAAI,UAAU,CAAC,GAAG,EAAE,CAAC,CAExC;gBAGW,MAAM,EAAE,MAAM;IAI1B,OAAO,CAAC,YAAY;IAcb,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"whatsapp.service.d.ts","sourceRoot":"","sources":["../src/whatsapp.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAW,MAAM,MAAM,CAAC;AAE3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAItD,qBAAa,eAAe;IAWpB,OAAO,CAAC,MAAM;IATlB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,QAAQ,CAAM;IACtB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAwB;IAEvD,IAAW,SAAS,IAAI,UAAU,CAAC,GAAG,EAAE,CAAC,CAExC;gBAGW,MAAM,EAAE,MAAM;IAI1B,OAAO,CAAC,YAAY;IAcb,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA2FrB,oBAAoB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAc7D,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAQvE"}
|
package/dist/whatsapp.service.js
CHANGED
|
@@ -2,7 +2,7 @@ import pkg from 'whatsapp-web.js';
|
|
|
2
2
|
import qrcode from 'qrcode-terminal';
|
|
3
3
|
import { Observable, Subject } from 'rxjs';
|
|
4
4
|
import { toJson, polandTimeOptions, serverTimeOptions } from '@jsm-mit/utils-package';
|
|
5
|
-
const { Client
|
|
5
|
+
const { Client, LocalAuth } = pkg;
|
|
6
6
|
export class WhatsAppService {
|
|
7
7
|
get messages$() {
|
|
8
8
|
return this.messageSubject.asObservable();
|
|
@@ -33,7 +33,7 @@ export class WhatsAppService {
|
|
|
33
33
|
return resolve();
|
|
34
34
|
}
|
|
35
35
|
this.pigeon.reportInfoAsyncSafe('Log in to WhatsApp by scanning the QR code in the terminal required.', '');
|
|
36
|
-
this.waClient = new
|
|
36
|
+
this.waClient = new Client({
|
|
37
37
|
authStrategy: new LocalAuth(),
|
|
38
38
|
puppeteer: {
|
|
39
39
|
headless: true,
|
|
@@ -93,26 +93,9 @@ export class WhatsAppService {
|
|
|
93
93
|
this.sendMessageAsyncSafe("48601926367", `Test successful, application is up since ${new Date(this.createdAt).toLocaleDateString('pl-PL', polandTimeOptions)}, server time: ${new Date(this.createdAt).toLocaleTimeString('pl-PL', serverTimeOptions)}`);
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
|
-
// if (message.body.toLowerCase() === 'roundtrip') {
|
|
97
|
-
// this.sendMessageAsyncSafe(
|
|
98
|
-
// "48601926367",
|
|
99
|
-
// `Roundtrip test started at ${new Date().toLocaleDateString('pl-PL', polandTimeOptions)}`
|
|
100
|
-
// );
|
|
101
|
-
// const args: AddTaskArgs = {
|
|
102
|
-
// channel: this.channel,
|
|
103
|
-
// payload: `Roundtrip test successful`,
|
|
104
|
-
// parentIds: []
|
|
105
|
-
// };
|
|
106
|
-
// await this.actor.addTaskAsync(args, true).catch((err: any) => {
|
|
107
|
-
// this.pigeon.reportUrgentAsyncSafe(`Error adding task`, toJson(err));
|
|
108
|
-
// console.error('❌ Error adding task');
|
|
109
|
-
// console.error(toJson(err));
|
|
110
|
-
// });
|
|
111
|
-
// return;
|
|
112
|
-
// }
|
|
113
96
|
const chat = await this.waClient.getChatById(message.from);
|
|
114
97
|
const messages = await chat.fetchMessages({ limit: 10 });
|
|
115
|
-
this.messageSubject.next(messages);
|
|
98
|
+
this.messageSubject.next(messages ?? []);
|
|
116
99
|
});
|
|
117
100
|
});
|
|
118
101
|
}
|