messages.ExportChatInvite
Export an invite link for a chat
Example
const { Api, TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");
const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});
(async function run() {
await client.connect(); // This assumes you have already authenticated with .start()
const result = await client.invoke(
new Api.messages.ExportChatInvite({
peer: "username",
legacyRevokePermanent: true,
requestNeeded: true,
expireDate: 43,
usageLimit: 43,
title: "My very normal title",
})
);
console.log(result); // prints the result
})();
import { Api, TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";
const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});
(async function run() {
await client.connect(); // This assumes you have already authenticated with .start()
const result: Api.ExportedChatInvite = await client.invoke(
new Api.messages.ExportChatInvite({
peer: "username",
legacyRevokePermanent: true,
requestNeeded: true,
expireDate: 43,
usageLimit: 43,
title: "My very normal title",
})
);
console.log(result); // prints the result
})();
Parameters
Name | Type | Description |
---|---|---|
flags | # | Flags, see TL conditional fields |
legacyRevokePermanent | flags.2?true | Legacy flag, reproducing legacy behavior of this method: if set, revokes all previous links before creating a new one. Kept for bot API BC, should not be used by modern clients. |
requestNeeded | flags.3?true | Whether admin confirmation is required before admitting each separate user into the chat |
peer | InputPeer | Chat |
expireDate | flags.0?int | Expiration date |
usageLimit | flags.1?int | Maximum number of users that can join using this link |
title | flags.4?string | Description of the invite link, visible only to administrators |
Result
Possible errors
Code | Type | Description |
---|---|---|
400 | CHANNEL_PRIVATE | You haven't joined this channel/supergroup. |
400 | CHAT_ADMIN_REQUIRED | You must be an admin in this chat to do this. |
400 | CHAT_ID_INVALID | The provided chat id is invalid. |
403 | CHAT_WRITE_FORBIDDEN | You can't write in this chat. |
400 | EXPIRE_DATE_INVALID | The specified expiration date is invalid. |
400 | PEER_ID_INVALID | The provided peer id is invalid. |
400 | USAGE_LIMIT_INVALID | The specified usage limit is invalid. |
Can bots use this method?
Yes