UNPKG

tgsnake

Version:

Telegram MTProto framework for nodejs.

84 lines (83 loc) 3.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendPhoto = sendPhoto; const SendMedia_js_1 = require("./SendMedia.js"); const platform_node_js_1 = require("../../platform.node.js"); const Utilities_js_1 = require("../../Utilities.js"); const Logger_js_1 = require("../../Context/Logger.js"); async function sendPhoto(client, chatId, photo, more = {}) { Logger_js_1.Logger.debug(`exec: send_photo chat ${typeof chatId} (${chatId}) ${(0, Utilities_js_1.parseArgObjAsStr)({ photo, })} ${(0, Utilities_js_1.parseArgObjAsStr)(more)}`); var { disableNotification, replyToMessageId, replyToStoryId, messageThreadId, scheduleDate, sendAsChannel, protectContent, replyMarkup, entities, parseMode, caption, invertMedia, hasSpoiler, } = more; if (typeof photo === 'string') { photo; if (/^http/i.test(photo)) { var savedFile = new platform_node_js_1.Raw.InputMediaPhotoExternal({ spoiler: hasSpoiler, url: photo, }); } else if (/^(\/|\.\.?\/|~\/)/i.test(photo)) { var savedFile = new platform_node_js_1.Raw.InputMediaUploadedPhoto({ file: (await client.core.saveFileStream({ source: platform_node_js_1.fs.createReadStream(photo), fileName: platform_node_js_1.path.basename(photo), })), spoiler: hasSpoiler, }); } else { const media = platform_node_js_1.FileId.decodeFileId(photo); if (media.fileType === platform_node_js_1.FileType.PHOTO) { var savedFile = new platform_node_js_1.Raw.InputMediaPhoto({ spoiler: hasSpoiler, id: new platform_node_js_1.Raw.InputPhoto({ id: media.id, accessHash: media.accessHash, fileReference: media.fileReference, }), }); } else { throw new Error('invalid file id'); } } } else if (platform_node_js_1.Buffer.isBuffer(photo)) { photo; var savedFile = new platform_node_js_1.Raw.InputMediaUploadedPhoto({ file: (await client.core.saveFile({ source: photo, fileName: `${Date.now()}.jpeg`, })), spoiler: hasSpoiler, }); } else if ('pipe' in photo) { var savedFile = new platform_node_js_1.Raw.InputMediaUploadedPhoto({ file: (await client.core.saveFileStream({ source: photo, fileName: `${Date.now()}.jpeg`, })), spoiler: hasSpoiler, }); } else { throw new Error('unknown file'); } return (0, SendMedia_js_1.sendMedia)(client, chatId, savedFile, { disableNotification, replyToMessageId, replyToStoryId, messageThreadId, scheduleDate, sendAsChannel, protectContent, replyMarkup, entities, parseMode, caption, invertMedia, }); }