mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat(Telegram Node): New operation sendAndWait (#12771)
This commit is contained in:
@@ -6,11 +6,27 @@ import type {
|
||||
INodeTypeDescription,
|
||||
IHttpRequestMethods,
|
||||
} from 'n8n-workflow';
|
||||
import { BINARY_ENCODING, NodeConnectionType, NodeOperationError } from 'n8n-workflow';
|
||||
import {
|
||||
BINARY_ENCODING,
|
||||
SEND_AND_WAIT_OPERATION,
|
||||
NodeConnectionType,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
import type { Readable } from 'stream';
|
||||
|
||||
import { addAdditionalFields, apiRequest, getPropertyName } from './GenericFunctions';
|
||||
import {
|
||||
addAdditionalFields,
|
||||
apiRequest,
|
||||
createSendAndWaitMessageBody,
|
||||
getPropertyName,
|
||||
} from './GenericFunctions';
|
||||
import { appendAttributionOption } from '../../utils/descriptions';
|
||||
import { sendAndWaitWebhooks } from '../../utils/sendAndWait/descriptions';
|
||||
import {
|
||||
configureWaitTillDate,
|
||||
getSendAndWaitProperties,
|
||||
sendAndWaitWebhook,
|
||||
} from '../../utils/sendAndWait/utils';
|
||||
|
||||
export class Telegram implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -33,6 +49,7 @@ export class Telegram implements INodeType {
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
webhooks: sendAndWaitWebhooks,
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
@@ -263,6 +280,12 @@ export class Telegram implements INodeType {
|
||||
description: 'Send a text message',
|
||||
action: 'Send a text message',
|
||||
},
|
||||
{
|
||||
name: 'Send and Wait for Response',
|
||||
value: SEND_AND_WAIT_OPERATION,
|
||||
description: 'Send a message and wait for response',
|
||||
action: 'Send message and wait for response',
|
||||
},
|
||||
{
|
||||
name: 'Send Photo',
|
||||
value: 'sendPhoto',
|
||||
@@ -1735,9 +1758,31 @@ export class Telegram implements INodeType {
|
||||
},
|
||||
],
|
||||
},
|
||||
...getSendAndWaitProperties(
|
||||
[
|
||||
{
|
||||
displayName: 'Chat ID',
|
||||
name: 'chatId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
description:
|
||||
'Unique identifier for the target chat or username of the target channel (in the format @channelusername). To find your chat ID ask @get_id_bot.',
|
||||
},
|
||||
],
|
||||
'message',
|
||||
undefined,
|
||||
{
|
||||
noButtonStyle: true,
|
||||
defaultApproveLabel: '✅ Approve',
|
||||
defaultDisapproveLabel: '❌ Decline',
|
||||
},
|
||||
).filter((p) => p.name !== 'subject'),
|
||||
],
|
||||
};
|
||||
|
||||
webhook = sendAndWaitWebhook;
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
@@ -1757,6 +1802,17 @@ export class Telegram implements INodeType {
|
||||
const nodeVersion = this.getNode().typeVersion;
|
||||
const instanceId = this.getInstanceId();
|
||||
|
||||
if (resource === 'message' && operation === SEND_AND_WAIT_OPERATION) {
|
||||
body = createSendAndWaitMessageBody(this);
|
||||
|
||||
await apiRequest.call(this, 'POST', 'sendMessage', body);
|
||||
|
||||
const waitTill = configureWaitTillDate(this);
|
||||
|
||||
await this.putExecutionToWait(waitTill);
|
||||
return [this.getInputData()];
|
||||
}
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
// Reset all values
|
||||
|
||||
Reference in New Issue
Block a user