Created
October 13, 2023 14:46
-
-
Save tripolskypetr/60b0d8100db034937fad1caa09354ebb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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