mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
✨ Add "sendMediaGroup" functionality to Telegram-Node #135
This commit is contained in:
parent
784aa25df8
commit
1d0a886d8b
|
@ -73,10 +73,15 @@ export function addAdditionalFields(this: IExecuteFunctions, body: IDataObject,
|
||||||
const additionalFields = this.getNodeParameter('additionalFields', index) as IDataObject;
|
const additionalFields = this.getNodeParameter('additionalFields', index) as IDataObject;
|
||||||
Object.assign(body, additionalFields);
|
Object.assign(body, additionalFields);
|
||||||
|
|
||||||
|
const operation = this.getNodeParameter('operation', index) as string;
|
||||||
|
|
||||||
// Add the reply markup
|
// Add the reply markup
|
||||||
const replyMarkupOption = this.getNodeParameter('replyMarkup', index) as string;
|
let replyMarkupOption = '';
|
||||||
if (replyMarkupOption === 'none') {
|
if (operation !== 'sendMediaGroup') {
|
||||||
return;
|
replyMarkupOption = this.getNodeParameter('replyMarkup', index) as string;
|
||||||
|
if (replyMarkupOption === 'none') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
body.reply_markup = {} as IMarkupForceReply | IMarkupReplyKeyboardRemove | ITelegramInlineReply | ITelegramReplyKeyboard;
|
body.reply_markup = {} as IMarkupForceReply | IMarkupReplyKeyboardRemove | ITelegramInlineReply | ITelegramReplyKeyboard;
|
||||||
|
|
|
@ -166,6 +166,11 @@ export class Telegram implements INodeType {
|
||||||
value: 'sendMessage',
|
value: 'sendMessage',
|
||||||
description: 'Send a text message',
|
description: 'Send a text message',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Send Media Group',
|
||||||
|
value: 'sendMediaGroup',
|
||||||
|
description: 'Send group of photos or videos to album',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Send Photo',
|
name: 'Send Photo',
|
||||||
value: 'sendPhoto',
|
value: 'sendPhoto',
|
||||||
|
@ -208,6 +213,7 @@ export class Telegram implements INodeType {
|
||||||
'sendChatAction',
|
'sendChatAction',
|
||||||
'sendDocument',
|
'sendDocument',
|
||||||
'sendMessage',
|
'sendMessage',
|
||||||
|
'sendMediaGroup',
|
||||||
'sendPhoto',
|
'sendPhoto',
|
||||||
'sendSticker',
|
'sendSticker',
|
||||||
'sendVideo',
|
'sendVideo',
|
||||||
|
@ -617,6 +623,100 @@ export class Telegram implements INodeType {
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// message:sendMediaGroup
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Media',
|
||||||
|
name: 'media',
|
||||||
|
type: 'fixedCollection',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'sendMediaGroup'
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'message',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'The media to add.',
|
||||||
|
placeholder: 'Add Media',
|
||||||
|
typeOptions: {
|
||||||
|
multipleValues: true,
|
||||||
|
},
|
||||||
|
default: {},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Media',
|
||||||
|
name: 'media',
|
||||||
|
values: [
|
||||||
|
{
|
||||||
|
displayName: 'Type',
|
||||||
|
name: 'type',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Photo',
|
||||||
|
value: 'photo',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Video',
|
||||||
|
value: 'video',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'photo',
|
||||||
|
description: 'The type of the media to add.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Media File',
|
||||||
|
name: 'media',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'Media to send. Pass a file_id to send a file that exists on the Telegram servers (recommended)<br />or pass an HTTP URL for Telegram to get a file from the Internet.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Additional Fields',
|
||||||
|
name: 'additionalFields',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Add Field',
|
||||||
|
default: {},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Caption',
|
||||||
|
name: 'caption',
|
||||||
|
type: 'string',
|
||||||
|
typeOptions: {
|
||||||
|
alwaysOpenEditWindow: true,
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: 'Caption text to set, 0-1024 characters.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Parse Mode',
|
||||||
|
name: 'parse_mode',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Markdown',
|
||||||
|
value: 'Markdown',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'HTML',
|
||||||
|
value: 'HTML',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'HTML',
|
||||||
|
description: 'How to parse the text.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// message:sendMessage
|
// message:sendMessage
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
@ -1049,6 +1149,7 @@ export class Telegram implements INodeType {
|
||||||
'editMessageText',
|
'editMessageText',
|
||||||
'sendDocument',
|
'sendDocument',
|
||||||
'sendMessage',
|
'sendMessage',
|
||||||
|
'sendMediaGroup',
|
||||||
'sendPhoto',
|
'sendPhoto',
|
||||||
'sendSticker',
|
'sendSticker',
|
||||||
'sendVideo',
|
'sendVideo',
|
||||||
|
@ -1417,6 +1518,28 @@ export class Telegram implements INodeType {
|
||||||
// Add additional fields and replyMarkup
|
// Add additional fields and replyMarkup
|
||||||
addAdditionalFields.call(this, body, i);
|
addAdditionalFields.call(this, body, i);
|
||||||
|
|
||||||
|
} else if (operation === 'sendMediaGroup') {
|
||||||
|
// ----------------------------------
|
||||||
|
// message:sendMediaGroup
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
|
endpoint = 'sendMediaGroup';
|
||||||
|
|
||||||
|
body.chat_id = this.getNodeParameter('chatId', i) as string;
|
||||||
|
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
Object.assign(body, additionalFields);
|
||||||
|
|
||||||
|
const mediaItems = this.getNodeParameter('media', i) as IDataObject;
|
||||||
|
body.media = [];
|
||||||
|
for (const mediaItem of mediaItems.media as IDataObject[]) {
|
||||||
|
if (mediaItem.additionalFields !== undefined) {
|
||||||
|
Object.assign(mediaItem, mediaItem.additionalFields);
|
||||||
|
delete mediaItem.additionalFields;
|
||||||
|
}
|
||||||
|
(body.media as IDataObject[]).push(mediaItem);
|
||||||
|
}
|
||||||
|
|
||||||
} else if (operation === 'sendPhoto') {
|
} else if (operation === 'sendPhoto') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// message:sendPhoto
|
// message:sendPhoto
|
||||||
|
|
Loading…
Reference in a new issue