Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acceptGroupV4Invite #677

Merged
merged 11 commits into from
Jun 5, 2021
17 changes: 17 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ declare namespace WAWebJS {
/**Accepts an invitation to join a group */
acceptInvite(inviteCode: string): Promise<string>

/** Accepts a private invitation to join a group (v4 invite) */
acceptGroupV4Invite: (inviteV4: InviteV4Data) => Promise<{status: number}>

/**Returns an object with information about the invite code's group */
getInviteInfo(inviteCode: string): Promise<object>

Expand Down Expand Up @@ -419,6 +422,7 @@ declare namespace WAWebJS {
ORDER = 'order',
PRODUCT = 'product',
UNKNOWN = 'unknown',
GROUP_INVITE = 'groups_v4_invite',
}

/** Client status */
Expand Down Expand Up @@ -453,6 +457,15 @@ declare namespace WAWebJS {
readRemaining: number
}

export type InviteV4Data = {
inviteCode: string,
inviteCodeExp: number,
groupId: string,
groupName?: string,
fromId: string,
toId: string
}

/**
* Represents a Message on WhatsApp
*
Expand Down Expand Up @@ -510,6 +523,8 @@ declare namespace WAWebJS {
location: Location,
/** List of vCards contained in the message */
vCards: string[],
/** Invite v4 info */
inviteV4?: InviteV4Data,
/** MediaKey that represents the sticker 'ID' */
mediaKey?: string,
/** Indicates the mentions in the message body. */
Expand All @@ -536,6 +551,8 @@ declare namespace WAWebJS {
businessOwnerJid?: string,
/** Product JID */
productId?: string,
/** Accept the Group V4 Invite in message */
acceptGroupV4Invite: () => Promise<{status: number}>,
/** Deletes the message from the chat */
delete: (everyone?: boolean) => Promise<void>,
/** Downloads and returns the attatched message media */
Expand Down
14 changes: 14 additions & 0 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>}
Expand Down Expand Up @@ -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
*
Expand Down
3 changes: 2 additions & 1 deletion src/util/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ exports.MessageTypes = {
ORDER: 'order',
REVOKED: 'revoked',
PRODUCT: 'product',
UNKNOWN: 'unknown'
UNKNOWN: 'unknown',
GROUP_INVITE: 'groups_v4_invite'
};

/**
Expand Down