mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 08:34:07 -08:00
⚡ Add File->Get to Telegram Node
This commit is contained in:
parent
1ea9915407
commit
95a9a1eb89
|
@ -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'`,
|
||||
},
|
||||
|
@ -154,20 +154,6 @@ export class TelegramTrigger implements INodeType {
|
|||
default: 'large',
|
||||
description: 'The size of the image to be downloaded',
|
||||
},
|
||||
{
|
||||
displayName: 'Include Download Link',
|
||||
name: 'includeDownloadLink',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
download: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: `When set to true, the download_link will be included in the response.`,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
@ -271,10 +257,6 @@ export class TelegramTrigger implements INodeType {
|
|||
|
||||
const binaryData = await this.helpers.prepareBinaryData(data as unknown as Buffer, fileName);
|
||||
|
||||
if (additionalFields.includeDownloadLink === true) {
|
||||
bodyData['download_link'] = `https://api.telegram.org/file/bot${credentials.accessToken}/${file_path}`;
|
||||
}
|
||||
|
||||
return {
|
||||
workflowData: [
|
||||
[
|
||||
|
|
Loading…
Reference in a new issue