Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ declare namespace WAWebJS {
acceptGroupV4Invite: (
inviteV4: InviteV4Data,
) => Promise<{ status: number }>;
/** Sets or updates your member tag in this group. Max 30 characters, plain text only. */
setMemberTag(label: string): Promise<boolean>;
/** Deletes your member tag in this group. */
deleteMemberTag(): Promise<boolean>;
/** Gets your current member tag in this group, or null if not set. */
getMemberTag(): Promise<string | null>;

/**Returns an object with information about the invite code's group */
getInviteInfo(inviteCode: string): Promise<object>;
Expand Down
58 changes: 58 additions & 0 deletions src/structures/GroupChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,65 @@

return success;
}
/**

Check failure on line 572 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / ESLint

Insert `···`

Check failure on line 572 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / Tests

Insert `···`
* Sets or updates your member tag in this group.

Check failure on line 573 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / ESLint

Insert `····`

Check failure on line 573 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / Tests

Insert `····`
* Max 30 characters, plain text only (no special characters, checkmarks, or links).

Check failure on line 574 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / ESLint

Insert `····`

Check failure on line 574 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / Tests

Insert `····`
* @param {string} label - The tag text to set

Check failure on line 575 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / ESLint

Insert `····`

Check failure on line 575 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / Tests

Insert `····`
* @returns {Promise<boolean>} Returns true if the tag was saved successfully

Check failure on line 576 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / ESLint

Insert `····`

Check failure on line 576 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / Tests

Insert `····`
*/

Check failure on line 577 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / ESLint

Insert `····`

Check failure on line 577 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / Tests

Insert `····`
async setMemberTag(label) {

Check failure on line 578 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / ESLint

Insert `····`

Check failure on line 578 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / Tests

Insert `····`
if (typeof label !== 'string' || label.trim().length === 0) {

Check failure on line 579 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / ESLint

Replace `····` with `········`

Check failure on line 579 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / Tests

Replace `····` with `········`
throw new Error('Member tag must be a non-empty string');

Check failure on line 580 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / ESLint

Insert `····`

Check failure on line 580 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / Tests

Insert `····`
}

Check failure on line 581 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / ESLint

Replace `····` with `········`

Check failure on line 581 in src/structures/GroupChat.js

View workflow job for this annotation

GitHub Actions / Tests

Replace `····` with `········`
if (label.length > 30) {
throw new Error('Member tag must be 30 characters or less');
}

return this.client.pupPage.evaluate(async (chatId, label) => {
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
if (!chat) return false;

const result = await window
.require('WAWebSendMemberLabelAction')
.sendMemberLabelMsg(chat, label.trim());

return result?.messageSendResult === 'OK';
}, this.id._serialized, label);
}

/**
* Deletes your member tag in this group.
* @returns {Promise<boolean>} Returns true if the tag was deleted successfully
*/
async deleteMemberTag() {
return this.client.pupPage.evaluate(async (chatId) => {
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
if (!chat) return false;

const result = await window
.require('WAWebSendMemberLabelAction')
.sendMemberLabelMsg(chat, '');

return result?.messageSendResult === 'OK';
}, this.id._serialized);
}

/**
* Gets your current member tag in this group.
* @returns {Promise<string|null>} The current tag string, or null if not set
*/
async getMemberTag() {
return this.client.pupPage.evaluate(async (chatId) => {
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
if (!chat) return null;

const label = window
.require('WAWebMemberLabelsFrontendUtils')
.getMyMemberLabelStringForChat(chat);

return label ?? null;
}, this.id._serialized);
}
/**
* Gets the invite code for a specific group
* @returns {Promise<string>} Group's invite code
Expand Down
Loading