first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled

This commit is contained in:
2026-03-17 16:22:57 +03:30
commit 3d5eaf9445
15349 changed files with 2847338 additions and 0 deletions
@@ -0,0 +1,408 @@
import type { INodeProperties } from 'n8n-workflow';
export const channelOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['channel'],
},
},
options: [
{
name: 'Archive',
value: 'archive',
description: 'Archive a channel',
action: 'Archive a channel',
},
{
name: 'Create',
value: 'create',
description: 'Initiates a public or private channel-based conversation',
action: 'Create a channel',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a channel',
action: 'Delete a channel',
},
{
name: 'Get',
value: 'get',
description: 'Get information about a channel',
action: 'Get a channel',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many channels',
action: 'Get many channels',
},
{
name: 'Unarchive',
value: 'unarchive',
description: 'Unarchive a channel',
action: 'Unarchive a channel',
},
{
name: 'Update',
value: 'update',
description: 'Update a channel',
action: 'Update a channel',
},
],
default: 'create',
},
];
export const channelFields: INodeProperties[] = [
/*-------------------------------------------------------------------------- */
/* channel:create */
/* ------------------------------------------------------------------------- */
{
displayName: 'Workspace Name or ID',
name: 'workspaceId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getWorkspaces',
},
default: '',
displayOptions: {
show: {
operation: ['create'],
resource: ['channel'],
},
},
required: true,
description:
'The ID of the workspace. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['create'],
resource: ['channel'],
},
},
required: true,
description: 'The name of the channel',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['channel'],
operation: ['create'],
},
},
options: [
{
displayName: 'Color',
name: 'color',
type: 'options',
options: [
{
name: 'Berry Red',
value: 6,
},
{
name: 'Blue',
value: 1,
},
{
name: 'Green',
value: 4,
},
{
name: 'Grey',
value: 0,
},
{
name: 'Magenta',
value: 7,
},
{
name: 'Mint Green',
value: 9,
},
{
name: 'Red',
value: 5,
},
{
name: 'Salmon',
value: 11,
},
{
name: 'Sky Blue',
value: 8,
},
{
name: 'Teal Blue',
value: 3,
},
{
name: 'Turquoise',
value: 2,
},
{
name: 'Yellow',
value: 10,
},
],
default: 0,
description: 'The color of the channel',
},
{
displayName: 'Description',
name: 'description',
type: 'string',
default: '',
description: 'The description of the channel',
},
{
displayName: 'Public',
name: 'public',
type: 'boolean',
default: false,
description: 'Whether the channel will be marked as public',
},
{
displayName: 'Temp ID',
name: 'temp_id',
type: 'number',
default: -1,
description: 'The temporary ID of the channel. It needs to be a negative number.',
},
{
displayName: 'User Names or IDs',
name: 'user_ids',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getUsers',
loadOptionsDependsOn: ['workspaceId'],
},
default: [],
description:
'The users that will participate in the channel. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
],
},
/* -------------------------------------------------------------------------- */
/* channel:get/archive/unarchive/delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Channel ID',
name: 'channelId',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['archive', 'delete', 'get', 'unarchive'],
resource: ['channel'],
},
},
required: true,
description: 'The ID of the channel',
},
/* -------------------------------------------------------------------------- */
/* channel:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Workspace Name or ID',
name: 'workspaceId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getWorkspaces',
},
default: '',
displayOptions: {
show: {
operation: ['getAll'],
resource: ['channel'],
},
},
required: true,
description:
'The ID of the workspace. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: ['channel'],
operation: ['getAll'],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: ['channel'],
operation: ['getAll'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 100,
},
default: 50,
description: 'Max number of results to return',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['channel'],
operation: ['getAll'],
},
},
options: [
{
displayName: 'Archived',
name: 'archived',
type: 'boolean',
default: false,
description: 'Whether only archived conversations are returned',
},
],
},
/* -------------------------------------------------------------------------- */
/* channel:update */
/* -------------------------------------------------------------------------- */
{
displayName: 'Channel ID',
name: 'channelId',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['update'],
resource: ['channel'],
},
},
required: true,
description: 'The ID of the channel',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['channel'],
operation: ['update'],
},
},
options: [
{
displayName: 'Color',
name: 'color',
type: 'options',
options: [
{
name: 'Berry Red',
value: 6,
},
{
name: 'Blue',
value: 1,
},
{
name: 'Green',
value: 4,
},
{
name: 'Grey',
value: 0,
},
{
name: 'Magenta',
value: 7,
},
{
name: 'Mint Green',
value: 9,
},
{
name: 'Red',
value: 5,
},
{
name: 'Salmon',
value: 11,
},
{
name: 'Sky Blue',
value: 8,
},
{
name: 'Teal Blue',
value: 3,
},
{
name: 'Turquoise',
value: 2,
},
{
name: 'Yellow',
value: 10,
},
],
default: 0,
description: 'The color of the channel',
},
{
displayName: 'Description',
name: 'description',
type: 'string',
default: '',
description: 'The description of the channel',
},
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'The name of the channel',
},
{
displayName: 'Public',
name: 'public',
type: 'boolean',
default: false,
description: 'Whether the channel will be marked as public',
},
],
},
];
@@ -0,0 +1,512 @@
import type { INodeProperties } from 'n8n-workflow';
export const commentOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['comment'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a new comment to a thread',
action: 'Create a comment',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a comment',
action: 'Delete a comment',
},
{
name: 'Get',
value: 'get',
description: 'Get information about a comment',
action: 'Get a comment',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many comments',
action: 'Get many comments',
},
{
name: 'Update',
value: 'update',
description: 'Update a comment',
action: 'Update a comment',
},
],
default: 'create',
},
];
export const commentFields: INodeProperties[] = [
/*-------------------------------------------------------------------------- */
/* comment:create */
/* ------------------------------------------------------------------------- */
{
displayName: 'Thread ID',
name: 'threadId',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['create'],
resource: ['comment'],
},
},
required: true,
description: 'The ID of the thread',
},
{
displayName: 'Content',
name: 'content',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['create'],
resource: ['comment'],
},
},
required: true,
description: 'The content of the comment',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['comment'],
operation: ['create'],
},
},
options: [
{
displayName: 'Actions',
name: 'actionsUi',
type: 'fixedCollection',
default: {},
placeholder: 'Add Action',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Action',
name: 'actionValues',
values: [
{
displayName: 'Action',
name: 'action',
type: 'options',
description: 'The action of the button',
options: [
{
name: 'Open URL',
value: 'open_url',
},
{
name: 'Prefill Message',
value: 'prefill_message',
},
{
name: 'Send Reply',
value: 'send_reply',
},
],
default: '',
},
{
displayName: 'Button Text',
name: 'button_text',
type: 'string',
description: 'The text for the action button',
default: '',
},
{
displayName: 'Message',
name: 'message',
type: 'string',
displayOptions: {
show: {
action: ['send_reply', 'prefill_message'],
},
},
description: 'The text for the action button',
default: '',
},
{
displayName: 'Type',
name: 'type',
type: 'options',
description:
'The type of the button. (Currently only <code>action</code> is available).',
options: [
{
name: 'Action',
value: 'action',
},
],
default: '',
},
{
displayName: 'URL',
name: 'url',
type: 'string',
displayOptions: {
show: {
action: ['open_url'],
},
},
description: 'URL to redirect',
default: '',
},
],
},
],
},
{
displayName: 'Attachments',
name: 'binaryProperties',
type: 'string',
default: 'data',
description:
'Name of the property that holds the binary data. Multiple can be defined separated by comma.',
},
{
displayName: 'Direct Mention Names or IDs',
name: 'direct_mentions',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getUsers',
loadOptionsDependsOn: ['workspaceId'],
},
default: [],
description:
'The users that are directly mentioned. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Mark Thread Position',
name: 'mark_thread_position',
type: 'boolean',
default: true,
description: 'Whether the position of the thread is marked',
},
{
displayName: 'Recipient Names or IDs',
name: 'recipients',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getUsers',
loadOptionsDependsOn: ['workspaceId'],
},
default: [],
description:
'The users that will attached to the comment. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Temporary ID',
name: 'temp_id',
type: 'number',
default: 0,
description: 'The temporary ID of the comment',
},
{
displayName: 'Send as Integration',
name: 'send_as_integration',
type: 'boolean',
default: false,
description: 'Whether to display the integration as the comment creator',
},
],
},
/* -------------------------------------------------------------------------- */
/* comment:get/delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Comment ID',
name: 'commentId',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['get', 'delete'],
resource: ['comment'],
},
},
required: true,
description: 'The ID of the comment',
},
/* -------------------------------------------------------------------------- */
/* comment:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Thread ID',
name: 'threadId',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['getAll'],
resource: ['comment'],
},
},
required: true,
description: 'The ID of the channel',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: ['comment'],
operation: ['getAll'],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: ['comment'],
operation: ['getAll'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 100,
},
default: 50,
description: 'Max number of results to return',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['comment'],
operation: ['getAll'],
},
},
options: [
{
displayName: 'As IDs',
name: 'as_ids',
type: 'boolean',
default: false,
description: 'Whether only the IDs of the comments are returned',
},
{
displayName: 'Ending Object Index',
name: 'to_obj_index',
type: 'number',
default: 50,
description: 'Limit comments ending at the specified object index',
},
{
displayName: 'Newer Than',
name: 'newer_than_ts',
type: 'dateTime',
default: '',
description: 'Limits comments to those newer when the specified Unix time',
},
{
displayName: 'Older Than',
name: 'older_than_ts',
type: 'dateTime',
default: '',
description: 'Limits comments to those older than the specified Unix time',
},
{
displayName: 'Order By',
name: 'order_by',
type: 'options',
options: [
{
name: 'ASC',
value: 'ASC',
},
{
name: 'DESC',
value: 'DESC',
},
],
default: 'ASC',
description: 'The order of the comments returned - one of DESC or ASC',
},
{
displayName: 'Starting Object Index',
name: 'from_obj_index',
type: 'number',
default: 0,
description: 'Limit comments starting at the specified object index',
},
],
},
/* -------------------------------------------------------------------------- */
/* comment:update */
/* -------------------------------------------------------------------------- */
{
displayName: 'Comment ID',
name: 'commentId',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['update'],
resource: ['comment'],
},
},
required: true,
description: 'The ID of the comment',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['comment'],
operation: ['update'],
},
},
options: [
{
displayName: 'Actions',
name: 'actionsUi',
type: 'fixedCollection',
default: {},
placeholder: 'Add Action',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Action',
name: 'actionValues',
values: [
{
displayName: 'Action',
name: 'action',
type: 'options',
description: 'The action of the button',
options: [
{
name: 'Open URL',
value: 'open_url',
},
{
name: 'Prefill Message',
value: 'prefill_message',
},
{
name: 'Send Reply',
value: 'send_reply',
},
],
default: '',
},
{
displayName: 'Button Text',
name: 'button_text',
type: 'string',
description: 'The text for the action button',
default: '',
},
{
displayName: 'Message',
name: 'message',
type: 'string',
displayOptions: {
show: {
action: ['send_reply', 'prefill_message'],
},
},
description: 'The text for the action button',
default: '',
},
{
displayName: 'Type',
name: 'type',
type: 'options',
description:
'The type of the button. (Currently only <code>action</code> is available).',
options: [
{
name: 'Action',
value: 'action',
},
],
default: '',
},
{
displayName: 'URL',
name: 'url',
type: 'string',
displayOptions: {
show: {
action: ['open_url'],
},
},
description: 'URL to redirect',
default: '',
},
],
},
],
},
{
displayName: 'Attachments',
name: 'binaryProperties',
type: 'string',
default: 'data',
description:
'Name of the property that holds the binary data. Multiple can be defined separated by comma.',
},
{
displayName: 'Content',
name: 'content',
type: 'string',
default: '',
description: 'The content of the comment',
},
{
displayName: 'Direct Mention Names or IDs',
name: 'direct_mentions',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getUsers',
loadOptionsDependsOn: ['workspaceId'],
},
default: [],
description:
'The users that are directly mentioned. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
],
},
];
@@ -0,0 +1,42 @@
import type {
IExecuteFunctions,
ILoadOptionsFunctions,
IDataObject,
JsonObject,
IHttpRequestMethods,
IRequestOptions,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
export async function twistApiRequest(
this: IExecuteFunctions | ILoadOptionsFunctions,
method: IHttpRequestMethods,
endpoint: string,
body: IDataObject = {},
qs: IDataObject = {},
option: IDataObject = {},
) {
const options: IRequestOptions = {
method,
body,
qs,
uri: `https://api.twist.com/api/v3${endpoint}`,
json: true,
};
if (Object.keys(body).length === 0) {
delete options.body;
}
if (Object.keys(qs).length === 0) {
delete options.qs;
}
Object.assign(options, option);
try {
return await this.helpers.requestOAuth2.call(this, 'twistOAuth2Api', options);
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
}
}
@@ -0,0 +1,493 @@
import type { INodeProperties } from 'n8n-workflow';
export const messageConversationOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['messageConversation'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a message in a conversation',
action: 'Create a message',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a message in a conversation',
action: 'Delete a message',
},
{
name: 'Get',
value: 'get',
description: 'Get a message in a conversation',
action: 'Get a message',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many messages in a conversation',
action: 'Get many messages',
},
{
name: 'Update',
value: 'update',
description: 'Update a message in a conversation',
action: 'Update a message',
},
],
default: 'create',
},
];
export const messageConversationFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* messageConversation:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'Workspace Name or ID',
name: 'workspaceId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getWorkspaces',
},
default: '',
displayOptions: {
show: {
operation: ['create'],
resource: ['messageConversation'],
},
},
required: true,
description:
'The ID of the workspace. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Conversation Name or ID',
name: 'conversationId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getConversations',
loadOptionsDependsOn: ['workspaceId'],
},
default: '',
displayOptions: {
show: {
operation: ['create'],
resource: ['messageConversation'],
},
},
required: true,
description:
'The ID of the conversation. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Content',
name: 'content',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['create'],
resource: ['messageConversation'],
},
},
description:
'The content of the new message. Mentions can be used as <code>[Name](twist-mention://user_id)</code> for users or <code>[Group name](twist-group-mention://group_id)</code> for groups.',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
displayOptions: {
show: {
operation: ['create'],
resource: ['messageConversation'],
},
},
default: {},
description: 'Other options to set',
placeholder: 'Add option',
options: [
{
displayName: 'Actions',
name: 'actionsUi',
type: 'fixedCollection',
default: {},
placeholder: 'Add Action',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Action',
name: 'actionValues',
values: [
{
displayName: 'Action',
name: 'action',
type: 'options',
description: 'The action of the button',
options: [
{
name: 'Open URL',
value: 'open_url',
},
{
name: 'Prefill Message',
value: 'prefill_message',
},
{
name: 'Send Reply',
value: 'send_reply',
},
],
default: '',
},
{
displayName: 'Button Text',
name: 'button_text',
type: 'string',
description: 'The text for the action button',
default: '',
},
{
displayName: 'Message',
name: 'message',
type: 'string',
displayOptions: {
show: {
action: ['send_reply', 'prefill_message'],
},
},
description: 'The text for the action button',
default: '',
},
{
displayName: 'Type',
name: 'type',
type: 'options',
description:
'The type of the button. (Currently only <code>action</code> is available).',
options: [
{
name: 'Action',
value: 'action',
},
],
default: '',
},
{
displayName: 'URL',
name: 'url',
type: 'string',
displayOptions: {
show: {
action: ['open_url'],
},
},
description: 'URL to redirect',
default: '',
},
],
},
],
},
{
displayName: 'Attachments',
name: 'binaryProperties',
type: 'string',
default: 'data',
description:
'Name of the property that holds the binary data. Multiple can be defined separated by comma.',
},
{
displayName: 'Direct Mention Names or IDs',
name: 'direct_mentions',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getUsers',
},
default: [],
description:
'The users that are directly mentioned. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
// {
// displayName: 'Direct Group Mentions ',
// name: 'direct_group_mentions',
// type: 'multiOptions',
// typeOptions: {
// loadOptionsMethod: 'getGroups',
// },
// default: [],
// description: 'The groups that are directly mentioned.',
// },
],
},
/* -------------------------------------------------------------------------- */
/* messageConversation:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Workspace Name or ID',
name: 'workspaceId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getWorkspaces',
},
default: '',
displayOptions: {
show: {
operation: ['getAll'],
resource: ['messageConversation'],
},
},
required: true,
description:
'The ID of the workspace. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Conversation Name or ID',
name: 'conversationId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getConversations',
loadOptionsDependsOn: ['workspaceId'],
},
default: '',
displayOptions: {
show: {
operation: ['getAll'],
resource: ['messageConversation'],
},
},
required: true,
description:
'The ID of the conversation. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
displayOptions: {
show: {
operation: ['getAll'],
resource: ['messageConversation'],
},
},
default: {},
description: 'Other options to set',
options: [
{
displayName: 'Ending Object Index',
name: 'to_obj_index',
type: 'number',
default: 50,
description: 'Limit messages ending at the specified object index',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
typeOptions: {
minValue: 1,
},
default: 50,
description: 'Max number of results to return',
},
{
displayName: 'Order By',
name: 'order_by',
type: 'options',
default: 'ASC',
description: 'The order of the conversations returned - one of DESC or ASC',
options: [
{
name: 'ASC',
value: 'ASC',
},
{
name: 'DESC',
value: 'DESC',
},
],
},
{
displayName: 'Starting Object Index',
name: 'from_obj_index',
type: 'number',
default: 0,
description: 'Limit messages starting at the specified object index',
},
],
},
/* -------------------------------------------------------------------------- */
/* messageConversation:get/delete/update */
/* -------------------------------------------------------------------------- */
{
displayName: 'Message ID',
name: 'id',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['delete', 'get'],
resource: ['messageConversation'],
},
},
required: true,
description: 'The ID of the conversation message',
},
/* -------------------------------------------------------------------------- */
/* messageConversation:update */
/* -------------------------------------------------------------------------- */
{
displayName: 'Conversation Message ID',
name: 'id',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['update'],
resource: ['messageConversation'],
},
},
required: true,
description: 'The ID of the conversation message',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
displayOptions: {
show: {
operation: ['update'],
resource: ['messageConversation'],
},
},
default: {},
description: 'Other options to set',
options: [
{
displayName: 'Actions',
name: 'actionsUi',
type: 'fixedCollection',
default: {},
placeholder: 'Add Action',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Action',
name: 'actionValues',
values: [
{
displayName: 'Action',
name: 'action',
type: 'options',
description: 'The action of the button',
options: [
{
name: 'Open URL',
value: 'open_url',
},
{
name: 'Prefill Message',
value: 'prefill_message',
},
{
name: 'Send Reply',
value: 'send_reply',
},
],
default: '',
},
{
displayName: 'Button Text',
name: 'button_text',
type: 'string',
description: 'The text for the action button',
default: '',
},
{
displayName: 'Message',
name: 'message',
type: 'string',
displayOptions: {
show: {
action: ['send_reply', 'prefill_message'],
},
},
description: 'The text for the action button',
default: '',
},
{
displayName: 'Type',
name: 'type',
type: 'options',
description:
'The type of the button. (Currently only <code>action</code> is available).',
options: [
{
name: 'Action',
value: 'action',
},
],
default: '',
},
{
displayName: 'URL',
name: 'url',
type: 'string',
displayOptions: {
show: {
action: ['open_url'],
},
},
description: 'URL to redirect',
default: '',
},
],
},
],
},
{
displayName: 'Attachments',
name: 'binaryProperties',
type: 'string',
default: 'data',
description:
'Name of the property that holds the binary data. Multiple can be defined separated by comma.',
},
{
displayName: 'Content',
name: 'content',
type: 'string',
default: '',
description:
'The content of the new message. Mentions can be used as <code>[Name](twist-mention://user_id)</code> for users or <code>[Group name](twist-group-mention://group_id)</code> for groups.',
},
{
displayName: 'Direct Mention Names or IDs',
name: 'direct_mentions',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getUsers',
},
default: [],
description:
'The users that are directly mentioned. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
],
},
];
@@ -0,0 +1,515 @@
import type { INodeProperties } from 'n8n-workflow';
export const threadOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['thread'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a new thread in a channel',
action: 'Create a thread',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a thread',
action: 'Delete a thread',
},
{
name: 'Get',
value: 'get',
description: 'Get information about a thread',
action: 'Get a thread',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many threads',
action: 'Get many threads',
},
{
name: 'Update',
value: 'update',
description: 'Update a thread',
action: 'Update a thread',
},
],
default: 'create',
},
];
export const threadFields: INodeProperties[] = [
/*-------------------------------------------------------------------------- */
/* thread:create */
/* ------------------------------------------------------------------------- */
{
displayName: 'Channel ID',
name: 'channelId',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['create'],
resource: ['thread'],
},
},
required: true,
description: 'The ID of the channel',
},
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['create'],
resource: ['thread'],
},
},
required: true,
description: 'The title of the new thread (1 < length < 300)',
},
{
displayName: 'Content',
name: 'content',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['create'],
resource: ['thread'],
},
},
required: true,
description: 'The content of the thread',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['thread'],
operation: ['create'],
},
},
options: [
{
displayName: 'Actions',
name: 'actionsUi',
type: 'fixedCollection',
default: {},
placeholder: 'Add Action',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Action',
name: 'actionValues',
values: [
{
displayName: 'Action',
name: 'action',
type: 'options',
description: 'The action of the button',
options: [
{
name: 'Open URL',
value: 'open_url',
},
{
name: 'Prefill Message',
value: 'prefill_message',
},
{
name: 'Send Reply',
value: 'send_reply',
},
],
default: '',
},
{
displayName: 'Button Text',
name: 'button_text',
type: 'string',
description: 'The text for the action button',
default: '',
},
{
displayName: 'Message',
name: 'message',
type: 'string',
displayOptions: {
show: {
action: ['send_reply', 'prefill_message'],
},
},
description: 'The text for the action button',
default: '',
},
{
displayName: 'Type',
name: 'type',
type: 'options',
description:
'The type of the button. (Currently only <code>action</code> is available).',
options: [
{
name: 'Action',
value: 'action',
},
],
default: '',
},
{
displayName: 'URL',
name: 'url',
type: 'string',
displayOptions: {
show: {
action: ['open_url'],
},
},
description: 'URL to redirect',
default: '',
},
],
},
],
},
{
displayName: 'Attachments',
name: 'binaryProperties',
type: 'string',
default: 'data',
description:
'Name of the property that holds the binary data. Multiple can be defined separated by comma.',
},
{
displayName: 'Direct Mention Names or IDs',
name: 'direct_mentions',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getUsers',
loadOptionsDependsOn: ['workspaceId'],
},
default: [],
description:
'The users that are directly mentioned. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Recipient Names or IDs',
name: 'recipients',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getUsers',
loadOptionsDependsOn: ['workspaceId'],
},
default: [],
description:
'The users that will attached to the thread. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Send as Integration',
name: 'send_as_integration',
type: 'boolean',
default: false,
description: 'Whether to display the integration as the thread creator',
},
{
displayName: 'Temporary ID',
name: 'temp_id',
type: 'number',
default: 0,
description: 'The temporary ID of the thread',
},
],
},
/* -------------------------------------------------------------------------- */
/* thread:get/delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Thread ID',
name: 'threadId',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['get', 'delete'],
resource: ['thread'],
},
},
required: true,
description: 'The ID of the thread',
},
/* -------------------------------------------------------------------------- */
/* thread:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Channel ID',
name: 'channelId',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['getAll'],
resource: ['thread'],
},
},
required: true,
description: 'The ID of the channel',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: ['thread'],
operation: ['getAll'],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: ['thread'],
operation: ['getAll'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 100,
},
default: 50,
description: 'Max number of results to return',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['thread'],
operation: ['getAll'],
},
},
options: [
{
displayName: 'As IDs',
name: 'as_ids',
type: 'boolean',
default: false,
description: 'Whether only the IDs of the threads are returned',
},
{
displayName: 'Filter By',
name: 'filter_by',
type: 'options',
options: [
{
name: 'Attached to Me',
value: 'attached_to_me',
},
{
name: 'Everyone',
value: 'everyone',
},
{
name: 'Starred',
value: 'is_starred',
},
],
default: '',
description:
'A filter can be one of <code>attached_to_me</code>, <code>everyone</code> and <code>is_starred</code>',
},
{
displayName: 'Newer Than',
name: 'newer_than_ts',
type: 'dateTime',
default: '',
description: 'Limits threads to those newer when the specified Unix time',
},
{
displayName: 'Older Than',
name: 'older_than_ts',
type: 'dateTime',
default: '',
description: 'Limits threads to those older than the specified Unix time',
},
],
},
/* -------------------------------------------------------------------------- */
/* thread:update */
/* -------------------------------------------------------------------------- */
{
displayName: 'Thread ID',
name: 'threadId',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['update'],
resource: ['thread'],
},
},
required: true,
description: 'The ID of the thread',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['thread'],
operation: ['update'],
},
},
options: [
{
displayName: 'Actions',
name: 'actionsUi',
type: 'fixedCollection',
default: {},
placeholder: 'Add Action',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Action',
name: 'actionValues',
values: [
{
displayName: 'Action',
name: 'action',
type: 'options',
description: 'The action of the button',
options: [
{
name: 'Open URL',
value: 'open_url',
},
{
name: 'Prefill Message',
value: 'prefill_message',
},
{
name: 'Send Reply',
value: 'send_reply',
},
],
default: '',
},
{
displayName: 'Button Text',
name: 'button_text',
type: 'string',
description: 'The text for the action button',
default: '',
},
{
displayName: 'Message',
name: 'message',
type: 'string',
displayOptions: {
show: {
action: ['send_reply', 'prefill_message'],
},
},
description: 'The text for the action button',
default: '',
},
{
displayName: 'Type',
name: 'type',
type: 'options',
description:
'The type of the button. (Currently only <code>action</code> is available).',
options: [
{
name: 'Action',
value: 'action',
},
],
default: '',
},
{
displayName: 'URL',
name: 'url',
type: 'string',
displayOptions: {
show: {
action: ['open_url'],
},
},
description: 'URL to redirect',
default: '',
},
],
},
],
},
{
displayName: 'Attachments',
name: 'binaryProperties',
type: 'string',
default: 'data',
description:
'Name of the property that holds the binary data. Multiple can be defined separated by comma.',
},
{
displayName: 'Content',
name: 'content',
type: 'string',
default: '',
description: 'The content of the thread',
},
{
displayName: 'Direct Mention Names or IDs',
name: 'direct_mentions',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getUsers',
loadOptionsDependsOn: ['workspaceId'],
},
default: [],
description:
'The users that are directly mentioned. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
description: 'The title of the thread (1 < length < 300)',
},
],
},
];
@@ -0,0 +1,18 @@
{
"node": "n8n-nodes-base.twist",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"categories": ["Communication"],
"resources": {
"credentialDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/credentials/twist/"
}
],
"primaryDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.twist/"
}
]
}
}
@@ -0,0 +1,771 @@
import moment from 'moment-timezone';
import type {
IBinaryData,
IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions,
INodeExecutionData,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
import { NodeConnectionTypes } from 'n8n-workflow';
import { v4 as uuid } from 'uuid';
import { channelFields, channelOperations } from './ChannelDescription';
import { commentFields, commentOperations } from './CommentDescription';
import { twistApiRequest } from './GenericFunctions';
import {
messageConversationFields,
messageConversationOperations,
} from './MessageConversationDescription';
import { threadFields, threadOperations } from './ThreadDescription';
import { prepareBinariesDataList } from '../../utils/binary';
export class Twist implements INodeType {
description: INodeTypeDescription = {
displayName: 'Twist',
name: 'twist',
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
icon: 'file:twist.png',
group: ['input'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume Twist API',
defaults: {
name: 'Twist',
},
usableAsTool: true,
inputs: [NodeConnectionTypes.Main],
outputs: [NodeConnectionTypes.Main],
credentials: [
{
name: 'twistOAuth2Api',
required: true,
},
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Channel',
value: 'channel',
},
{
name: 'Comment',
value: 'comment',
},
{
name: 'Message Conversation',
value: 'messageConversation',
},
{
name: 'Thread',
value: 'thread',
},
],
default: 'messageConversation',
},
...channelOperations,
...channelFields,
...commentOperations,
...commentFields,
...messageConversationOperations,
...messageConversationFields,
...threadOperations,
...threadFields,
],
};
methods = {
loadOptions: {
// Get all the available workspaces to display them to user so that they can
// select them easily
async getWorkspaces(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const workspaces = await twistApiRequest.call(this, 'GET', '/workspaces/get');
for (const workspace of workspaces) {
returnData.push({
name: workspace.name,
value: workspace.id,
});
}
return returnData;
},
// Get all the available conversations to display them to user so that they can
// select them easily
async getConversations(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const qs: IDataObject = {
workspace_id: this.getCurrentNodeParameter('workspaceId') as string,
};
const conversations = await twistApiRequest.call(this, 'GET', '/conversations/get', {}, qs);
for (const conversation of conversations) {
returnData.push({
name: conversation.title || conversation.id,
value: conversation.id,
});
}
return returnData;
},
// Get all the available users to display them to user so that they can
// select them easily
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const qs: IDataObject = {
id: this.getCurrentNodeParameter('workspaceId') as string,
};
const users = await twistApiRequest.call(this, 'GET', '/workspaces/get_users', {}, qs);
for (const user of users) {
returnData.push({
name: user.name,
value: user.id,
});
}
return returnData;
},
// Get all the available groups to display them to user so that they can
// select them easily
async getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const qs: IDataObject = {
workspace_id: this.getCurrentNodeParameter('workspaceId') as string,
};
const groups = await twistApiRequest.call(this, 'GET', '/groups/get', {}, qs);
for (const group of groups) {
returnData.push({
name: group.name,
value: group.id,
});
}
return returnData;
},
},
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const length = items.length;
const qs: IDataObject = {};
let responseData;
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
for (let i = 0; i < length; i++) {
try {
if (resource === 'channel') {
//https://developer.twist.com/v3/#add-channel
if (operation === 'create') {
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
const name = this.getNodeParameter('name', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i);
const body: IDataObject = {
workspace_id: workspaceId,
name,
};
Object.assign(body, additionalFields);
responseData = await twistApiRequest.call(this, 'POST', '/channels/add', body);
}
//https://developer.twist.com/v3/#remove-channel
if (operation === 'delete') {
qs.id = this.getNodeParameter('channelId', i) as string;
responseData = await twistApiRequest.call(this, 'POST', '/channels/remove', {}, qs);
}
//https://developer.twist.com/v3/#get-channel
if (operation === 'get') {
qs.id = this.getNodeParameter('channelId', i) as string;
responseData = await twistApiRequest.call(this, 'GET', '/channels/getone', {}, qs);
}
//https://developer.twist.com/v3/#get-all-channels
if (operation === 'getAll') {
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
const returnAll = this.getNodeParameter('returnAll', i);
const filters = this.getNodeParameter('filters', i);
qs.workspace_id = workspaceId;
Object.assign(qs, filters);
responseData = await twistApiRequest.call(this, 'GET', '/channels/get', {}, qs);
if (!returnAll) {
const limit = this.getNodeParameter('limit', i);
responseData = responseData.splice(0, limit);
}
}
//https://developer.twist.com/v3/#update-channel
if (operation === 'update') {
const channelId = this.getNodeParameter('channelId', i) as string;
const updateFields = this.getNodeParameter('updateFields', i);
const body: IDataObject = {
id: channelId,
};
Object.assign(body, updateFields);
responseData = await twistApiRequest.call(this, 'POST', '/channels/update', body);
}
//https://developer.twist.com/v3/#archive-channel
if (operation === 'archive') {
qs.id = this.getNodeParameter('channelId', i) as string;
responseData = await twistApiRequest.call(this, 'POST', '/channels/archive', {}, qs);
}
//https://developer.twist.com/v3/#unarchive-channel
if (operation === 'unarchive') {
qs.id = this.getNodeParameter('channelId', i) as string;
responseData = await twistApiRequest.call(this, 'POST', '/channels/unarchive', {}, qs);
}
}
if (resource === 'comment') {
//https://developer.twist.com/v3/#add-comment
if (operation === 'create') {
const threadId = this.getNodeParameter('threadId', i) as string;
const content = this.getNodeParameter('content', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i);
const body: IDataObject = {
thread_id: threadId,
content,
};
Object.assign(body, additionalFields);
if (body.actionsUi) {
const actions = (body.actionsUi as IDataObject).actionValues as IDataObject[];
if (actions) {
body.actions = actions;
delete body.actionsUi;
}
}
if (body.binaryProperties) {
const binaryProperties = prepareBinariesDataList(
body.binaryProperties as string | string[] | IBinaryData | IBinaryData[],
);
const attachments: IDataObject[] = [];
for (const binaryProperty of binaryProperties) {
const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
attachments.push(
(await twistApiRequest.call(
this,
'POST',
'/attachments/upload',
{},
{},
{
formData: {
file_name: {
value: dataBuffer,
options: {
filename: binaryData.fileName,
},
},
attachment_id: uuid(),
},
},
)) as IDataObject,
);
}
body.attachments = attachments;
}
if (body.direct_mentions) {
const directMentions: string[] = [];
for (const directMention of body.direct_mentions as number[]) {
directMentions.push(`[name](twist-mention://${directMention})`);
}
body.content = `${directMentions.join(' ')} ${body.content}`;
}
responseData = await twistApiRequest.call(this, 'POST', '/comments/add', body);
}
//https://developer.twist.com/v3/#remove-comment
if (operation === 'delete') {
qs.id = this.getNodeParameter('commentId', i) as string;
responseData = await twistApiRequest.call(this, 'POST', '/comments/remove', {}, qs);
}
//https://developer.twist.com/v3/#get-comment
if (operation === 'get') {
qs.id = this.getNodeParameter('commentId', i) as string;
responseData = await twistApiRequest.call(this, 'GET', '/comments/getone', {}, qs);
responseData = responseData?.comment;
}
//https://developer.twist.com/v3/#get-all-comments
if (operation === 'getAll') {
const threadId = this.getNodeParameter('threadId', i) as string;
const returnAll = this.getNodeParameter('returnAll', i);
const filters = this.getNodeParameter('filters', i);
qs.thread_id = threadId;
Object.assign(qs, filters);
if (!returnAll) {
qs.limit = this.getNodeParameter('limit', i);
}
if (qs.older_than_ts) {
qs.older_than_ts = moment(qs.older_than_ts as string).unix();
}
if (qs.newer_than_ts) {
qs.newer_than_ts = moment(qs.newer_than_ts as string).unix();
}
responseData = await twistApiRequest.call(this, 'GET', '/comments/get', {}, qs);
if (qs.as_ids) {
responseData = (responseData as number[]).map((id) => ({ ID: id }));
}
}
//https://developer.twist.com/v3/#update-comment
if (operation === 'update') {
const commentId = this.getNodeParameter('commentId', i) as string;
const updateFields = this.getNodeParameter('updateFields', i);
const body: IDataObject = {
id: commentId,
};
Object.assign(body, updateFields);
if (body.actionsUi) {
const actions = (body.actionsUi as IDataObject).actionValues as IDataObject[];
if (actions) {
body.actions = actions;
delete body.actionsUi;
}
}
if (body.binaryProperties) {
const binaryProperties = prepareBinariesDataList(
body.binaryProperties as string | string[] | IBinaryData | IBinaryData[],
);
const attachments: IDataObject[] = [];
for (const binaryProperty of binaryProperties) {
const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
attachments.push(
(await twistApiRequest.call(
this,
'POST',
'/attachments/upload',
{},
{},
{
formData: {
file_name: {
value: dataBuffer,
options: {
filename: binaryData.fileName,
},
},
attachment_id: uuid(),
},
},
)) as IDataObject,
);
}
body.attachments = attachments;
}
if (body.direct_mentions) {
const directMentions: string[] = [];
for (const directMention of body.direct_mentions as number[]) {
directMentions.push(`[name](twist-mention://${directMention})`);
}
body.content = `${directMentions.join(' ')} ${body.content}`;
}
responseData = await twistApiRequest.call(this, 'POST', '/comments/update', body);
}
}
if (resource === 'messageConversation') {
//https://developer.twist.com/v3/#add-message-to-conversation
if (operation === 'create') {
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
const conversationId = this.getNodeParameter('conversationId', i) as string;
const content = this.getNodeParameter('content', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i);
const body: IDataObject = {
conversation_id: conversationId,
workspace_id: workspaceId,
content,
};
Object.assign(body, additionalFields);
if (body.actionsUi) {
const actions = (body.actionsUi as IDataObject).actionValues as IDataObject[];
if (actions) {
body.actions = actions;
delete body.actionsUi;
}
}
if (body.binaryProperties) {
const binaryProperties = prepareBinariesDataList(
body.binaryProperties as string | string[] | IBinaryData | IBinaryData[],
);
const attachments: IDataObject[] = [];
for (const binaryProperty of binaryProperties) {
const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
attachments.push(
(await twistApiRequest.call(
this,
'POST',
'/attachments/upload',
{},
{},
{
formData: {
file_name: {
value: dataBuffer,
options: {
filename: binaryData.fileName,
},
},
attachment_id: uuid(),
},
},
)) as IDataObject,
);
}
body.attachments = attachments;
}
if (body.direct_mentions) {
const directMentions: string[] = [];
for (const directMention of body.direct_mentions as number[]) {
directMentions.push(`[name](twist-mention://${directMention})`);
}
body.content = `${directMentions.join(' ')} ${body.content}`;
}
// if (body.direct_group_mentions) {
// const directGroupMentions: string[] = [];
// for (const directGroupMention of body.direct_group_mentions as number[]) {
// directGroupMentions.push(`[Group name](twist-group-mention://${directGroupMention})`);
// }
// body.content = `${directGroupMentions.join(' ')} ${body.content}`;
// }
responseData = await twistApiRequest.call(
this,
'POST',
'/conversation_messages/add',
body,
);
}
//https://developer.twist.com/v3/#get-message
if (operation === 'get') {
qs.id = this.getNodeParameter('id', i) as string;
responseData = await twistApiRequest.call(
this,
'GET',
'/conversation_messages/getone',
{},
qs,
);
}
//https://developer.twist.com/v3/#get-all-messages
if (operation === 'getAll') {
const conversationId = this.getNodeParameter('conversationId', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i);
qs.conversation_id = conversationId;
Object.assign(qs, additionalFields);
responseData = await twistApiRequest.call(
this,
'GET',
'/conversation_messages/get',
{},
qs,
);
}
//https://developer.twist.com/v3/#remove-message-from-conversation
if (operation === 'delete') {
qs.id = this.getNodeParameter('id', i) as string;
responseData = await twistApiRequest.call(
this,
'POST',
'/conversation_messages/remove',
{},
qs,
);
}
//https://developer.twist.com/v3/#update-message-in-conversation
if (operation === 'update') {
const id = this.getNodeParameter('id', i) as string;
const updateFields = this.getNodeParameter('updateFields', i);
const body: IDataObject = {
id,
};
Object.assign(body, updateFields);
if (body.actionsUi) {
const actions = (body.actionsUi as IDataObject).actionValues as IDataObject[];
if (actions) {
body.actions = actions;
delete body.actionsUi;
}
}
if (body.binaryProperties) {
const binaryProperties = prepareBinariesDataList(
body.binaryProperties as string | string[] | IBinaryData | IBinaryData[],
);
const attachments: IDataObject[] = [];
for (const binaryProperty of binaryProperties) {
const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
attachments.push(
(await twistApiRequest.call(
this,
'POST',
'/attachments/upload',
{},
{},
{
formData: {
file_name: {
value: dataBuffer,
options: {
filename: binaryData.fileName,
},
},
attachment_id: uuid(),
},
},
)) as IDataObject,
);
}
body.attachments = attachments;
}
if (body.direct_mentions) {
const directMentions: string[] = [];
for (const directMention of body.direct_mentions as number[]) {
directMentions.push(`[name](twist-mention://${directMention})`);
}
body.content = `${directMentions.join(' ')} ${body.content}`;
}
responseData = await twistApiRequest.call(
this,
'POST',
'/conversation_messages/update',
body,
);
}
}
if (resource === 'thread') {
//https://developer.twist.com/v3/#add-thread
if (operation === 'create') {
const channelId = this.getNodeParameter('channelId', i) as string;
const title = this.getNodeParameter('title', i) as string;
const content = this.getNodeParameter('content', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i);
const body: IDataObject = {
channel_id: channelId,
content,
title,
};
Object.assign(body, additionalFields);
if (body.actionsUi) {
const actions = (body.actionsUi as IDataObject).actionValues as IDataObject[];
if (actions) {
body.actions = actions;
delete body.actionsUi;
}
}
if (body.binaryProperties) {
const binaryProperties = prepareBinariesDataList(
body.binaryProperties as string | string[] | IBinaryData | IBinaryData[],
);
const attachments: IDataObject[] = [];
for (const binaryProperty of binaryProperties) {
const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
attachments.push(
(await twistApiRequest.call(
this,
'POST',
'/attachments/upload',
{},
{},
{
formData: {
file_name: {
value: dataBuffer,
options: {
filename: binaryData.fileName,
},
},
attachment_id: uuid(),
},
},
)) as IDataObject,
);
}
body.attachments = attachments;
}
if (body.direct_mentions) {
const directMentions: string[] = [];
for (const directMention of body.direct_mentions as number[]) {
directMentions.push(`[name](twist-mention://${directMention})`);
}
body.content = `${directMentions.join(' ')} ${body.content}`;
}
responseData = await twistApiRequest.call(this, 'POST', '/threads/add', body);
}
//https://developer.twist.com/v3/#remove-thread
if (operation === 'delete') {
qs.id = this.getNodeParameter('threadId', i) as string;
responseData = await twistApiRequest.call(this, 'POST', '/threads/remove', {}, qs);
}
//https://developer.twist.com/v3/#get-thread
if (operation === 'get') {
qs.id = this.getNodeParameter('threadId', i) as string;
responseData = await twistApiRequest.call(this, 'GET', '/threads/getone', {}, qs);
}
//https://developer.twist.com/v3/#get-all-threads
if (operation === 'getAll') {
const channelId = this.getNodeParameter('channelId', i) as string;
const returnAll = this.getNodeParameter('returnAll', i);
const filters = this.getNodeParameter('filters', i);
qs.channel_id = channelId;
Object.assign(qs, filters);
if (!returnAll) {
qs.limit = this.getNodeParameter('limit', i);
}
if (qs.older_than_ts) {
qs.older_than_ts = moment(qs.older_than_ts as string).unix();
}
if (qs.newer_than_ts) {
qs.newer_than_ts = moment(qs.newer_than_ts as string).unix();
}
responseData = await twistApiRequest.call(this, 'GET', '/threads/get', {}, qs);
if (qs.as_ids) {
responseData = (responseData as number[]).map((id) => ({ ID: id }));
}
}
//https://developer.twist.com/v3/#update-thread
if (operation === 'update') {
const threadId = this.getNodeParameter('threadId', i) as string;
const updateFields = this.getNodeParameter('updateFields', i);
const body: IDataObject = {
id: threadId,
};
Object.assign(body, updateFields);
if (body.actionsUi) {
const actions = (body.actionsUi as IDataObject).actionValues as IDataObject[];
if (actions) {
body.actions = actions;
delete body.actionsUi;
}
}
if (body.binaryProperties) {
const binaryProperties = prepareBinariesDataList(
body.binaryProperties as string | string[] | IBinaryData | IBinaryData[],
);
const attachments: IDataObject[] = [];
for (const binaryProperty of binaryProperties) {
const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
attachments.push(
(await twistApiRequest.call(
this,
'POST',
'/attachments/upload',
{},
{},
{
formData: {
file_name: {
value: dataBuffer,
options: {
filename: binaryData.fileName,
},
},
attachment_id: uuid(),
},
},
)) as IDataObject,
);
}
body.attachments = attachments;
}
if (body.direct_mentions) {
const directMentions: string[] = [];
for (const directMention of body.direct_mentions as number[]) {
directMentions.push(`[name](twist-mention://${directMention})`);
}
body.content = `${directMentions.join(' ')} ${body.content}`;
}
responseData = await twistApiRequest.call(this, 'POST', '/threads/update', body);
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else {
returnData.push(responseData as IDataObject);
}
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.message });
continue;
}
throw error;
}
}
return [this.helpers.returnJsonArray(returnData)];
}
}
@@ -0,0 +1,497 @@
import type { IExecuteFunctions, IBinaryData, INodeExecutionData } from 'n8n-workflow';
import { Twist } from '../Twist.node';
import * as GenericFunctions from '../GenericFunctions';
jest.mock('../GenericFunctions');
describe('Twist Node - prepareBinariesDataList usage', () => {
let twist: Twist;
let mockExecuteFunctions: jest.Mocked<IExecuteFunctions>;
beforeEach(() => {
twist = new Twist();
mockExecuteFunctions = {
getInputData: jest.fn(),
getNodeParameter: jest.fn(),
helpers: {
assertBinaryData: jest.fn(),
getBinaryDataBuffer: jest.fn(),
returnJsonArray: jest.fn(),
},
} as unknown as jest.Mocked<IExecuteFunctions>;
jest.clearAllMocks();
// Mock the twistApiRequest to return successful responses
(GenericFunctions.twistApiRequest as jest.Mock).mockResolvedValue({
id: 'test-id',
});
});
describe('comment create with string binaryProperties', () => {
it('should process comma-separated string binaryProperties', async () => {
const items: INodeExecutionData[] = [
{
json: {},
binary: {
file1: {
data: Buffer.from('data1').toString('base64'),
mimeType: 'text/plain',
fileName: 'file1.txt',
},
file2: {
data: Buffer.from('data2').toString('base64'),
mimeType: 'text/plain',
fileName: 'file2.txt',
},
},
},
];
mockExecuteFunctions.getInputData.mockReturnValue(items);
(mockExecuteFunctions.getNodeParameter as jest.Mock)
.mockReturnValueOnce('comment')
.mockReturnValueOnce('create')
.mockReturnValueOnce('thread123')
.mockReturnValueOnce('Test content')
.mockReturnValueOnce({
binaryProperties: 'file1, file2',
});
(mockExecuteFunctions.helpers.assertBinaryData as jest.Mock).mockImplementation(
(itemIndex: number, propertyName: string) => {
return items[itemIndex].binary![propertyName];
},
);
(mockExecuteFunctions.helpers.getBinaryDataBuffer as jest.Mock).mockResolvedValue(
Buffer.from('test data'),
);
(mockExecuteFunctions.helpers.returnJsonArray as jest.Mock).mockImplementation(
(data: any) => {
return Array.isArray(data) ? data.map((item) => ({ json: item })) : [{ json: data }];
},
);
const result = await twist.execute.call(mockExecuteFunctions);
expect(result[0]).toHaveLength(1);
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledTimes(2);
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledWith(0, 'file1');
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledWith(0, 'file2');
});
it('should handle single string binaryProperty', async () => {
const items: INodeExecutionData[] = [
{
json: {},
binary: {
singleFile: {
data: Buffer.from('data').toString('base64'),
mimeType: 'text/plain',
fileName: 'single.txt',
},
},
},
];
mockExecuteFunctions.getInputData.mockReturnValue(items);
(mockExecuteFunctions.getNodeParameter as jest.Mock)
.mockReturnValueOnce('comment')
.mockReturnValueOnce('create')
.mockReturnValueOnce('thread123')
.mockReturnValueOnce('Test content')
.mockReturnValueOnce({
binaryProperties: 'singleFile',
});
(mockExecuteFunctions.helpers.assertBinaryData as jest.Mock).mockImplementation(
(itemIndex: number, propertyName: string) => {
return items[itemIndex].binary![propertyName];
},
);
(mockExecuteFunctions.helpers.getBinaryDataBuffer as jest.Mock).mockResolvedValue(
Buffer.from('test data'),
);
(mockExecuteFunctions.helpers.returnJsonArray as jest.Mock).mockImplementation(
(data: any) => {
return Array.isArray(data) ? data.map((item) => ({ json: item })) : [{ json: data }];
},
);
const result = await twist.execute.call(mockExecuteFunctions);
expect(result[0]).toHaveLength(1);
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledTimes(1);
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledWith(0, 'singleFile');
});
});
describe('comment create with string[] binaryProperties', () => {
it('should process string array binaryProperties', async () => {
const items: INodeExecutionData[] = [
{
json: {},
binary: {
doc1: {
data: Buffer.from('data1').toString('base64'),
mimeType: 'application/pdf',
fileName: 'doc1.pdf',
},
doc2: {
data: Buffer.from('data2').toString('base64'),
mimeType: 'application/pdf',
fileName: 'doc2.pdf',
},
doc3: {
data: Buffer.from('data3').toString('base64'),
mimeType: 'application/pdf',
fileName: 'doc3.pdf',
},
},
},
];
mockExecuteFunctions.getInputData.mockReturnValue(items);
(mockExecuteFunctions.getNodeParameter as jest.Mock)
.mockReturnValueOnce('comment')
.mockReturnValueOnce('create')
.mockReturnValueOnce('thread123')
.mockReturnValueOnce('Test content')
.mockReturnValueOnce({
binaryProperties: ['doc1', 'doc2', 'doc3'],
});
(mockExecuteFunctions.helpers.assertBinaryData as jest.Mock).mockImplementation(
(itemIndex: number, propertyName: string) => {
return items[itemIndex].binary![propertyName];
},
);
(mockExecuteFunctions.helpers.getBinaryDataBuffer as jest.Mock).mockResolvedValue(
Buffer.from('test data'),
);
(mockExecuteFunctions.helpers.returnJsonArray as jest.Mock).mockImplementation(
(data: any) => {
return Array.isArray(data) ? data.map((item) => ({ json: item })) : [{ json: data }];
},
);
const result = await twist.execute.call(mockExecuteFunctions);
expect(result[0]).toHaveLength(1);
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledTimes(3);
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledWith(0, 'doc1');
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledWith(0, 'doc2');
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledWith(0, 'doc3');
});
});
describe('comment create with IBinaryData binaryProperties', () => {
it('should process single IBinaryData object', async () => {
const binaryData: IBinaryData = {
data: Buffer.from('data').toString('base64'),
mimeType: 'image/png',
fileName: 'image.png',
};
const items: INodeExecutionData[] = [
{
json: {},
binary: {},
},
];
mockExecuteFunctions.getInputData.mockReturnValue(items);
(mockExecuteFunctions.getNodeParameter as jest.Mock)
.mockReturnValueOnce('comment')
.mockReturnValueOnce('create')
.mockReturnValueOnce('thread123')
.mockReturnValueOnce('Test content')
.mockReturnValueOnce({
binaryProperties: binaryData,
});
(mockExecuteFunctions.helpers.assertBinaryData as jest.Mock).mockReturnValue(binaryData);
(mockExecuteFunctions.helpers.getBinaryDataBuffer as jest.Mock).mockResolvedValue(
Buffer.from('test data'),
);
(mockExecuteFunctions.helpers.returnJsonArray as jest.Mock).mockImplementation(
(data: any) => {
return Array.isArray(data) ? data.map((item) => ({ json: item })) : [{ json: data }];
},
);
const result = await twist.execute.call(mockExecuteFunctions);
expect(result[0]).toHaveLength(1);
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledTimes(1);
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledWith(0, binaryData);
});
});
describe('comment create with IBinaryData[] binaryProperties', () => {
it('should process IBinaryData array', async () => {
const binaryDataArray: IBinaryData[] = [
{
data: Buffer.from('data1').toString('base64'),
mimeType: 'text/plain',
fileName: 'file1.txt',
},
{
data: Buffer.from('data2').toString('base64'),
mimeType: 'image/jpeg',
fileName: 'image.jpg',
},
];
const items: INodeExecutionData[] = [
{
json: {},
binary: {},
},
];
mockExecuteFunctions.getInputData.mockReturnValue(items);
(mockExecuteFunctions.getNodeParameter as jest.Mock)
.mockReturnValueOnce('comment')
.mockReturnValueOnce('create')
.mockReturnValueOnce('thread123')
.mockReturnValueOnce('Test content')
.mockReturnValueOnce({
binaryProperties: binaryDataArray,
});
(mockExecuteFunctions.helpers.assertBinaryData as jest.Mock).mockImplementation(
(_: number, data: any) => {
if (typeof data === 'object') return data;
return binaryDataArray[0];
},
);
(mockExecuteFunctions.helpers.getBinaryDataBuffer as jest.Mock).mockResolvedValue(
Buffer.from('test data'),
);
(mockExecuteFunctions.helpers.returnJsonArray as jest.Mock).mockImplementation(
(data: any) => {
return Array.isArray(data) ? data.map((item) => ({ json: item })) : [{ json: data }];
},
);
const result = await twist.execute.call(mockExecuteFunctions);
expect(result[0]).toHaveLength(1);
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledTimes(2);
});
});
describe('messageConversation create with binaryProperties', () => {
it('should process string binaryProperties in messageConversation', async () => {
const items: INodeExecutionData[] = [
{
json: {},
binary: {
attachment: {
data: Buffer.from('data').toString('base64'),
mimeType: 'application/pdf',
fileName: 'report.pdf',
},
},
},
];
mockExecuteFunctions.getInputData.mockReturnValue(items);
(mockExecuteFunctions.getNodeParameter as jest.Mock)
.mockReturnValueOnce('messageConversation')
.mockReturnValueOnce('create')
.mockReturnValueOnce('workspace123')
.mockReturnValueOnce('conversation123')
.mockReturnValueOnce('Test message')
.mockReturnValueOnce({
binaryProperties: 'attachment',
});
(mockExecuteFunctions.helpers.assertBinaryData as jest.Mock).mockImplementation(
(itemIndex: number, propertyName: string) => {
return items[itemIndex].binary![propertyName];
},
);
(mockExecuteFunctions.helpers.getBinaryDataBuffer as jest.Mock).mockResolvedValue(
Buffer.from('test data'),
);
(mockExecuteFunctions.helpers.returnJsonArray as jest.Mock).mockImplementation(
(data: any) => {
return Array.isArray(data) ? data.map((item) => ({ json: item })) : [{ json: data }];
},
);
const result = await twist.execute.call(mockExecuteFunctions);
expect(result[0]).toHaveLength(1);
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledWith(0, 'attachment');
});
it('should process IBinaryData[] in messageConversation', async () => {
const binaryDataArray: IBinaryData[] = [
{
data: Buffer.from('data1').toString('base64'),
mimeType: 'text/csv',
fileName: 'data.csv',
},
{
data: Buffer.from('data2').toString('base64'),
mimeType: 'application/zip',
fileName: 'archive.zip',
},
];
const items: INodeExecutionData[] = [
{
json: {},
binary: {},
},
];
mockExecuteFunctions.getInputData.mockReturnValue(items);
(mockExecuteFunctions.getNodeParameter as jest.Mock)
.mockReturnValueOnce('messageConversation')
.mockReturnValueOnce('create')
.mockReturnValueOnce('workspace123')
.mockReturnValueOnce('conversation123')
.mockReturnValueOnce('Test message')
.mockReturnValueOnce({
binaryProperties: binaryDataArray,
});
(mockExecuteFunctions.helpers.assertBinaryData as jest.Mock).mockImplementation(
(_: number, data: any) => {
if (typeof data === 'object') return data;
return binaryDataArray[0];
},
);
(mockExecuteFunctions.helpers.getBinaryDataBuffer as jest.Mock).mockResolvedValue(
Buffer.from('test data'),
);
(mockExecuteFunctions.helpers.returnJsonArray as jest.Mock).mockImplementation(
(data: any) => {
return Array.isArray(data) ? data.map((item) => ({ json: item })) : [{ json: data }];
},
);
const result = await twist.execute.call(mockExecuteFunctions);
expect(result[0]).toHaveLength(1);
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledTimes(2);
});
});
describe('thread create with binaryProperties', () => {
it('should process string binaryProperties in thread', async () => {
const items: INodeExecutionData[] = [
{
json: {},
binary: {
doc1: {
data: Buffer.from('data1').toString('base64'),
mimeType: 'application/pdf',
fileName: 'spec.pdf',
},
doc2: {
data: Buffer.from('data2').toString('base64'),
mimeType: 'application/pdf',
fileName: 'design.pdf',
},
},
},
];
mockExecuteFunctions.getInputData.mockReturnValue(items);
(mockExecuteFunctions.getNodeParameter as jest.Mock)
.mockReturnValueOnce('thread')
.mockReturnValueOnce('create')
.mockReturnValueOnce('channel123')
.mockReturnValueOnce('Test Thread')
.mockReturnValueOnce('Thread content')
.mockReturnValueOnce({
binaryProperties: 'doc1, doc2',
});
(mockExecuteFunctions.helpers.assertBinaryData as jest.Mock).mockImplementation(
(itemIndex: number, propertyName: string) => {
return items[itemIndex].binary![propertyName];
},
);
(mockExecuteFunctions.helpers.getBinaryDataBuffer as jest.Mock).mockResolvedValue(
Buffer.from('test data'),
);
(mockExecuteFunctions.helpers.returnJsonArray as jest.Mock).mockImplementation(
(data: any) => {
return Array.isArray(data) ? data.map((item) => ({ json: item })) : [{ json: data }];
},
);
const result = await twist.execute.call(mockExecuteFunctions);
expect(result[0]).toHaveLength(1);
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledTimes(2);
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledWith(0, 'doc1');
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledWith(0, 'doc2');
});
it('should process single IBinaryData in thread', async () => {
const binaryData: IBinaryData = {
data: Buffer.from('data').toString('base64'),
mimeType: 'text/markdown',
fileName: 'README.md',
};
const items: INodeExecutionData[] = [
{
json: {},
binary: {},
},
];
mockExecuteFunctions.getInputData.mockReturnValue(items);
(mockExecuteFunctions.getNodeParameter as jest.Mock)
.mockReturnValueOnce('thread')
.mockReturnValueOnce('create')
.mockReturnValueOnce('channel123')
.mockReturnValueOnce('Test Thread')
.mockReturnValueOnce('Thread content')
.mockReturnValueOnce({
binaryProperties: binaryData,
});
(mockExecuteFunctions.helpers.assertBinaryData as jest.Mock).mockReturnValue(binaryData);
(mockExecuteFunctions.helpers.getBinaryDataBuffer as jest.Mock).mockResolvedValue(
Buffer.from('test data'),
);
(mockExecuteFunctions.helpers.returnJsonArray as jest.Mock).mockImplementation(
(data: any) => {
return Array.isArray(data) ? data.map((item) => ({ json: item })) : [{ json: data }];
},
);
const result = await twist.execute.call(mockExecuteFunctions);
expect(result[0]).toHaveLength(1);
expect(mockExecuteFunctions.helpers.assertBinaryData).toHaveBeenCalledWith(0, binaryData);
});
});
});
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB