feat(Telegram Node): New operation sendAndWait (#12771)

This commit is contained in:
Michael Kret
2025-01-24 13:44:05 +02:00
committed by GitHub
parent 5b760e7f7f
commit 2c58d47f8e
8 changed files with 269 additions and 124 deletions

View File

@@ -10,6 +10,8 @@ import type {
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
import { getSendAndWaitConfig } from '../../utils/sendAndWait/utils';
// Interface in n8n
export interface IMarkupKeyboard {
rows?: IMarkupKeyboardRow[];
@@ -252,3 +254,36 @@ export function getSecretToken(this: IHookFunctions | IWebhookFunctions) {
const secret_token = `${this.getWorkflow().id}_${this.getNode().id}`;
return secret_token.replace(/[^a-zA-Z0-9\_\-]+/g, '');
}
export function createSendAndWaitMessageBody(context: IExecuteFunctions) {
const chat_id = context.getNodeParameter('chatId', 0) as string;
const config = getSendAndWaitConfig(context);
let text = config.message;
const instanceId = context.getInstanceId();
const attributionText = 'This message was sent automatically with ';
const link = `https://n8n.io/?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=${encodeURIComponent(
'n8n-nodes-base.telegram',
)}${instanceId ? '_' + instanceId : ''}`;
text = `${text}\n\n_${attributionText}_[n8n](${link})`;
const body = {
chat_id,
text,
disable_web_page_preview: true,
parse_mode: 'Markdown',
reply_markup: {
inline_keyboard: [
config.options.map((option) => {
return {
text: option.label,
url: `${config.url}?approved=${option.value}`,
};
}),
],
},
};
return body;
}