whatsapp-web.js 1.26.1-alpha.1 → 1.26.1-alpha.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.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  <p>
8
8
  <a href="https://www.npmjs.com/package/whatsapp-web.js"><img src="https://img.shields.io/npm/v/whatsapp-web.js.svg" alt="npm" /></a>
9
9
  <a href="https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765"><img src="https://badges.depfu.com/badges/4a65a0de96ece65fdf39e294e0c8dcba/overview.svg" alt="Depfu" /></a>
10
- <img src="https://img.shields.io/badge/WhatsApp_Web-2.3000.1016590837-brightgreen.svg" alt="WhatsApp_Web 2.2346.52" />
10
+ <img src="https://img.shields.io/badge/WhatsApp_Web-2.3000.1017054665-brightgreen.svg" alt="WhatsApp_Web 2.2346.52" />
11
11
  <a href="https://discord.gg/H7DqQs4"><img src="https://img.shields.io/discord/698610475432411196.svg?logo=discord" alt="Discord server" /></a>
12
12
  </p>
13
13
  <br />
package/example.js CHANGED
@@ -465,6 +465,11 @@ client.on('message', async msg => {
465
465
  // const isSynced = await chat.syncHistory();
466
466
 
467
467
  await msg.reply(isSynced ? 'Historical chat is syncing..' : 'There is no historical chat to sync.');
468
+ } else if (msg.body === '!statuses') {
469
+ const statuses = await client.getBroadcasts();
470
+ console.log(statuses);
471
+ const chat = await statuses[0]?.getChat(); // Get user chat of a first status
472
+ console.log(chat);
468
473
  }
469
474
  });
470
475
 
