Enable image downloading in channel_post event on Telegram (#2513)

This commit is contained in:
Ricardo Espinoza 2021-12-03 02:53:20 -05:00 committed by GitHub
parent 95a9019cbe
commit ca761c88c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 14 deletions

View file

@ -1,13 +1,17 @@
export interface IEvent {
message?: {
photo?: [
{
file_id: string,
},
],
document?: {
file_id: string;
interface EventBody {
photo?: [
{
file_id: string,
},
];
document?: {
file_id: string;
};
}
export interface IEvent {
message?: EventBody;
channel_post?: EventBody;
download_link?: string;
}

View file

@ -218,7 +218,13 @@ export class TelegramTrigger implements INodeType {
let imageSize = 'large';
if ((bodyData.message && bodyData.message.photo && Array.isArray(bodyData.message.photo) || bodyData.message?.document)) {
let key: 'message' | 'channel_post' = 'message';
if (bodyData.channel_post) {
key = 'channel_post';
}
if ((bodyData[key] && bodyData[key]?.photo && Array.isArray(bodyData[key]?.photo) || bodyData[key]?.document)) {
if (additionalFields.imageSize) {
@ -227,22 +233,22 @@ export class TelegramTrigger implements INodeType {
let fileId;
if (bodyData.message.photo) {
if (bodyData[key]?.photo) {
let image = getImageBySize(bodyData.message.photo as IDataObject[], imageSize) as IDataObject;
let image = getImageBySize(bodyData[key]?.photo as IDataObject[], imageSize) as IDataObject;
// When the image is sent from the desktop app telegram does not resize the image
// So return the only image avaiable
// Basically the Image Size parameter would work just when the images comes from the mobile app
if (image === undefined) {
image = bodyData.message.photo[0];
image = bodyData[key]!.photo![0];
}
fileId = image.file_id;
} else {
fileId = bodyData.message?.document?.file_id;
fileId = bodyData[key]?.document?.file_id;
}
const { result: { file_path } } = await apiRequest.call(this, 'GET', `getFile?file_id=${fileId}`, {});