mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
feat: acceptGroupV4Invite (#677)
* Added option client.acceptGroupV4Invite() * Update Client.js * Update index.d.ts Added a description to the inviteV4 object Renamed "invite" by "inviteV4" * Update Client.js * Update Message.js renamed "invite" to "inviteV4" * Update Client.js * Added message.acceptGroupV4Invite method * Update index.d.ts acceptGroupV4Invite * better typings, refactor some names Co-authored-by: Pedro Lopez <pedroslopez@me.com>
This commit is contained in:
@@ -607,6 +607,20 @@ class Client extends EventEmitter {
|
||||
return chatId._serialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a private invitation to join a group
|
||||
* @param {object} inviteV4 Invite V4 Info
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
async acceptGroupV4Invite(inviteInfo) {
|
||||
if(!inviteInfo.inviteCode) throw 'Invalid invite code, try passing the message.inviteV4 object';
|
||||
if (inviteInfo.inviteCodeExp == 0) throw 'Expired invite code';
|
||||
return await this.pupPage.evaluate(async inviteInfo => {
|
||||
let { groupId, fromId, inviteCode, inviteCodeExp, toId } = inviteInfo;
|
||||
return await window.Store.Wap.acceptGroupV4Invite(groupId, fromId, inviteCode, String(inviteCodeExp), toId);
|
||||
}, inviteInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current user's status message
|
||||
* @param {string} status New status message
|
||||
|
||||
@@ -136,6 +136,19 @@ class Message extends Base {
|
||||
*/
|
||||
this.vCards = data.type === MessageTypes.CONTACT_CARD_MULTI ? data.vcardList.map((c) => c.vcard) : data.type === MessageTypes.CONTACT_CARD ? [data.body] : [];
|
||||
|
||||
/**
|
||||
* Group Invite Data
|
||||
* @type {object}
|
||||
*/
|
||||
this.inviteV4 = data.type === MessageTypes.GROUP_INVITE ? {
|
||||
inviteCode: data.inviteCode,
|
||||
inviteCodeExp: data.inviteCodeExp,
|
||||
groupId: data.inviteGrp,
|
||||
groupName: data.inviteGrpName,
|
||||
fromId: data.from._serialized,
|
||||
toId: data.to._serialized
|
||||
} : undefined;
|
||||
|
||||
/**
|
||||
* Indicates the mentions in the message body.
|
||||
* @type {Array<string>}
|
||||
@@ -252,6 +265,14 @@ class Message extends Base {
|
||||
return this.client.sendMessage(chatId, content, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept Group V4 Invite
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
async acceptGroupV4Invite() {
|
||||
return await this.client.acceptGroupV4Invite(this.inviteV4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards this message to another chat
|
||||
*
|
||||
|
||||
@@ -72,7 +72,8 @@ exports.MessageTypes = {
|
||||
ORDER: 'order',
|
||||
REVOKED: 'revoked',
|
||||
PRODUCT: 'product',
|
||||
UNKNOWN: 'unknown'
|
||||
UNKNOWN: 'unknown',
|
||||
GROUP_INVITE: 'groups_v4_invite'
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user