package/index.d.ts CHANGED
@@ -75,6 +75,9 @@ declare namespace WAWebJS {
75
75
  /** Get all current Labels */
76
76
  getLabels(): Promise<Label[]>
77
77
 
78
+ /** Get all current Broadcasts */
79
+ getBroadcasts(): Promise<Broadcast[]>
80
+
78
81
  /** Change labels in chats */
79
82
  addOrRemoveLabels(labelIds: Array<number|string>, chatIds: Array<string>): Promise<void>
80
83
 
@@ -1089,6 +1092,28 @@ declare namespace WAWebJS {
1089
1092
  getChats: () => Promise<Chat[]>
1090
1093
  }
1091
1094
 
1095
+ export interface Broadcast {
1096
+ /** Chat Object ID */
1097
+ id: {
1098
+ server: string,
1099
+ user: string,
1100
+ _serialized: string
1101
+ },
1102
+ /** Unix timestamp of last story */
1103
+ timestamp: number,
1104
+ /** Number of available statuses */
1105
+ totalCount: number,
1106
+ /** Number of not viewed */
1107
+ unreadCount: number,
1108
+ /** Unix timestamp of last story */
1109
+ msgs: Message[],
1110
+
1111
+ /** Returns the Chat of the owner of the story */
1112
+ getChat: () => Promise<Chat>,
1113
+ /** Returns the Contact of the owner of the story */
1114
+ getContact: () => Promise<Contact>,
1115
+ }
1116
+
1092
1117
  /** Options for sending a message */
1093
1118
  export interface MessageSendOptions {
1094
1119
  /** Show links preview. Has no effect on multi-device accounts. */
package/index.js CHANGED
@@ -22,6 +22,7 @@ module.exports = {
22
22
  ProductMetadata: require('./src/structures/ProductMetadata'),
23
23
  List: require('./src/structures/List'),
24
24
  Buttons: require('./src/structures/Buttons'),
25
+ Broadcast: require('./src/structures/Broadcast'),
25
26
 
26
27
  // Auth Strategies
27
28
  NoAuth: require('./src/authStrategies/NoAuth'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whatsapp-web.js",
3
- "version": "1.26.1-alpha.1",
3
+ "version": "1.26.1-alpha.3",
4
4
  "description": "Library for interacting with the WhatsApp Web API ",
5
5
  "main": "./index.js",
6
6
  "typings": "./index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "test": "mocha tests --recursive --timeout 5000",
9
9
  "test-single": "mocha",
10
10
  "shell": "node --experimental-repl-await ./shell.js",
11
- "generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose"
11
+ "generate-docs": "npx jsdoc --configure .jsdoc.json --verbose"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
package/src/Client.js CHANGED
@@ -15,7 +15,7 @@ const { LoadUtils } = require('./util/Injected/Utils');
15
15
  const ChatFactory = require('./factories/ChatFactory');
16
16
  const ContactFactory = require('./factories/ContactFactory');
17
17
  const WebCacheFactory = require('./webCache/WebCacheFactory');
18
- const { ClientInfo, Message, MessageMedia, Contact, Location, Poll, PollVote, GroupNotification, Label, Call, Buttons, List, Reaction } = require('./structures');
18
+ const { ClientInfo, Message, MessageMedia, Contact, Location, Poll, PollVote, GroupNotification, Label, Call, Buttons, List, Reaction, Broadcast} = require('./structures');
19
19
  const NoAuth = require('./authStrategies/NoAuth');
20
20
  const {exposeFunctionIfAbsent} = require('./util/Puppeteer');
21
21
 
@@ -1472,6 +1472,17 @@ class Client extends EventEmitter {
1472
1472
 
1473
1473
  return labels.map(data => new Label(this, data));
1474
1474
  }
1475
+
1476
+ /**
1477
+ * Get all current Broadcast
1478
+ * @returns {Promise<Array<Broadcast>>}
1479
+ */
1480
+ async getBroadcasts() {
1481
+ const broadcasts = await this.pupPage.evaluate(async () => {
1482
+ return window.WWebJS.getAllStatuses();
1483
+ });
1484
+ return broadcasts.map(data => new Broadcast(this, data));
1485
+ }
1475
1486
 
1476
1487
  /**
1477
1488
  * Get Label instance by ID
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ const Base = require('./Base');
4
+ const Message = require('./Message');
5
+
6
+ /**
7
+ * Represents a Status/Story on WhatsApp
8
+ * @extends {Base}
9
+ */
10
+ class Broadcast extends Base {
11
+ constructor(client, data) {
12
+ super(client);
13
+
14
+ if (data) this._patch(data);
15
+ }
16
+
17
+ _patch(data) {
18
+ /**
19
+ * ID that represents the chat
20
+ * @type {object}
21
+ */
22
+ this.id = data.id;
23
+
24
+ /**
25
+ * Unix timestamp of last status
26
+ * @type {number}
27
+ */
28
+ this.timestamp = data.t;
29
+
30
+ /**
31
+ * Number of available statuses
32
+ * @type {number}
33
+ */
34
+ this.totalCount = data.totalCount;
35
+
36
+ /**
37
+ * Number of not viewed
38
+ * @type {number}
39
+ */
40
+ this.unreadCount = data.unreadCount;
41
+
42
+ /**
43
+ * Messages statuses
44
+ * @type {Message[]}
45
+ */
46
+ this.msgs = data.msgs.map(msg => new Message(this.client, msg));
47
+
48
+ return super._patch(data);
49
+ }
50
+
51
+ /**
52
+ * Returns the Chat this message was sent in
53
+ * @returns {Promise<Chat>}
54
+ */
55
+ getChat() {
56
+ return this.client.getChatById(this.id._serialized);
57
+ }
58
+
59
+ /**
60
+ * Returns the Contact this message was sent from
61
+ * @returns {Promise<Contact>}
62
+ */
63
+ getContact() {
64
+ return this.client.getContactById(this.id._serialized);
65
+ }
66
+
67
+ }
68
+
69
+ module.exports = Broadcast;
@@ -79,7 +79,7 @@ class Chat extends Base {
79
79
  * Last message fo chat
80
80
  * @type {Message}
81
81
  */
82
- this.lastMessage = data.lastMessage ? new Message(super.client, data.lastMessage) : undefined;
82
+ this.lastMessage = data.lastMessage ? new Message(this.client, data.lastMessage) : undefined;
83
83
 
84
84
  return super._patch(data);
85
85
  }
@@ -20,5 +20,6 @@ module.exports = {
20
20
  Payment: require('./Payment'),
21
21
  Reaction: require('./Reaction'),
22
22
  Poll: require('./Poll'),
23
- PollVote: require('./PollVote')
23
+ PollVote: require('./PollVote'),
24
+ Broadcast: require('./Broadcast')
24
25
  };
@@ -7,7 +7,7 @@ exports.DefaultOptions = {
7
7
  headless: true,
8
8
  defaultViewport: null
9
9
  },
10
- webVersion: '2.3000.1016590837',
10
+ webVersion: '2.3000.1017054665',
11
11
  webVersionCache: {
12
12
  type: 'local',
13
13
  },
@@ -451,11 +451,12 @@ exports.LoadUtils = () => {
451
451
  window.WWebJS.getChatModel = async chat => {
452
452
 
453
453
  let res = chat.serialize();
454
- res.isGroup = chat.isGroup;
454
+ res.isGroup = false;
455
455
  res.formattedTitle = chat.formattedTitle;
456
- res.isMuted = chat.mute && chat.mute.isMuted;
456
+ res.isMuted = chat.muteExpiration == 0 ? false : true;
457
457
 
458
458
  if (chat.groupMetadata) {
459
+ res.isGroup = true;
459
460
  const chatWid = window.Store.WidFactory.createWid((chat.id._serialized));
460
461
  await window.Store.GroupMetadata.update(chatWid);
461
462
  res.groupMetadata = chat.groupMetadata.serialize();
@@ -1013,5 +1014,16 @@ exports.LoadUtils = () => {
1013
1014
  const response = await window.Store.pinUnpinMsg(message, action, duration);
1014
1015
  return response.messageSendResult === 'OK';
1015
1016
  };
1017
+
1018
+ window.WWebJS.getStatusModel = status => {
1019
+ let res = status.serialize();
1020
+ delete res._msgs;
1021
+ res.msgs = status._msgs.map(msg => window.WWebJS.getMessageModel(msg));
1022
+ return res;
1023
+ };
1016
1024
 
1025
+ window.WWebJS.getAllStatuses = () => {
1026
+ const statuses = window.Store.Status.getModelsArray();
1027
+ return statuses.map(status => window.WWebJS.getStatusModel(status));
1028
+ };
1017
1029
  };