chore(): generate docs
This commit is contained in:
parent
477db5a7c9
commit
2128f97729
75 changed files with 10148 additions and 4112 deletions
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta name="generator" content="JSDoc 3.6.11">
|
||||
<meta charset="utf-8">
|
||||
<title>whatsapp-web.js 1.28.1-alpha.0 » Source: Client.js</title>
|
||||
<title>whatsapp-web.js 1.29.0 » Source: Client.js</title>
|
||||
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
|
||||
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
|
||||
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
|
||||
<div id="jsdoc-navbar-container">
|
||||
<div id="jsdoc-navbar-content">
|
||||
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>28.<wbr>1-alpha.<wbr>0</a>
|
||||
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>29.<wbr>0</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
@ -46,7 +46,7 @@ const { LoadUtils } = require('./util/Injected/Utils');
|
|||
const ChatFactory = require('./factories/ChatFactory');
|
||||
const ContactFactory = require('./factories/ContactFactory');
|
||||
const WebCacheFactory = require('./webCache/WebCacheFactory');
|
||||
const { ClientInfo, Message, MessageMedia, Contact, Location, Poll, PollVote, GroupNotification, Label, Call, Buttons, List, Reaction, Broadcast} = require('./structures');
|
||||
const { Broadcast, Buttons, Call, ClientInfo, Contact, GroupNotification, Label, List, Location, Message, MessageMedia, Poll, PollVote, Reaction } = require('./structures');
|
||||
const NoAuth = require('./authStrategies/NoAuth');
|
||||
const {exposeFunctionIfAbsent} = require('./util/Puppeteer');
|
||||
|
||||
|
|
@ -851,11 +851,9 @@ class Client extends EventEmitter {
|
|||
*
|
||||
*/
|
||||
async sendSeen(chatId) {
|
||||
const result = await this.pupPage.evaluate(async (chatId) => {
|
||||
return await this.pupPage.evaluate(async (chatId) => {
|
||||
return window.WWebJS.sendSeen(chatId);
|
||||
|
||||
}, chatId);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -885,6 +883,7 @@ class Client extends EventEmitter {
|
|||
* @property {string} [stickerName=undefined] - Sets the name of the sticker, (if sendMediaAsSticker is true).
|
||||
* @property {string[]} [stickerCategories=undefined] - Sets the categories of the sticker, (if sendMediaAsSticker is true). Provide emoji char array, can be null.
|
||||
* @property {MessageMedia} [media] - Media to be sent
|
||||
* @property {any} [extra] - Extra options
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -896,6 +895,19 @@ class Client extends EventEmitter {
|
|||
* @returns {Promise&lt;Message>} Message that was just sent
|
||||
*/
|
||||
async sendMessage(chatId, content, options = {}) {
|
||||
const isChannel = /@\w*newsletter\b/.test(chatId);
|
||||
|
||||
if (isChannel &amp;&amp; [
|
||||
options.sendMediaAsDocument, options.quotedMessageId,
|
||||
options.parseVCards, options.isViewOnce,
|
||||
content instanceof Location, content instanceof Contact,
|
||||
content instanceof Buttons, content instanceof List,
|
||||
Array.isArray(content) &amp;&amp; content.length > 0 &amp;&amp; content[0] instanceof Contact
|
||||
].includes(true)) {
|
||||
console.warn('The message type is currently not supported for sending in channels,\nthe supported message types are: text, image, sticker, gif, video, voice and poll.');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (options.mentions) {
|
||||
!Array.isArray(options.mentions) &amp;&amp; (options.mentions = [options.mentions]);
|
||||
if (options.mentions.some((possiblyContact) => possiblyContact instanceof Contact)) {
|
||||
|
|
@ -905,7 +917,7 @@ class Client extends EventEmitter {
|
|||
}
|
||||
|
||||
options.groupMentions &amp;&amp; !Array.isArray(options.groupMentions) &amp;&amp; (options.groupMentions = [options.groupMentions]);
|
||||
|
||||
|
||||
let internalOptions = {
|
||||
linkPreview: options.linkPreview === false ? undefined : true,
|
||||
sendAudioAsVoice: options.sendAudioAsVoice,
|
||||
|
|
@ -921,14 +933,14 @@ class Client extends EventEmitter {
|
|||
extraOptions: options.extra
|
||||
};
|
||||
|
||||
const sendSeen = typeof options.sendSeen === 'undefined' ? true : options.sendSeen;
|
||||
const sendSeen = options.sendSeen !== false;
|
||||
|
||||
if (content instanceof MessageMedia) {
|
||||
internalOptions.attachment = content;
|
||||
internalOptions.media = content;
|
||||
internalOptions.isViewOnce = options.isViewOnce,
|
||||
content = '';
|
||||
} else if (options.media instanceof MessageMedia) {
|
||||
internalOptions.attachment = options.media;
|
||||
internalOptions.media = options.media;
|
||||
internalOptions.caption = content;
|
||||
internalOptions.isViewOnce = options.isViewOnce,
|
||||
content = '';
|
||||
|
|
@ -945,17 +957,19 @@ class Client extends EventEmitter {
|
|||
internalOptions.contactCardList = content.map(contact => contact.id._serialized);
|
||||
content = '';
|
||||
} else if (content instanceof Buttons) {
|
||||
console.warn('Buttons are now deprecated. See more at https://www.youtube.com/watch?v=hv1R1rLeVVE.');
|
||||
if (content.type !== 'chat') { internalOptions.attachment = content.body; }
|
||||
internalOptions.buttons = content;
|
||||
content = '';
|
||||
} else if (content instanceof List) {
|
||||
console.warn('Lists are now deprecated. See more at https://www.youtube.com/watch?v=hv1R1rLeVVE.');
|
||||
internalOptions.list = content;
|
||||
content = '';
|
||||
}
|
||||
|
||||
if (internalOptions.sendMediaAsSticker &amp;&amp; internalOptions.attachment) {
|
||||
internalOptions.attachment = await Util.formatToWebpSticker(
|
||||
internalOptions.attachment, {
|
||||
if (internalOptions.sendMediaAsSticker &amp;&amp; internalOptions.media) {
|
||||
internalOptions.media = await Util.formatToWebpSticker(
|
||||
internalOptions.media, {
|
||||
name: options.stickerName,
|
||||
author: options.stickerAuthor,
|
||||
categories: options.stickerCategories
|
||||
|
|
@ -963,20 +977,60 @@ class Client extends EventEmitter {
|
|||
);
|
||||
}
|
||||
|
||||
const newMessage = await this.pupPage.evaluate(async (chatId, message, options, sendSeen) => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
const chat = await window.Store.Chat.find(chatWid);
|
||||
const sentMsg = await this.pupPage.evaluate(async (chatId, content, options, sendSeen) => {
|
||||
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
||||
|
||||
if (!chat) return null;
|
||||
|
||||
if (sendSeen) {
|
||||
await window.WWebJS.sendSeen(chatId);
|
||||
}
|
||||
|
||||
const msg = await window.WWebJS.sendMessage(chat, message, options, sendSeen);
|
||||
return window.WWebJS.getMessageModel(msg);
|
||||
const msg = await window.WWebJS.sendMessage(chat, content, options);
|
||||
return msg
|
||||
? window.WWebJS.getMessageModel(msg)
|
||||
: undefined;
|
||||
}, chatId, content, internalOptions, sendSeen);
|
||||
|
||||
return new Message(this, newMessage);
|
||||
return sentMsg
|
||||
? new Message(this, sentMsg)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} SendChannelAdminInviteOptions
|
||||
* @property {?string} comment The comment to be added to an invitation
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sends a channel admin invitation to a user, allowing them to become an admin of the channel
|
||||
* @param {string} chatId The ID of a user to send the channel admin invitation to
|
||||
* @param {string} channelId The ID of a channel for which the invitation is being sent
|
||||
* @param {SendChannelAdminInviteOptions} options
|
||||
* @returns {Promise&lt;boolean>} Returns true if an invitation was sent successfully, false otherwise
|
||||
*/
|
||||
async sendChannelAdminInvite(chatId, channelId, options = {}) {
|
||||
const response = await this.pupPage.evaluate(async (chatId, channelId, options) => {
|
||||
const channelWid = window.Store.WidFactory.createWid(channelId);
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
const chat = window.Store.Chat.get(chatWid) || (await window.Store.Chat.find(chatWid));
|
||||
|
||||
if (!chatWid.isUser()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return await window.Store.SendChannelMessage.sendNewsletterAdminInviteMessage(
|
||||
chat,
|
||||
{
|
||||
newsletterWid: channelWid,
|
||||
invitee: chatWid,
|
||||
inviteMessage: options.comment,
|
||||
base64Thumb: await window.WWebJS.getProfilePicThumbToBase64(channelWid)
|
||||
}
|
||||
);
|
||||
}, chatId, channelId, options);
|
||||
|
||||
return response.messageSendResult === 'OK';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1002,7 +1056,7 @@ class Client extends EventEmitter {
|
|||
* @returns {Promise&lt;Array&lt;Chat>>}
|
||||
*/
|
||||
async getChats() {
|
||||
let chats = await this.pupPage.evaluate(async () => {
|
||||
const chats = await this.pupPage.evaluate(async () => {
|
||||
return await window.WWebJS.getChats();
|
||||
});
|
||||
|
||||
|
|
@ -1010,16 +1064,51 @@ class Client extends EventEmitter {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get chat instance by ID
|
||||
* Gets all cached {@link Channel} instance
|
||||
* @returns {Promise&lt;Array&lt;Channel>>}
|
||||
*/
|
||||
async getChannels() {
|
||||
const channels = await this.pupPage.evaluate(async () => {
|
||||
return await window.WWebJS.getChannels();
|
||||
});
|
||||
|
||||
return channels.map((channel) => ChatFactory.create(this, channel));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets chat or channel instance by ID
|
||||
* @param {string} chatId
|
||||
* @returns {Promise&lt;Chat>}
|
||||
* @returns {Promise&lt;Chat|Channel>}
|
||||
*/
|
||||
async getChatById(chatId) {
|
||||
let chat = await this.pupPage.evaluate(async chatId => {
|
||||
const chat = await this.pupPage.evaluate(async chatId => {
|
||||
return await window.WWebJS.getChat(chatId);
|
||||
}, chatId);
|
||||
return chat
|
||||
? ChatFactory.create(this, chat)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
return ChatFactory.create(this, chat);
|
||||
/**
|
||||
* Gets a {@link Channel} instance by invite code
|
||||
* @param {string} inviteCode The code that comes after the 'https://whatsapp.com/channel/'
|
||||
* @returns {Promise&lt;Channel>}
|
||||
*/
|
||||
async getChannelByInviteCode(inviteCode) {
|
||||
const channel = await this.pupPage.evaluate(async (inviteCode) => {
|
||||
let channelMetadata;
|
||||
try {
|
||||
channelMetadata = await window.WWebJS.getChannelMetadata(inviteCode);
|
||||
} catch (err) {
|
||||
if (err.name === 'ServerStatusCodeError') return null;
|
||||
throw err;
|
||||
}
|
||||
return await window.WWebJS.getChat(channelMetadata.id);
|
||||
}, inviteCode);
|
||||
|
||||
return channel
|
||||
? ChatFactory.create(this, channel)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1089,6 +1178,61 @@ class Client extends EventEmitter {
|
|||
return res.gid._serialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a channel admin invitation and promotes the current user to a channel admin
|
||||
* @param {string} channelId The channel ID to accept the admin invitation from
|
||||
* @returns {Promise&lt;boolean>} Returns true if the operation completed successfully, false otherwise
|
||||
*/
|
||||
async acceptChannelAdminInvite(channelId) {
|
||||
return await this.pupPage.evaluate(async (channelId) => {
|
||||
try {
|
||||
await window.Store.ChannelUtils.acceptNewsletterAdminInvite(channelId);
|
||||
return true;
|
||||
} catch (err) {
|
||||
if (err.name === 'ServerStatusCodeError') return false;
|
||||
throw err;
|
||||
}
|
||||
}, channelId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Revokes a channel admin invitation sent to a user by a channel owner
|
||||
* @param {string} channelId The channel ID an invitation belongs to
|
||||
* @param {string} userId The user ID the invitation was sent to
|
||||
* @returns {Promise&lt;boolean>} Returns true if the operation completed successfully, false otherwise
|
||||
*/
|
||||
async revokeChannelAdminInvite(channelId, userId) {
|
||||
return await this.pupPage.evaluate(async (channelId, userId) => {
|
||||
try {
|
||||
const userWid = window.Store.WidFactory.createWid(userId);
|
||||
await window.Store.ChannelUtils.revokeNewsletterAdminInvite(channelId, userWid);
|
||||
return true;
|
||||
} catch (err) {
|
||||
if (err.name === 'ServerStatusCodeError') return false;
|
||||
throw err;
|
||||
}
|
||||
}, channelId, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Demotes a channel admin to a regular subscriber (can be used also for self-demotion)
|
||||
* @param {string} channelId The channel ID to demote an admin in
|
||||
* @param {string} userId The user ID to demote
|
||||
* @returns {Promise&lt;boolean>} Returns true if the operation completed successfully, false otherwise
|
||||
*/
|
||||
async demoteChannelAdmin(channelId, userId) {
|
||||
return await this.pupPage.evaluate(async (channelId, userId) => {
|
||||
try {
|
||||
const userWid = window.Store.WidFactory.createWid(userId);
|
||||
await window.Store.ChannelUtils.demoteNewsletterAdmin(channelId, userWid);
|
||||
return true;
|
||||
} catch (err) {
|
||||
if (err.name === 'ServerStatusCodeError') return false;
|
||||
throw err;
|
||||
}
|
||||
}, channelId, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a private invitation to join a group
|
||||
* @param {object} inviteInfo Invite V4 Info
|
||||
|
|
@ -1165,7 +1309,7 @@ class Client extends EventEmitter {
|
|||
*/
|
||||
async archiveChat(chatId) {
|
||||
return await this.pupPage.evaluate(async chatId => {
|
||||
let chat = await window.Store.Chat.get(chatId);
|
||||
let chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
||||
await window.Store.Cmd.archiveChat(chat, true);
|
||||
return true;
|
||||
}, chatId);
|
||||
|
|
@ -1177,7 +1321,7 @@ class Client extends EventEmitter {
|
|||
*/
|
||||
async unarchiveChat(chatId) {
|
||||
return await this.pupPage.evaluate(async chatId => {
|
||||
let chat = await window.Store.Chat.get(chatId);
|
||||
let chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
||||
await window.Store.Cmd.archiveChat(chat, false);
|
||||
return false;
|
||||
}, chatId);
|
||||
|
|
@ -1189,7 +1333,7 @@ class Client extends EventEmitter {
|
|||
*/
|
||||
async pinChat(chatId) {
|
||||
return this.pupPage.evaluate(async chatId => {
|
||||
let chat = window.Store.Chat.get(chatId);
|
||||
let chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
||||
if (chat.pin) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1212,7 +1356,7 @@ class Client extends EventEmitter {
|
|||
*/
|
||||
async unpinChat(chatId) {
|
||||
return this.pupPage.evaluate(async chatId => {
|
||||
let chat = window.Store.Chat.get(chatId);
|
||||
let chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
||||
if (!chat.pin) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1264,7 +1408,7 @@ class Client extends EventEmitter {
|
|||
*/
|
||||
async markChatUnread(chatId) {
|
||||
await this.pupPage.evaluate(async chatId => {
|
||||
let chat = await window.Store.Chat.get(chatId);
|
||||
let chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
||||
await window.Store.Cmd.markChatUnread(chat, true);
|
||||
}, chatId);
|
||||
}
|
||||
|
|
@ -1466,7 +1610,7 @@ class Client extends EventEmitter {
|
|||
for (const participant of createGroupResult.participants) {
|
||||
let isInviteV4Sent = false;
|
||||
const participantId = participant.wid._serialized;
|
||||
const statusCode = participant.error ?? 200;
|
||||
const statusCode = participant.error || 200;
|
||||
|
||||
if (autoSendInviteV4 &amp;&amp; statusCode === 403) {
|
||||
window.Store.Contact.gadd(participant.wid, { silent: true });
|
||||
|
|
@ -1505,6 +1649,219 @@ class Client extends EventEmitter {
|
|||
}, title, participants, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* An object that handles the result for {@link createChannel} method
|
||||
* @typedef {Object} CreateChannelResult
|
||||
* @property {string} title A channel title
|
||||
* @property {ChatId} nid An object that handels the newly created channel ID
|
||||
* @property {string} nid.server 'newsletter'
|
||||
* @property {string} nid.user 'XXXXXXXXXX'
|
||||
* @property {string} nid._serialized 'XXXXXXXXXX@newsletter'
|
||||
* @property {string} inviteLink The channel invite link, starts with 'https://whatsapp.com/channel/'
|
||||
* @property {number} createdAtTs The timestamp the channel was created at
|
||||
*/
|
||||
|
||||
/**
|
||||
* Options for the channel creation
|
||||
* @typedef {Object} CreateChannelOptions
|
||||
* @property {?string} description The channel description
|
||||
* @property {?MessageMedia} picture The channel profile picture
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a new channel
|
||||
* @param {string} title The channel name
|
||||
* @param {CreateChannelOptions} options
|
||||
* @returns {Promise&lt;CreateChannelResult|string>} Returns an object that handles the result for the channel creation or an error message as a string
|
||||
*/
|
||||
async createChannel(title, options = {}) {
|
||||
return await this.pupPage.evaluate(async (title, options) => {
|
||||
let response, { description = null, picture = null } = options;
|
||||
|
||||
if (!window.Store.ChannelUtils.isNewsletterCreationEnabled()) {
|
||||
return 'CreateChannelError: A channel creation is not enabled';
|
||||
}
|
||||
|
||||
if (picture) {
|
||||
picture = await window.WWebJS.cropAndResizeImage(picture, {
|
||||
asDataUrl: true,
|
||||
mimetype: 'image/jpeg',
|
||||
size: 640,
|
||||
quality: 1
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
response = await window.Store.ChannelUtils.createNewsletterQuery({
|
||||
name: title,
|
||||
description: description,
|
||||
picture: picture,
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.name === 'ServerStatusCodeError') {
|
||||
return 'CreateChannelError: An error occupied while creating a channel';
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
return {
|
||||
title: title,
|
||||
nid: window.Store.JidToWid.newsletterJidToWid(response.idJid),
|
||||
inviteLink: `https://whatsapp.com/channel/${response.newsletterInviteLinkMetadataMixin.inviteCode}`,
|
||||
createdAtTs: response.newsletterCreationTimeMetadataMixin.creationTimeValue
|
||||
};
|
||||
}, title, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to channel
|
||||
* @param {string} channelId The channel ID
|
||||
* @returns {Promise&lt;boolean>} Returns true if the operation completed successfully, false otherwise
|
||||
*/
|
||||
async subscribeToChannel(channelId) {
|
||||
return await this.pupPage.evaluate(async (channelId) => {
|
||||
return await window.WWebJS.subscribeToUnsubscribeFromChannel(channelId, 'Subscribe');
|
||||
}, channelId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for unsubscribe from a channel
|
||||
* @typedef {Object} UnsubscribeOptions
|
||||
* @property {boolean} [deleteLocalModels = false] If true, after an unsubscription, it will completely remove a channel from the channel collection making it seem like the current user have never interacted with it. Otherwise it will only remove a channel from the list of channels the current user is subscribed to and will set the membership type for that channel to GUEST
|
||||
*/
|
||||
|
||||
/**
|
||||
* Unsubscribe from channel
|
||||
* @param {string} channelId The channel ID
|
||||
* @param {UnsubscribeOptions} options
|
||||
* @returns {Promise&lt;boolean>} Returns true if the operation completed successfully, false otherwise
|
||||
*/
|
||||
async unsubscribeFromChannel(channelId, options) {
|
||||
return await this.pupPage.evaluate(async (channelId, options) => {
|
||||
return await window.WWebJS.subscribeToUnsubscribeFromChannel(channelId, 'Unsubscribe', options);
|
||||
}, channelId, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for transferring a channel ownership to another user
|
||||
* @typedef {Object} TransferChannelOwnershipOptions
|
||||
* @property {boolean} [shouldDismissSelfAsAdmin = false] If true, after the channel ownership is being transferred to another user, the current user will be dismissed as a channel admin and will become to a channel subscriber.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Transfers a channel ownership to another user.
|
||||
* Note: the user you are transferring the channel ownership to must be a channel admin.
|
||||
* @param {string} channelId
|
||||
* @param {string} newOwnerId
|
||||
* @param {TransferChannelOwnershipOptions} options
|
||||
* @returns {Promise&lt;boolean>} Returns true if the operation completed successfully, false otherwise
|
||||
*/
|
||||
async transferChannelOwnership(channelId, newOwnerId, options = {}) {
|
||||
return await this.pupPage.evaluate(async (channelId, newOwnerId, options) => {
|
||||
const channel = await window.WWebJS.getChat(channelId, { getAsModel: false });
|
||||
const newOwner = window.Store.Contact.get(newOwnerId) || (await window.Store.Contact.find(newOwnerId));
|
||||
if (!channel.newsletterMetadata) {
|
||||
await window.Store.NewsletterMetadataCollection.update(channel.id);
|
||||
}
|
||||
|
||||
try {
|
||||
await window.Store.ChannelUtils.changeNewsletterOwnerAction(channel, newOwner);
|
||||
|
||||
if (options.shouldDismissSelfAsAdmin) {
|
||||
const meContact = window.Store.ContactCollection.getMeContact();
|
||||
meContact &amp;&amp; (await window.Store.ChannelUtils.demoteNewsletterAdminAction(channel, meContact));
|
||||
}
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}, channelId, newOwnerId, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for channels based on search criteria, there are some notes:
|
||||
* 1. The method finds only channels you are not subscribed to currently
|
||||
* 2. If you have never been subscribed to a found channel
|
||||
* or you have unsubscribed from it with {@link UnsubscribeOptions.deleteLocalModels} set to 'true',
|
||||
* the lastMessage property of a found channel will be 'null'
|
||||
*
|
||||
* @param {Object} searchOptions Search options
|
||||
* @param {string} [searchOptions.searchText = ''] Text to search
|
||||
* @param {Array&lt;string>} [searchOptions.countryCodes = [your local region]] Array of country codes in 'ISO 3166-1 alpha-2' standart (@see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) to search for channels created in these countries
|
||||
* @param {boolean} [searchOptions.skipSubscribedNewsletters = false] If true, channels that user is subscribed to won't appear in found channels
|
||||
* @param {number} [searchOptions.view = 0] View type, makes sense only when the searchText is empty. Valid values to provide are:
|
||||
* 0 for RECOMMENDED channels
|
||||
* 1 for TRENDING channels
|
||||
* 2 for POPULAR channels
|
||||
* 3 for NEW channels
|
||||
* @param {number} [searchOptions.limit = 50] The limit of found channels to be appear in the returnig result
|
||||
* @returns {Promise&lt;Array&lt;Channel>|[]>} Returns an array of Channel objects or an empty array if no channels were found
|
||||
*/
|
||||
async searchChannels(searchOptions = {}) {
|
||||
return await this.pupPage.evaluate(async ({
|
||||
searchText = '',
|
||||
countryCodes = [window.Store.ChannelUtils.currentRegion],
|
||||
skipSubscribedNewsletters = false,
|
||||
view = 0,
|
||||
limit = 50
|
||||
}) => {
|
||||
searchText = searchText.trim();
|
||||
const currentRegion = window.Store.ChannelUtils.currentRegion;
|
||||
if (![0, 1, 2, 3].includes(view)) view = 0;
|
||||
|
||||
countryCodes = countryCodes.length === 1 &amp;&amp; countryCodes[0] === currentRegion
|
||||
? countryCodes
|
||||
: countryCodes.filter((code) => Object.keys(window.Store.ChannelUtils.countryCodesIso).includes(code));
|
||||
|
||||
const viewTypeMapping = {
|
||||
0: 'RECOMMENDED',
|
||||
1: 'TRENDING',
|
||||
2: 'POPULAR',
|
||||
3: 'NEW'
|
||||
};
|
||||
|
||||
searchOptions = {
|
||||
searchText: searchText,
|
||||
countryCodes: countryCodes,
|
||||
skipSubscribedNewsletters: skipSubscribedNewsletters,
|
||||
view: viewTypeMapping[view],
|
||||
categories: [],
|
||||
cursorToken: ''
|
||||
};
|
||||
|
||||
const originalFunction = window.Store.ChannelUtils.getNewsletterDirectoryPageSize;
|
||||
limit !== 50 &amp;&amp; (window.Store.ChannelUtils.getNewsletterDirectoryPageSize = () => limit);
|
||||
|
||||
const channels = (await window.Store.ChannelUtils.fetchNewsletterDirectories(searchOptions)).newsletters;
|
||||
|
||||
limit !== 50 &amp;&amp; (window.Store.ChannelUtils.getNewsletterDirectoryPageSize = originalFunction);
|
||||
|
||||
return channels
|
||||
? await Promise.all(channels.map((channel) => window.WWebJS.getChatModel(channel, { isChannel: true })))
|
||||
: [];
|
||||
}, searchOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the channel you created
|
||||
* @param {string} channelId The ID of a channel to delete
|
||||
* @returns {Promise&lt;boolean>} Returns true if the operation completed successfully, false otherwise
|
||||
*/
|
||||
async deleteChannel(channelId) {
|
||||
return await this.client.pupPage.evaluate(async (channelId) => {
|
||||
const channel = await window.WWebJS.getChat(channelId, { getAsModel: false });
|
||||
if (!channel) return false;
|
||||
try {
|
||||
await window.Store.ChannelUtils.deleteNewsletterAction(channel);
|
||||
return true;
|
||||
} catch (err) {
|
||||
if (err.name === 'ServerStatusCodeError') return false;
|
||||
throw err;
|
||||
}
|
||||
}, channelId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all current Labels
|
||||
* @returns {Promise&lt;Array&lt;Label>>}
|
||||
|
|
@ -1863,7 +2220,7 @@ module.exports = Client;
|
|||
<footer id="jsdoc-footer" class="jsdoc-footer">
|
||||
<div id="jsdoc-footer-container">
|
||||
<p>
|
||||
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.11 on May 30, 2025.
|
||||
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.11 on May 31, 2025.
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
|
|
|||
Loading…
Reference in a new issue