mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
test(Telegram Trigger Node): Add tests for Telegram Trigger (no-changelog) (#14537)
This commit is contained in:
@@ -9,8 +9,9 @@ import type {
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes } from 'n8n-workflow';
|
||||
|
||||
import { apiRequest, getImageBySize, getSecretToken } from './GenericFunctions';
|
||||
import { apiRequest, getSecretToken } from './GenericFunctions';
|
||||
import type { IEvent } from './IEvent';
|
||||
import { downloadFile } from './util/triggerUtils';
|
||||
|
||||
export class TelegramTrigger implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -277,86 +278,10 @@ export class TelegramTrigger implements INodeType {
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields') as IDataObject;
|
||||
|
||||
if (additionalFields.download === true) {
|
||||
let imageSize = 'large';
|
||||
if (additionalFields.download) {
|
||||
const downloadFilesResult = await downloadFile(this, credentials, bodyData, additionalFields);
|
||||
|
||||
let key: 'message' | 'channel_post' = 'message';
|
||||
|
||||
if (bodyData.channel_post) {
|
||||
key = 'channel_post';
|
||||
}
|
||||
|
||||
if (
|
||||
(bodyData[key]?.photo && Array.isArray(bodyData[key]?.photo)) ||
|
||||
bodyData[key]?.document ||
|
||||
bodyData[key]?.video
|
||||
) {
|
||||
if (additionalFields.imageSize) {
|
||||
imageSize = additionalFields.imageSize as string;
|
||||
}
|
||||
|
||||
let fileId;
|
||||
|
||||
if (bodyData[key]?.photo) {
|
||||
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 available
|
||||
// Basically the Image Size parameter would work just when the images comes from the mobile app
|
||||
if (image === undefined) {
|
||||
image = bodyData[key]!.photo![0];
|
||||
}
|
||||
|
||||
fileId = image.file_id;
|
||||
} else if (bodyData[key]?.video) {
|
||||
fileId = bodyData[key]?.video?.file_id;
|
||||
} else {
|
||||
fileId = bodyData[key]?.document?.file_id;
|
||||
}
|
||||
|
||||
const {
|
||||
result: { file_path },
|
||||
} = await apiRequest.call(this, 'GET', `getFile?file_id=${fileId}`, {});
|
||||
|
||||
const file = await apiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
'',
|
||||
{},
|
||||
{},
|
||||
{
|
||||
json: false,
|
||||
encoding: null,
|
||||
uri: `${credentials.baseUrl}/file/bot${credentials.accessToken}/${file_path}`,
|
||||
resolveWithFullResponse: true,
|
||||
},
|
||||
);
|
||||
|
||||
const data = Buffer.from(file.body as string);
|
||||
|
||||
const fileName = file_path.split('/').pop();
|
||||
|
||||
const binaryData = await this.helpers.prepareBinaryData(
|
||||
data as unknown as Buffer,
|
||||
fileName as string,
|
||||
);
|
||||
|
||||
return {
|
||||
workflowData: [
|
||||
[
|
||||
{
|
||||
json: bodyData as unknown as IDataObject,
|
||||
binary: {
|
||||
data: binaryData,
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
}
|
||||
if (Object.entries(downloadFilesResult).length !== 0) return downloadFilesResult;
|
||||
}
|
||||
|
||||
if (nodeVersion >= 1.2) {
|
||||
|
||||
Reference in New Issue
Block a user