2023-10-09 05:59:48 +03:00
|
|
|
import { BaseTelegramClient } from '@mtcute/core'
|
|
|
|
|
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'
|
2023-10-09 05:59:48 +03:00
|
|
|
import { resolvePeer } from '../users/resolve-peer'
|
2021-05-10 00:35:29 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
export async function editInviteLink(
|
2023-10-09 05:59:48 +03:00
|
|
|
client: BaseTelegramClient,
|
2021-05-10 00:35:29 +03:00
|
|
|
params: {
|
2023-10-07 00:22:08 +03:00
|
|
|
/** Chat ID */
|
|
|
|
chatId: InputPeerLike
|
|
|
|
/** Invite link to edit */
|
|
|
|
link: string
|
2021-05-10 00:35:29 +03:00
|
|
|
/**
|
|
|
|
* 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
|
2023-06-05 03:30:48 +03:00
|
|
|
},
|
2021-05-10 00:35:29 +03:00
|
|
|
): Promise<ChatInviteLink> {
|
2023-10-07 00:22:08 +03:00
|
|
|
const { chatId, link, expires, usageLimit, withApproval } = params
|
|
|
|
|
2023-10-09 05:59:48 +03:00
|
|
|
const res = await client.call({
|
2021-05-10 00:35:29 +03:00
|
|
|
_: 'messages.editExportedChatInvite',
|
2023-10-09 05:59:48 +03:00
|
|
|
peer: await resolvePeer(client, chatId),
|
2021-05-10 00:35:29 +03:00
|
|
|
link,
|
2023-10-07 00:22:08 +03:00
|
|
|
expireDate: normalizeDate(expires),
|
|
|
|
usageLimit,
|
|
|
|
requestNeeded: 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
|
|
|
|
2023-10-09 05:59:48 +03:00
|
|
|
return new ChatInviteLink(res.invite, peers)
|
2021-05-10 00:35:29 +03:00
|
|
|
}
|