Add sending annotation images

This commit is contained in:
2022-01-30 22:39:44 +03:00
parent 9ceb6ed350
commit 9b525a5c5c
2 changed files with 24 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ import { getCallbackArgs, getPaginatedMessage, getPrefixWithQueryCreator, getSea
import { getRandomKeyboard, getTextPaginationData, getUpdateLogKeyboard, getUserAllowedLangsKeyboard } from './keyboard';
import { sendFile } from './hooks/downloading';
import { setCommands } from './hooks/setCommands';
import { downloadImage } from './services/downloader';
Sentry.init({
@@ -143,6 +144,12 @@ export async function createApprovedBot(token: string, state: BotState): Promise
const data = getTextPaginationData(`${CallbackData.BOOK_ANNOTATION_PREFIX}${bookId}`, annotation.text, 0);
if (annotation.file) {
const imageData = await downloadImage(annotation.file);
if (imageData) await ctx.telegram.sendPhoto(ctx.message.chat.id, {source: imageData});
}
try {
await ctx.reply(data.current, {
parse_mode: "HTML",
@@ -196,6 +203,12 @@ export async function createApprovedBot(token: string, state: BotState): Promise
const data = getTextPaginationData(`${CallbackData.AUTHOR_ANNOTATION_PREFIX}${authorId}`, annotation.text, 0);
if (annotation.file) {
const imageData = await downloadImage(annotation.file);
if (imageData) await ctx.telegram.sendPhoto(ctx.message.chat.id, {source: imageData});
}
try {
await ctx.reply(data.current, {
parse_mode: "HTML",

View File

@@ -21,3 +21,14 @@ export async function download(source_id: number, remote_id: number, file_type:
filename: (response.headers['content-disposition'] || '').split('filename=')[1]
}
}
export async function downloadImage(path: string) {
const response = await got(path);
if (response.statusCode === 200) {
return response.rawBody;
} else {
return null;
}
}