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
  • Why do you need an Api class?
  • Get Api class in controller
  • Api methods
  • Get Api for different token
  1. Config

Api class

You can use an Api class to send a message to another users and more

PreviousWebhooks and run configNextModules

Last updated 2 years ago

Why do you need an Api class?

If you want to send a message to another user, call api method for a different bot, or get data from the , you can use Api class methods

Get Api class in controller

To get Api class in controller, use @GetApi property decorator, and Api class as type

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

@Controller()
export class AppController {
  @GetApi() api: Api;

  constructor(private readonly appService?: AppService) {}

  @OnCommand('start')
  async start(): Promise<string> {
    await this.api.send('userId', 'Hello!'); // send message
    return 'Hello, world!';
  }
}

.send Api method take arguments:

Argument
Description
Required
1

User ID or channel ID (string or number)

Required

2

Message you want to send (you can use MessageSend class too)

Required

3

Keyboard

Optional

4

Optional

If you want to get a bot token, you can get it via .token api property

Api methods

You can use any method from the Answer class in the Api class

If Api method takes chat id or message id, you need to pass it as 1st and 2nd arguments

Get Api for different token

If you want to call some api method for different bot, use bot.to method

bot.to method takes argument: token you want to get api

main.ts
import { ChatAction } from 'nestgram';
import { bot } from './bot';

bot.to('token').send('chatId', new ChatAction('typing'));

âš™ī¸
api reference
Options