Nestgram
  • ⭐About Nestgram
  • 📄Guide
  • 📰News
  • 🔼Handling updates
    • Handling commands
    • Handling text messages
    • Handling other updates
    • Entities: url, email and other
    • Other arguments in handler
    • Handling media files and download it
  • 🪶Nestgram Features
    • Services
    • Middlewares and Params
    • Sending messages correctly
    • Answer class
    • Scopes
    • States
    • Views
  • 💬Messages
    • Sending a photo, video and other media
    • Sending a media group
    • Send location (live) or venue
    • Send contact
    • Send poll
    • Send dice
    • Edit/delete messages
    • Copy or Forward a message
  • ⌨️Keyboards
    • Keyboard types, building keyboard
    • Handle underTheMessage keyboard button click by Alert or Toast
    • Keyboard layouts
  • ⚙️Config
    • CLI
    • Webhooks and run config
    • Api class
    • Modules
      • Mongo module
    • Controller Helper class
  • 🤖API Reference
    • Set chat action
    • Save user profile photo
    • Ban, unban user or chat
    • Restrict or Promote user
    • Set chat permissions
    • Set chat admin custom title
    • Chat invite links
    • Join requests
    • Update chat info, photo, title, description and more
    • Pin or unpin messages
    • Get chat info, leave chat
    • Check user subscription
    • Chat sticker set
    • My commands
    • My default admin rights
    • Menu button
Powered by GitBook
On this page
  • Export chat invite link
  • Create invite link
  • Edit invite link
  • Revoke invite link
  1. API Reference

Chat invite links

You can export chat invite link

Export chat invite link

To export chat invite link, use .exportInviteLink answer/api method

If you need, you can pass chat id you want to export chat invite link as argument (required in Api method)

If you want to know what arguments an API method takes, see the IDE hint

Use this method to generate a new primary invite link for a chat; any previously generated primary link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights

Returns the new invite link as string on success

app.controller.ts
import { Controller, OnCommand, GetAnswer, Answer } from 'nestgram';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @OnCommand('admin_export_invite_link')
  async exportInviteLink(@GetAnswer() answer: Answer): Promise<string> {
    return await answer.exportInviteLink();
  }
}

Create invite link

You can create chat invite link using .createInviteLink answer/api method

.createInviteLink answer method take arguments:

Argument
Description
Required
1

Optional

2

Chat id you want to export invite link to

Optional. Current chat id by default

If you want to know what arguments an API method takes, see the IDE hint

app.controller.ts
import { Controller, OnCommand, IChatInviteLink, GetAnswer, Answer } from 'nestgram';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @OnCommand('admin_create_invite_link')
  async createInviteLink(@GetAnswer() answer: Answer) {
    const inviteLinkInfo: IChatInviteLink = await answer.createInviteLink({ member_limit: 10 });
    return inviteLinkInfo.invite_link;
  }
}

Edit invite link

To edit invite link, use Edit class-method and InviteLink class-mark. Or .editInviteLink api method

Edit class-method take arguments:

Argument
Description
Required
1

Invite link you want to edit

Required

2

Options how you want to edit link

Required

If you want to know what arguments an API method takes, see the IDE hint

app.controller.ts
import { Answer, Controller, Edit, GetAnswer, IChatInviteLink, InviteLink, OnCommand } from 'nestgram';
import { AppService } from './app.service';

@Controller()
export class AppController {
  inviteLink: string
  constructor(private readonly appService: AppService) {}

  @OnCommand('start')
  async createInviteLink(@GetAnswer() answer: Answer) {
    const linkInfo: IChatInviteLink = await answer.createInviteLink();
    return this.inviteLink = linkInfo.invite_link;
  }

  @OnCommand('edit')
  editInviteLink() {
    return new Edit(new InviteLink(this.inviteLink, { name: 'New name (edited)' })).next('Edited');
  }
}

Revoke invite link

You can revoke invite link using .revokeInviteLink answer/api method

.revokeInviteLink answer method take arguments:

Argument
Description
Required
1

Invite link you want to revoke

Required

2

Chat id in which you want to revoke link

Optional. Current chat id by default

If you want to know what arguments an API method takes, see the IDE hint

app.controller.ts
import { Controller, OnCommand, IChatInviteLink, GetAnswer, Answer } from 'nestgram';
import { AppService } from './app.service';

@Controller()
export class AppController {
  inviteLink: string = '';
  constructor(private readonly appService: AppService) {}

  @OnCommand('admin_create_invite_link')
  async createInviteLink(@GetAnswer() answer: Answer) {
    const inviteLinkInfo: IChatInviteLink = await answer.createInviteLink({ member_limit: 10 });
    this.inviteLink = inviteLinkInfo.invite_link;
    return inviteLinkInfo.invite_link;
  }

  @OnCommand('admin_revoke_invite_link')
  async revokeInviteLink(@GetAnswer() answer: Answer) {
    await answer.revokeInviteLink(this.inviteLink);
    return `${this.inviteLink} link revoked`;
  }
}
PreviousSet chat admin custom titleNextJoin requests

Last updated 2 years ago

Returns on success

We recommend using to save data

Returns on success

We recommend using to save data

🤖
chat invite link
services
chat invite link
services
Options