mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat: Human in the loop (#10675)
Co-authored-by: Giulio Andreini <g.andreini@gmail.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import type {
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import get from 'lodash/get';
|
||||
import { getSendAndWaitConfig } from '../../../utils/sendAndWait/utils';
|
||||
|
||||
export async function slackApiRequest(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
|
||||
@@ -219,3 +220,81 @@ export function validateJSON(json: string | undefined): any {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function getTarget(
|
||||
context: IExecuteFunctions,
|
||||
itemIndex: number,
|
||||
idType: 'user' | 'channel',
|
||||
): string {
|
||||
let target = '';
|
||||
|
||||
if (idType === 'channel') {
|
||||
target = context.getNodeParameter('channelId', itemIndex, undefined, {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
} else {
|
||||
target = context.getNodeParameter('user', itemIndex, undefined, {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
}
|
||||
|
||||
if (
|
||||
idType === 'user' &&
|
||||
(context.getNodeParameter('user', itemIndex) as IDataObject).mode === 'username'
|
||||
) {
|
||||
target = target.slice(0, 1) === '@' ? target : `@${target}`;
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
export function createSendAndWaitMessageBody(context: IExecuteFunctions) {
|
||||
const select = context.getNodeParameter('select', 0) as 'user' | 'channel';
|
||||
const target = getTarget(context, 0, select);
|
||||
|
||||
const config = getSendAndWaitConfig(context);
|
||||
|
||||
const body: IDataObject = {
|
||||
channel: target,
|
||||
blocks: [
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
type: 'section',
|
||||
text: {
|
||||
type: 'plain_text',
|
||||
text: config.message,
|
||||
emoji: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'section',
|
||||
text: {
|
||||
type: 'plain_text',
|
||||
text: ' ',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
type: 'actions',
|
||||
elements: config.options.map((option) => {
|
||||
return {
|
||||
type: 'button',
|
||||
style: option.style === 'primary' ? 'primary' : undefined,
|
||||
text: {
|
||||
type: 'plain_text',
|
||||
text: option.label,
|
||||
emoji: true,
|
||||
},
|
||||
url: `${config.url}?approved=${option.value}`,
|
||||
};
|
||||
}),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user