mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
This commit is contained in:
@@ -5,15 +5,9 @@ import {
|
||||
IWebhookFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
NodeApiError,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
import { IDataObject, NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
// Interface in n8n
|
||||
export interface IMarkupKeyboard {
|
||||
@@ -33,7 +27,6 @@ export interface IMarkupKeyboardButton {
|
||||
additionalFields?: IDataObject;
|
||||
}
|
||||
|
||||
|
||||
// Interface in Telegram
|
||||
export interface ITelegramInlineReply {
|
||||
inline_keyboard?: ITelegramKeyboardButton[][];
|
||||
@@ -47,7 +40,6 @@ export interface ITelegramReplyKeyboard extends IMarkupReplyKeyboardOptions {
|
||||
keyboard: ITelegramKeyboardButton[][];
|
||||
}
|
||||
|
||||
|
||||
// Shared interfaces
|
||||
export interface IMarkupForceReply {
|
||||
force_reply?: boolean;
|
||||
@@ -65,7 +57,6 @@ export interface IMarkupReplyKeyboardRemove {
|
||||
selective?: boolean;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add the additional fields to the body
|
||||
*
|
||||
@@ -90,7 +81,11 @@ export function addAdditionalFields(this: IExecuteFunctions, body: IDataObject,
|
||||
}
|
||||
}
|
||||
|
||||
body.reply_markup = {} as IMarkupForceReply | IMarkupReplyKeyboardRemove | ITelegramInlineReply | ITelegramReplyKeyboard;
|
||||
body.reply_markup = {} as
|
||||
| IMarkupForceReply
|
||||
| IMarkupReplyKeyboardRemove
|
||||
| ITelegramInlineReply
|
||||
| ITelegramReplyKeyboard;
|
||||
if (['inlineKeyboard', 'replyKeyboard'].includes(replyMarkupOption)) {
|
||||
let setParameterName = 'inline_keyboard';
|
||||
if (replyMarkupOption === 'replyKeyboard') {
|
||||
@@ -100,7 +95,8 @@ export function addAdditionalFields(this: IExecuteFunctions, body: IDataObject,
|
||||
const keyboardData = this.getNodeParameter(replyMarkupOption, index) as IMarkupKeyboard;
|
||||
|
||||
// @ts-ignore
|
||||
(body.reply_markup as ITelegramInlineReply | ITelegramReplyKeyboard)[setParameterName] = [] as ITelegramKeyboardButton[][];
|
||||
(body.reply_markup as ITelegramInlineReply | ITelegramReplyKeyboard)[setParameterName] =
|
||||
[] as ITelegramKeyboardButton[][];
|
||||
let sendButtonData: ITelegramKeyboardButton;
|
||||
if (keyboardData.rows !== undefined) {
|
||||
for (const row of keyboardData.rows) {
|
||||
@@ -117,6 +113,7 @@ export function addAdditionalFields(this: IExecuteFunctions, body: IDataObject,
|
||||
sendRows.push(sendButtonData);
|
||||
}
|
||||
// @ts-ignore
|
||||
// prettier-ignore
|
||||
((body.reply_markup as ITelegramInlineReply | ITelegramReplyKeyboard)[setParameterName] as ITelegramKeyboardButton[][]).push(sendRows);
|
||||
}
|
||||
}
|
||||
@@ -124,17 +121,22 @@ export function addAdditionalFields(this: IExecuteFunctions, body: IDataObject,
|
||||
const forceReply = this.getNodeParameter('forceReply', index) as IMarkupForceReply;
|
||||
body.reply_markup = forceReply;
|
||||
} else if (replyMarkupOption === 'replyKeyboardRemove') {
|
||||
const forceReply = this.getNodeParameter('replyKeyboardRemove', index) as IMarkupReplyKeyboardRemove;
|
||||
const forceReply = this.getNodeParameter(
|
||||
'replyKeyboardRemove',
|
||||
index,
|
||||
) as IMarkupReplyKeyboardRemove;
|
||||
body.reply_markup = forceReply;
|
||||
}
|
||||
|
||||
if (replyMarkupOption === 'replyKeyboard') {
|
||||
const replyKeyboardOptions = this.getNodeParameter('replyKeyboardOptions', index) as IMarkupReplyKeyboardOptions;
|
||||
const replyKeyboardOptions = this.getNodeParameter(
|
||||
'replyKeyboardOptions',
|
||||
index,
|
||||
) as IMarkupReplyKeyboardOptions;
|
||||
Object.assign(body.reply_markup, replyKeyboardOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make an API request to Telegram
|
||||
*
|
||||
@@ -144,7 +146,15 @@ export function addAdditionalFields(this: IExecuteFunctions, body: IDataObject,
|
||||
* @param {object} body
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
export async function apiRequest(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
body: IDataObject,
|
||||
query?: IDataObject,
|
||||
option: IDataObject = {},
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const credentials = await this.getCredentials('telegramApi');
|
||||
|
||||
query = query || {};
|
||||
@@ -178,12 +188,11 @@ export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoa
|
||||
}
|
||||
|
||||
export function getImageBySize(photos: IDataObject[], size: string): IDataObject | undefined {
|
||||
|
||||
const sizes = {
|
||||
'small': 0,
|
||||
'medium': 1,
|
||||
'large': 2,
|
||||
'extraLarge': 3,
|
||||
small: 0,
|
||||
medium: 1,
|
||||
large: 2,
|
||||
extraLarge: 3,
|
||||
} as IDataObject;
|
||||
|
||||
const index = sizes[size] as number;
|
||||
|
||||
Reference in New Issue
Block a user