2021-05-10 00:35:29 +03:00
|
|
|
import { TelegramClient } from '../../client'
|
2021-11-23 00:03:59 +03:00
|
|
|
import { ChatInviteLink, InputPeerLike, PeersIndex } from '../../types'
|
2021-05-10 00:35:29 +03:00
|
|
|
import { normalizeDate } from '../../utils/misc-utils'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit an invite link. You can only edit non-primary
|
|
|
|
* invite links.
|
|
|
|
*
|
|
|
|
* Only pass the fields that you want to modify.
|
|
|
|
*
|
|
|
|
* @param chatId Chat ID
|
|
|
|
* @param link Invite link to edit
|
|
|
|
* @param params
|
|
|
|
* @returns Modified invite link
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
export async function editInviteLink(
|
|
|
|
this: TelegramClient,
|
|
|
|
chatId: InputPeerLike,
|
|
|
|
link: string,
|
|
|
|
params: {
|
|
|
|
/**
|
|
|
|
* Date when this link will expire.
|
|
|
|
* If `number` is passed, UNIX time in ms is expected.
|
|
|
|
*/
|
|
|
|
expires?: number | Date
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum number of users that can be members of this chat
|
|
|
|
* at the same time after joining using this link.
|
|
|
|
*
|
|
|
|
* Integer in range `[1, 99999]` or `Infinity`,
|
|
|
|
*/
|
|
|
|
usageLimit?: number
|
2022-05-09 17:25:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether users to be joined via this link need to be
|
|
|
|
* approved by an admin
|
|
|
|
*/
|
|
|
|
withApproval?: boolean
|
2021-05-10 00:35:29 +03:00
|
|
|
}
|
|
|
|
): Promise<ChatInviteLink> {
|
|
|
|
const res = await this.call({
|
|
|
|
_: 'messages.editExportedChatInvite',
|
2021-05-15 20:25:59 +03:00
|
|
|
peer: await this.resolvePeer(chatId),
|
2021-05-10 00:35:29 +03:00
|
|
|
link,
|
|
|
|
expireDate: normalizeDate(params.expires),
|
2021-06-06 15:20:41 +03:00
|
|
|
usageLimit: params.usageLimit,
|
2022-06-30 16:32:56 +03:00
|
|
|
requestNeeded: params.withApproval,
|
2021-05-10 00:35:29 +03:00
|
|
|
})
|
|
|
|
|
2021-11-23 00:03:59 +03:00
|
|
|
const peers = PeersIndex.from(res)
|
2021-05-10 00:35:29 +03:00
|
|
|
|
2021-11-23 00:03:59 +03:00
|
|
|
return new ChatInviteLink(this, res.invite, peers)
|
2021-05-10 00:35:29 +03:00
|
|
|
}
|