mtcute/packages/client/src/methods/invite-links/edit-invite-link.ts
Alina Tumanova f5976a2d74
ESM + end-to-end tests (#11)
* feat: moved tl-runtime to esm and native ArrayBuffers

* feat: migration to esm

* fix(core): web-related fixes

* test: finally, some good fucking e2e

* chore: fixed linters etc

* ci: added e2e to ci

* build(tl): fixed gen-code on node 20

* fix: codegen Uint8Array, not Buffer

never `git reset --hard` kids

* build: only do type-aware linting for `packages/*`

* build: ignore no-unresolved in ci for e2e

* fix: node 16 doesn't have subtle crypto apparently?

* fix(tests): use Uint8Array

for gods sake please can i just merge this already

* ci: don't parallel tasks in ci

because machines are utter garbage and it may just randomly break

* ci: pass secrets to e2e tests

* ci: separate cli command for ci

apparently im retarded

* fix: run codegen in e2e

im actually retarded

* ci: more fixes for e2e

* ci: debugging stuff

* ci: still debugging

* ci: hopefully fix ci???
2023-10-16 19:23:53 +03:00

60 lines
1.7 KiB
TypeScript

import { BaseTelegramClient } from '@mtcute/core'
import { ChatInviteLink, InputPeerLike, PeersIndex } from '../../types/index.js'
import { normalizeDate } from '../../utils/misc-utils.js'
import { resolvePeer } from '../users/resolve-peer.js'
/**
* 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(
client: BaseTelegramClient,
params: {
/** Chat ID */
chatId: InputPeerLike
/** Invite link to edit */
link: string | ChatInviteLink
/**
* 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
/**
* Whether users to be joined via this link need to be
* approved by an admin
*/
withApproval?: boolean
},
): Promise<ChatInviteLink> {
const { chatId, link, expires, usageLimit, withApproval } = params
const res = await client.call({
_: 'messages.editExportedChatInvite',
peer: await resolvePeer(client, chatId),
link: typeof link === 'string' ? link : link.link,
expireDate: normalizeDate(expires),
usageLimit,
requestNeeded: withApproval,
})
const peers = PeersIndex.from(res)
return new ChatInviteLink(res.invite, peers)
}