mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
✨ Add File->Get to Telegram Node (#1242)
* Add option `Include Download Link`
* ⚡ Add File->Get to Telegram Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
parent
bfd967258c
commit
baa1ee1ad2
|
@ -9,4 +9,5 @@ export interface IEvent {
|
|||
file_id: string;
|
||||
},
|
||||
};
|
||||
download_link?: string;
|
||||
}
|
||||
|
|
|
@ -50,6 +50,10 @@ export class Telegram implements INodeType {
|
|||
name: 'Callback',
|
||||
value: 'callback',
|
||||
},
|
||||
{
|
||||
name: 'File',
|
||||
value: 'file',
|
||||
},
|
||||
{
|
||||
name: 'Message',
|
||||
value: 'message',
|
||||
|
@ -129,6 +133,28 @@ export class Telegram implements INodeType {
|
|||
description: 'The operation to perform.',
|
||||
},
|
||||
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'file',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a file.',
|
||||
},
|
||||
],
|
||||
default: 'get',
|
||||
description: 'The operation to perform.',
|
||||
},
|
||||
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
|
@ -390,6 +416,51 @@ export class Telegram implements INodeType {
|
|||
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// file
|
||||
// ----------------------------------
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// file:get/download
|
||||
// ----------------------------------
|
||||
|
||||
{
|
||||
displayName: 'File ID',
|
||||
name: 'fileId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
resource: [
|
||||
'file',
|
||||
],
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
description: 'The ID of the file.',
|
||||
},
|
||||
{
|
||||
displayName: 'Download',
|
||||
name: 'download',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
resource: [
|
||||
'file',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: true,
|
||||
description: 'Download the file.',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// message
|
||||
// ----------------------------------
|
||||
|
@ -1398,7 +1469,7 @@ export class Telegram implements INodeType {
|
|||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
// For Post
|
||||
let body: IDataObject;
|
||||
|
@ -1484,6 +1555,18 @@ export class Telegram implements INodeType {
|
|||
|
||||
}
|
||||
|
||||
} else if (resource === 'file') {
|
||||
|
||||
if (operation === 'get') {
|
||||
// ----------------------------------
|
||||
// file:get
|
||||
// ----------------------------------
|
||||
|
||||
endpoint = 'getFile';
|
||||
|
||||
body.file_id = this.getNodeParameter('fileId', i) as string;
|
||||
}
|
||||
|
||||
} else if (resource === 'message') {
|
||||
|
||||
if (operation === 'editMessageText') {
|
||||
|
@ -1638,9 +1721,34 @@ export class Telegram implements INodeType {
|
|||
}
|
||||
|
||||
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
|
||||
returnData.push(responseData);
|
||||
|
||||
if (resource === 'file' && operation === 'get') {
|
||||
if (this.getNodeParameter('download', i, false) as boolean === true) {
|
||||
const filePath = responseData.result.file_path;
|
||||
|
||||
const credentials = this.getCredentials('telegramApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
const file = await apiRequest.call(this, 'GET', '', {}, {}, { json: false, encoding: null, uri: `https://api.telegram.org/file/bot${credentials.accessToken}/${filePath}`, resolveWithFullResponse: true });
|
||||
|
||||
const fileName = filePath.split('/').pop();
|
||||
const binaryData = await this.helpers.prepareBinaryData(Buffer.from(file.body as string), fileName);
|
||||
|
||||
returnData.push({
|
||||
json: responseData,
|
||||
binary: {
|
||||
data: binaryData,
|
||||
},
|
||||
});
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
returnData.push({ json: responseData });
|
||||
}
|
||||
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
return this.prepareOutputData(returnData);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ export class TelegramTrigger implements INodeType {
|
|||
name: 'download',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: `Telegram develiers the image in 3 sizes.<br>
|
||||
description: `Telegram delivers the image in 3 sizes.<br>
|
||||
By default, just the larger image would be downloaded.<br>
|
||||
if you want to change the size set the field 'Image Size'`,
|
||||
},
|
||||
|
@ -225,7 +225,6 @@ export class TelegramTrigger implements INodeType {
|
|||
if (additionalFields.imageSize) {
|
||||
|
||||
imageSize = additionalFields.imageSize as string;
|
||||
|
||||
}
|
||||
|
||||
let fileId;
|
||||
|
|
Loading…
Reference in a new issue