2023-10-09 05:59:48 +03:00
|
|
|
import { BaseTelegramClient } from '@mtcute/core'
|
|
|
|
|
2023-10-16 19:23:53 +03:00
|
|
|
import { ChatInviteLink, InputPeerLike } from '../../types/index.js'
|
|
|
|
import { normalizeDate } from '../../utils/misc-utils.js'
|
|
|
|
import { resolvePeer } from '../users/resolve-peer.js'
|
2021-05-10 00:35:29 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an additional invite link for the chat.
|
|
|
|
*
|
|
|
|
* You must be an administrator and have appropriate rights.
|
|
|
|
*
|
|
|
|
* @param chatId Chat ID
|
|
|
|
* @param params
|
|
|
|
*/
|
|
|
|
export async function createInviteLink(
|
2023-10-09 05:59:48 +03:00
|
|
|
client: BaseTelegramClient,
|
2021-05-10 00:35:29 +03:00
|
|
|
chatId: InputPeerLike,
|
|
|
|
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`, defaults to `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> {
|
|
|
|
if (!params) params = {}
|
|
|
|
|
2023-10-09 05:59:48 +03:00
|
|
|
const res = await client.call({
|
2021-05-10 00:35:29 +03:00
|
|
|
_: 'messages.exportChatInvite',
|
2023-10-09 05:59:48 +03:00
|
|
|
peer: await resolvePeer(client, chatId),
|
2021-05-10 00:35:29 +03:00
|
|
|
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
|
|
|
})
|
|
|
|
|
2023-10-09 05:59:48 +03:00
|
|
|
return new ChatInviteLink(res)
|
2021-05-10 00:35:29 +03:00
|
|
|
}
|