@wppconnect-team/wppconnect
Advanced tools
Comparing version 1.3.6 to 1.4.0
@@ -0,1 +1,14 @@ | ||
# [1.4.0](https://github.com/wppconnect-team/wppconnect/compare/v1.3.6...v1.4.0) (2021-05-08) | ||
### Bug Fixes | ||
- Fixed getAllMessagesInChat function when chat not found ([2760f68](https://github.com/wppconnect-team/wppconnect/commit/2760f68e2347f4ec9b664315c4a1a89371760aab)) | ||
- Fixed onParticipantsChanged function (fix [#171](https://github.com/wppconnect-team/wppconnect/issues/171)) ([08975a0](https://github.com/wppconnect-team/wppconnect/commit/08975a0657eaed1e4dfc1673003ffac9c657c87f)) | ||
- Improved speed of loadAndGetAllMessagesInChat function (fix [#166](https://github.com/wppconnect-team/wppconnect/issues/166)) ([7f1348a](https://github.com/wppconnect-team/wppconnect/commit/7f1348ac75756822c9356ecc2fc8d793a84f0e30)) | ||
### Features | ||
- Added getAllBroadcastList function (close [#184](https://github.com/wppconnect-team/wppconnect/issues/184)) ([351be03](https://github.com/wppconnect-team/wppconnect/commit/351be03ba4801566753e8856ee3940fb362e202e)) | ||
- Added onNotificationMessage function for notif. msg. ([#171](https://github.com/wppconnect-team/wppconnect/issues/171)) ([32c395b](https://github.com/wppconnect-team/wppconnect/commit/32c395b2f936b9b9d259ca43acaa44c02d455bb6)) | ||
## [1.3.6](https://github.com/wppconnect-team/wppconnect/compare/v1.3.5...v1.3.6) (2021-05-04) | ||
@@ -2,0 +15,0 @@ |
@@ -5,2 +5,3 @@ export declare enum ExposedFn { | ||
onAck = "onAck", | ||
onNotificationMessage = "onNotificationMessage", | ||
onParticipantsChanged = "onParticipantsChanged", | ||
@@ -7,0 +8,0 @@ onStateChange = "onStateChange", |
@@ -25,2 +25,3 @@ "use strict"; | ||
ExposedFn["onAck"] = "onAck"; | ||
ExposedFn["onNotificationMessage"] = "onNotificationMessage"; | ||
ExposedFn["onParticipantsChanged"] = "onParticipantsChanged"; | ||
@@ -27,0 +28,0 @@ ExposedFn["onStateChange"] = "onStateChange"; |
@@ -49,2 +49,11 @@ import { Page } from 'puppeteer'; | ||
/** | ||
* @event Listens to all notification messages, like group changes, join, leave | ||
* @param to callback | ||
* @fires Message | ||
* @returns Disposable object to stop the listening | ||
*/ | ||
onNotificationMessage(callback: (message: Message) => void): { | ||
dispose: () => void; | ||
}; | ||
/** | ||
* @event Listens List of mobile states | ||
@@ -90,2 +99,10 @@ * @returns Disposable object to stop the listening | ||
* @event Listens to participants changed | ||
* @param to callback | ||
* @returns Stream of ParticipantEvent | ||
*/ | ||
onParticipantsChanged(callback: (participantChangedEvent: ParticipantEvent) => void): { | ||
dispose: () => void; | ||
}; | ||
/** | ||
* @event Listens to participants changed | ||
* @param to group id: xxxxx-yyyy@us.c | ||
@@ -95,3 +112,5 @@ * @param to callback | ||
*/ | ||
onParticipantsChanged(groupId: string, fn: (participantChangedEvent: ParticipantEvent) => void): Promise<void>; | ||
onParticipantsChanged(groupId: string, callback: (participantChangedEvent: ParticipantEvent) => void): { | ||
dispose: () => void; | ||
}; | ||
/** | ||
@@ -98,0 +117,0 @@ * @event Fires callback with Chat object every time the host phone is added to a group. |
@@ -78,2 +78,3 @@ "use strict"; | ||
var exposed_enum_1 = require("../helpers/exposed.enum"); | ||
var enum_1 = require("../model/enum"); | ||
var profile_layer_1 = require("./profile.layer"); | ||
@@ -183,2 +184,6 @@ var ListenerLayer = /** @class */ (function (_super) { | ||
} | ||
if (!window['onNotificationMessage'].exposed) { | ||
window.WAPI.onNotificationMessage(window['onNotificationMessage']); | ||
window['onNotificationMessage'].exposed = true; | ||
} | ||
}) | ||
@@ -225,2 +230,11 @@ .catch(function () { })]; | ||
/** | ||
* @event Listens to all notification messages, like group changes, join, leave | ||
* @param to callback | ||
* @fires Message | ||
* @returns Disposable object to stop the listening | ||
*/ | ||
ListenerLayer.prototype.onNotificationMessage = function (callback) { | ||
return this.registerEvent(exposed_enum_1.ExposedFn.onNotificationMessage, callback); | ||
}; | ||
/** | ||
* @event Listens List of mobile states | ||
@@ -280,25 +294,22 @@ * @returns Disposable object to stop the listening | ||
}; | ||
/** | ||
* @event Listens to participants changed | ||
* @param to group id: xxxxx-yyyy@us.c | ||
* @param to callback | ||
* @returns Stream of ParticipantEvent | ||
*/ | ||
ListenerLayer.prototype.onParticipantsChanged = function (groupId, fn) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var method; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
method = 'onParticipantsChanged_' + groupId.replace('_', '').replace('_', ''); | ||
return [2 /*return*/, this.page | ||
.exposeFunction(method, function (participantChangedEvent) { | ||
return fn(participantChangedEvent); | ||
}) | ||
.then(function (_) { | ||
return _this.page.evaluate(function (_a) { | ||
var groupId = _a.groupId, method = _a.method; | ||
//@ts-ignore | ||
WAPI.onParticipantsChanged(groupId, window[method]); | ||
}, { groupId: groupId, method: method }); | ||
})]; | ||
ListenerLayer.prototype.onParticipantsChanged = function (groupId, callback) { | ||
if (typeof groupId === 'function') { | ||
callback = groupId; | ||
groupId = null; | ||
} | ||
var subtypeEvents = ['invite', 'add', 'remove', 'leave']; | ||
return this.registerEvent(exposed_enum_1.ExposedFn.onNotificationMessage, function (message) { | ||
// Only group events | ||
if (message.type !== enum_1.MessageType.GP2 || | ||
!subtypeEvents.includes(message.subtype)) { | ||
return; | ||
} | ||
if (groupId && groupId !== message.id) { | ||
return; | ||
} | ||
callback({ | ||
by: message.from, | ||
groupId: message.chatId, | ||
action: message.subtype, | ||
who: message.recipients, | ||
}); | ||
@@ -305,0 +316,0 @@ }); |
@@ -60,2 +60,8 @@ import { Page } from 'puppeteer'; | ||
/** | ||
* Retrieve all broadcast list | ||
* @category Group | ||
* @returns array of broadcast list | ||
*/ | ||
getAllBroadcastList(): Promise<import("../model").Chat[]>; | ||
/** | ||
* Retrieves contact detail object of given contact id | ||
@@ -62,0 +68,0 @@ * @category Contact |
@@ -236,2 +236,20 @@ "use strict"; | ||
/** | ||
* Retrieve all broadcast list | ||
* @category Group | ||
* @returns array of broadcast list | ||
*/ | ||
RetrieverLayer.prototype.getAllBroadcastList = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var chats; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.page.evaluate(function () { return WAPI.getAllChats(); })]; | ||
case 1: | ||
chats = _a.sent(); | ||
return [2 /*return*/, chats.filter(function (chat) { return chat.isBroadcast && chat.id._serialized !== 'status@broadcast'; })]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Retrieves contact detail object of given contact id | ||
@@ -238,0 +256,0 @@ * @category Contact |
@@ -13,3 +13,2 @@ import { Contact } from './contact'; | ||
archive: boolean; | ||
isReadOnly: boolean; | ||
muteExpiration: number; | ||
@@ -21,3 +20,6 @@ name: string; | ||
kind: string; | ||
isBroadcast: boolean; | ||
isGroup: boolean; | ||
isReadOnly: boolean; | ||
isUser: boolean; | ||
contact: Contact; | ||
@@ -24,0 +26,0 @@ groupMetadata: GroupMetadata; |
export declare enum GroupChangeEvent { | ||
Remove = "remove", | ||
Add = "add" | ||
Add = "add", | ||
Inivite = "invite", | ||
Leave = "leave", | ||
Remove = "remove" | ||
} |
@@ -22,4 +22,6 @@ "use strict"; | ||
(function (GroupChangeEvent) { | ||
GroupChangeEvent["Add"] = "add"; | ||
GroupChangeEvent["Inivite"] = "invite"; | ||
GroupChangeEvent["Leave"] = "leave"; | ||
GroupChangeEvent["Remove"] = "remove"; | ||
GroupChangeEvent["Add"] = "add"; | ||
})(GroupChangeEvent = exports.GroupChangeEvent || (exports.GroupChangeEvent = {})); |
export declare enum MessageType { | ||
TEXT = "chat", | ||
AUDIO = "audio", | ||
VOICE = "ptt", | ||
NOTIFICATION = "notification", | ||
NOTIFICATION_TEMPLATE = "notification_template", | ||
GROUP_NOTIFICATION = "group_notification", | ||
/** | ||
* Group data modification, like subtitle or description and group members (join, leave) | ||
* See {@link GroupNotificationType} | ||
*/ | ||
GP2 = "gp2", | ||
BROADCAST_NOTIFICATION = "broadcast_notification", | ||
E2E_NOTIFICATION = "e2e_notification", | ||
CALL_LOG = "call_log", | ||
PROTOCOL = "protocol", | ||
CHAT = "chat", | ||
LOCATION = "location", | ||
PAYMENT = "payment", | ||
VCARD = "vcard", | ||
CIPHERTEXT = "ciphertext", | ||
MULTI_VCARD = "multi_vcard", | ||
REVOKED = "revoked", | ||
OVERSIZED = "oversized", | ||
GROUPS_V4_INVITE = "groups_v4_invite", | ||
HSM = "hsm", | ||
TEMPLATE_BUTTON_REPLY = "template_button_reply", | ||
IMAGE = "image", | ||
VIDEO = "video", | ||
AUDIO = "audio", | ||
PTT = "ptt", | ||
STICKER = "sticker", | ||
DOCUMENT = "document", | ||
STICKER = "sticker", | ||
LOCATION = "location", | ||
CONTACT_CARD = "vcard", | ||
CONTACT_CARD_MULTI = "multi_vcard", | ||
REVOKED = "revoked", | ||
PRODUCT = "product", | ||
ORDER = "order", | ||
LIST = "list", | ||
LIST_RESPONSE = "list_response", | ||
BUTTONS_RESPONSE = "buttons_response", | ||
UNKNOWN = "unknown" | ||
@@ -14,0 +37,0 @@ } |
@@ -22,13 +22,36 @@ "use strict"; | ||
(function (MessageType) { | ||
MessageType["TEXT"] = "chat"; | ||
MessageType["AUDIO"] = "audio"; | ||
MessageType["VOICE"] = "ptt"; | ||
MessageType["NOTIFICATION"] = "notification"; | ||
MessageType["NOTIFICATION_TEMPLATE"] = "notification_template"; | ||
MessageType["GROUP_NOTIFICATION"] = "group_notification"; | ||
/** | ||
* Group data modification, like subtitle or description and group members (join, leave) | ||
* See {@link GroupNotificationType} | ||
*/ | ||
MessageType["GP2"] = "gp2"; | ||
MessageType["BROADCAST_NOTIFICATION"] = "broadcast_notification"; | ||
MessageType["E2E_NOTIFICATION"] = "e2e_notification"; | ||
MessageType["CALL_LOG"] = "call_log"; | ||
MessageType["PROTOCOL"] = "protocol"; | ||
MessageType["CHAT"] = "chat"; | ||
MessageType["LOCATION"] = "location"; | ||
MessageType["PAYMENT"] = "payment"; | ||
MessageType["VCARD"] = "vcard"; | ||
MessageType["CIPHERTEXT"] = "ciphertext"; | ||
MessageType["MULTI_VCARD"] = "multi_vcard"; | ||
MessageType["REVOKED"] = "revoked"; | ||
MessageType["OVERSIZED"] = "oversized"; | ||
MessageType["GROUPS_V4_INVITE"] = "groups_v4_invite"; | ||
MessageType["HSM"] = "hsm"; | ||
MessageType["TEMPLATE_BUTTON_REPLY"] = "template_button_reply"; | ||
MessageType["IMAGE"] = "image"; | ||
MessageType["VIDEO"] = "video"; | ||
MessageType["AUDIO"] = "audio"; | ||
MessageType["PTT"] = "ptt"; | ||
MessageType["STICKER"] = "sticker"; | ||
MessageType["DOCUMENT"] = "document"; | ||
MessageType["STICKER"] = "sticker"; | ||
MessageType["LOCATION"] = "location"; | ||
MessageType["CONTACT_CARD"] = "vcard"; | ||
MessageType["CONTACT_CARD_MULTI"] = "multi_vcard"; | ||
MessageType["REVOKED"] = "revoked"; | ||
MessageType["PRODUCT"] = "product"; | ||
MessageType["ORDER"] = "order"; | ||
MessageType["LIST"] = "list"; | ||
MessageType["LIST_RESPONSE"] = "list_response"; | ||
MessageType["BUTTONS_RESPONSE"] = "buttons_response"; | ||
MessageType["UNKNOWN"] = "unknown"; | ||
@@ -35,0 +58,0 @@ })(MessageType = exports.MessageType || (exports.MessageType = {})); |
import { Chat } from './chat'; | ||
import { Contact } from './contact'; | ||
import { MessageType } from './enum'; | ||
export interface Message { | ||
id: string; | ||
body: string; | ||
type: string; | ||
type: MessageType; | ||
/** | ||
* When type is GP2: {@link GroupNotificationType} | ||
*/ | ||
subtype: string; | ||
t: number; | ||
@@ -47,2 +52,3 @@ notifyName: string; | ||
mediaData: MediaData; | ||
recipients?: string[]; | ||
} | ||
@@ -49,0 +55,0 @@ export interface MediaData { |
@@ -1,7 +0,7 @@ | ||
import { Id } from './id'; | ||
import { GroupChangeEvent } from './enum'; | ||
export interface ParticipantEvent { | ||
by: Id; | ||
by: string; | ||
groupId: string; | ||
action: GroupChangeEvent; | ||
who: [Id]; | ||
who: string[]; | ||
} |
{ | ||
"name": "@wppconnect-team/wppconnect", | ||
"version": "1.3.6", | ||
"version": "1.4.0", | ||
"description": "WPPConnect is an open source project developed by the JavaScript community with the aim of exporting functions from WhatsApp Web to the node, which can be used to support the creation of any interaction, such as customer service, media sending, intelligence recognition based on phrases artificial and many other things, use your imagination... 😀🤔💭", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is too big to display
853759
20533