Skip to content

Instantly share code, notes, and snippets.

@tripolskypetr
Created October 13, 2023 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripolskypetr/60b0d8100db034937fad1caa09354ebb to your computer and use it in GitHub Desktop.
Save tripolskypetr/60b0d8100db034937fad1caa09354ebb to your computer and use it in GitHub Desktop.
"telegraf": "4.3.0",
///////////////////////////////////////////////////////////////////////////////////////
import { IsArray, IsOptional, IsString } from 'class-validator';
export class CreateDto {
@IsString()
token: string;
@IsString()
channel: string;
@IsString()
msg: string;
@IsArray()
@IsString({ each: true })
@IsOptional()
images?: string[];
}
///////////////////////////////////////////////////////////////////////////////////////
@Post('create')
async create(@Body() dto: CreateDto) {
const bot = new Telegraf(dto.token)
await bot.launch();
if (dto.images) {
await bot.telegram.sendMediaGroup(dto.channel, dto.images.map((media) => ({ type: 'photo', media, caption: dto.msg })));
} else {
await bot.telegram.sendMessage(dto.channel, dto.msg);
}
await bot.stop();
return dto;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment