GramJS

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

NameTypeDescription
flags#Flags, see TL conditional fields
legacyRevokePermanentflags.2?trueLegacy 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.
requestNeededflags.3?trueWhether admin confirmation is required before admitting each separate user into the chat
peerInputPeerChat
expireDateflags.0?intExpiration date
usageLimitflags.1?intMaximum number of users that can join using this link
titleflags.4?stringDescription of the invite link, visible only to administrators

Result

ExportedChatInvite

Possible errors

CodeTypeDescription
400CHANNEL_PRIVATEYou haven't joined this channel/supergroup.
400CHAT_ADMIN_REQUIREDYou must be an admin in this chat to do this.
400CHAT_ID_INVALIDThe provided chat id is invalid.
403CHAT_WRITE_FORBIDDENYou can't write in this chat.
400EXPIRE_DATE_INVALIDThe specified expiration date is invalid.
400PEER_ID_INVALIDThe provided peer id is invalid.
400USAGE_LIMIT_INVALIDThe specified usage limit is invalid.

Can bots use this method?

Yes