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
  • Send photo
  • Send other media
  • Set thumb
  • Set caption
  • Media caches
  1. Messages

Sending a photo, video and other media

Sending a media by url or path

Send photo

If you want to send photo as message, you can use Photo class and pass it as content to answer.send or MessageSend

Photo class take arguments:

Argument
Description
Required
1

Type how you want to upload the photo. Pass 'path' if you want to upload local file, or pass 'url' if you want to upload file by url

Required

2

Content. Pass path to the file if you passed 'path' as 1st argument, or pass url if you passed 'url' as 1st argument

Required

3

Optional

4

Cache. Pass false to disable the cache

Optional

app.controller.ts
import { OnCommand, Controller, MessageSend, Photo } from 'nestgram';
import { AppService } from './app.service';
import * as path from 'path';

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

  @OnCommand('start')
  async start(): Promise<MessageSend> {
    return new MessageSend(new Photo('path', path.resolve(__dirname, 'image.jpg')));
  }
}

Send other media

You can also use other classes to send various media files. For example, use another class instead of the Photo class:

  • Photo

  • Video

  • Audio

  • Document

  • Animation

  • Voice

  • VideoNote

Set thumb

You can set the thumb for some media files. Just use the .setThumb method on the media class

.setThumb method takes argument: new instance of the Thumb class

app.controller.ts
import { OnCommand, Controller, MessageSend, Audio, Thumb } from 'nestgram';
import { AppService } from './app.service';
import * as path from 'path';

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

  @OnCommand('start')
  async start(): Promise<MessageSend> {
    return new MessageSend(
      new Audio('path', path.resolve(__dirname, 'audio.mp3'))
        .setThumb(new Thumb('path', path.resolve(__dirname, 'thumb.jpg')))
    );
  }
}

Set caption

To set caption, use .setCaption media class method

.setCaption method takes argument: caption you want to set (string)

app.controller.ts
import { OnCommand, Controller, MessageSend, Photo } from 'nestgram';
import { AppService } from './app.service';
import * as path from 'path';

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

  @OnCommand('start')
  async start(): Promise<MessageSend> {
    return new MessageSend(
      new Photo('path', path.resolve(__dirname, 'photo.jpeg'))
        .setCaption('Photo caption'),
    );
  }
}

Media caches

When you upload a new media file, its ID is stored in the nestgram/media.json file so that when you resubmit this media file, you don't upload it again

If you want to disable cache for the same file, pass false as 4th argument to the media class

PreviousViewsNextSending a media group

Last updated 2 years ago

💬
Options