Save user profile photo

You can save any user profile photo by index

To save user profile photo, use .saveProfilePhoto answer method or SaveProfilePhoto class-method

SaveProfilePhoto class-methods or .saveProfilePhoto method take arguments:

ArgumentDescriptionRequired
1

Path in which you want to save profile photo

Required

2

Index of the profile photo you want to save

Optional. 0 by default

app.controller.ts
import { Controller, OnCommand, GetAnswer, Answer, ChatAction, SaveProfilePhoto, 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 getChatAction(@GetAnswer() answer: Answer): Promise<ChatAction> {
    const imgPath: string = path.resolve(__dirname, 'profile-photo.jpeg');

    return new ChatAction('upload_photo')
      .next(new SaveProfilePhoto(imgPath))
      .next(new Photo('path', imgPath, null, false))
  }
}

In the 15th line, we disabled the cache with the 4th argument, because user photo may change

Last updated