2023-01-27 03:22:44 -08:00
|
|
|
|
import type {
|
2023-03-09 09:13:15 -08:00
|
|
|
|
IExecuteFunctions,
|
2023-01-27 03:22:44 -08:00
|
|
|
|
IDataObject,
|
|
|
|
|
INodeExecutionData,
|
|
|
|
|
INodeType,
|
|
|
|
|
INodeTypeDescription,
|
|
|
|
|
} from 'n8n-workflow';
|
2021-01-22 07:17:12 -08:00
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
|
import { rocketchatApiRequest, validateJSON } from './GenericFunctions';
|
2019-11-08 20:11:01 -08:00
|
|
|
|
|
2019-11-09 17:29:05 -08:00
|
|
|
|
interface IField {
|
2019-11-10 21:00:24 -08:00
|
|
|
|
short?: boolean;
|
|
|
|
|
title?: string;
|
|
|
|
|
value?: string;
|
2019-11-09 17:29:05 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IAttachment {
|
2019-11-10 21:00:24 -08:00
|
|
|
|
color?: string;
|
2019-11-09 17:29:05 -08:00
|
|
|
|
text?: string;
|
2019-11-10 21:00:24 -08:00
|
|
|
|
ts?: string;
|
|
|
|
|
title?: string;
|
|
|
|
|
thumb_url?: string;
|
|
|
|
|
message_link?: string;
|
|
|
|
|
collapsed?: boolean;
|
|
|
|
|
author_name?: string;
|
|
|
|
|
author_link?: string;
|
|
|
|
|
author_icon?: string;
|
|
|
|
|
title_link?: string;
|
|
|
|
|
title_link_download?: boolean;
|
|
|
|
|
image_url?: string;
|
|
|
|
|
audio_url?: string;
|
|
|
|
|
video_url?: string;
|
|
|
|
|
fields?: IField[];
|
2019-11-09 17:29:05 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IPostMessageBody {
|
|
|
|
|
channel: string;
|
|
|
|
|
text?: string;
|
|
|
|
|
alias?: string;
|
2019-11-10 21:00:24 -08:00
|
|
|
|
emoji?: string;
|
|
|
|
|
avatar?: string;
|
2019-11-09 17:29:05 -08:00
|
|
|
|
attachments?: IAttachment[];
|
|
|
|
|
}
|
2019-11-08 20:11:01 -08:00
|
|
|
|
|
|
|
|
|
export class Rocketchat implements INodeType {
|
|
|
|
|
description: INodeTypeDescription = {
|
2020-07-09 05:33:05 -07:00
|
|
|
|
displayName: 'RocketChat',
|
2020-05-12 06:45:41 -07:00
|
|
|
|
name: 'rocketchat',
|
2021-01-22 07:17:12 -08:00
|
|
|
|
icon: 'file:rocketchat.svg',
|
2019-11-08 20:11:01 -08:00
|
|
|
|
group: ['output'],
|
|
|
|
|
version: 1,
|
2019-11-09 08:57:22 -08:00
|
|
|
|
subtitle: '={{$parameter["resource"] + ": " + $parameter["operation"]}}',
|
2020-07-09 05:33:05 -07:00
|
|
|
|
description: 'Consume RocketChat API',
|
2019-11-08 20:11:01 -08:00
|
|
|
|
defaults: {
|
2020-07-09 05:33:05 -07:00
|
|
|
|
name: 'RocketChat',
|
2019-11-08 20:11:01 -08:00
|
|
|
|
},
|
|
|
|
|
inputs: ['main'],
|
|
|
|
|
outputs: ['main'],
|
|
|
|
|
credentials: [
|
|
|
|
|
{
|
|
|
|
|
name: 'rocketchatApi',
|
|
|
|
|
required: true,
|
2020-10-22 06:46:03 -07:00
|
|
|
|
},
|
2019-11-10 21:00:24 -08:00
|
|
|
|
],
|
2019-11-08 20:11:01 -08:00
|
|
|
|
properties: [
|
2022-08-17 08:50:24 -07:00
|
|
|
|
{
|
2019-11-09 08:57:22 -08:00
|
|
|
|
displayName: 'Resource',
|
|
|
|
|
name: 'resource',
|
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
|
noDataExpression: true,
|
2019-11-09 08:57:22 -08:00
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
name: 'Chat',
|
|
|
|
|
value: 'chat',
|
|
|
|
|
},
|
|
|
|
|
],
|
2019-11-13 13:29:52 -08:00
|
|
|
|
default: 'chat',
|
2019-11-09 08:57:22 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Operation',
|
|
|
|
|
name: 'operation',
|
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
|
noDataExpression: true,
|
2019-11-09 08:57:22 -08:00
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
resource: ['chat'],
|
2019-11-09 08:57:22 -08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
name: 'Post Message',
|
|
|
|
|
value: 'postMessage',
|
|
|
|
|
description: 'Post a message to a channel or a direct message',
|
2022-07-10 13:50:51 -07:00
|
|
|
|
action: 'Post a message',
|
2019-11-09 08:57:22 -08:00
|
|
|
|
},
|
|
|
|
|
],
|
2019-11-13 13:29:52 -08:00
|
|
|
|
default: 'postMessage',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-11-09 17:29:05 -08:00
|
|
|
|
displayName: 'Channel',
|
|
|
|
|
name: 'channel',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
type: 'string',
|
|
|
|
|
required: true,
|
2019-11-09 17:29:05 -08:00
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
resource: ['chat'],
|
|
|
|
|
operation: ['postMessage'],
|
2019-11-09 17:29:05 -08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
default: '',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'The channel name with the prefix in front of it',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-11-09 17:29:05 -08:00
|
|
|
|
displayName: 'Text',
|
|
|
|
|
name: 'text',
|
|
|
|
|
type: 'string',
|
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
resource: ['chat'],
|
|
|
|
|
operation: ['postMessage'],
|
2019-11-09 17:29:05 -08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
default: '',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'The text of the message to send, is optional because of attachments',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-11-09 17:29:05 -08:00
|
|
|
|
displayName: 'JSON Parameters',
|
|
|
|
|
name: 'jsonParameters',
|
|
|
|
|
type: 'boolean',
|
|
|
|
|
default: false,
|
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
resource: ['chat'],
|
|
|
|
|
operation: ['postMessage'],
|
2019-11-09 17:29:05 -08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-11-10 21:00:24 -08:00
|
|
|
|
{
|
2019-11-09 08:57:22 -08:00
|
|
|
|
displayName: 'Options',
|
|
|
|
|
name: 'options',
|
|
|
|
|
type: 'collection',
|
2024-07-29 05:27:23 -07:00
|
|
|
|
placeholder: 'Add option',
|
2019-11-09 08:57:22 -08:00
|
|
|
|
default: {},
|
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
resource: ['chat'],
|
|
|
|
|
operation: ['postMessage'],
|
2019-11-09 08:57:22 -08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
options: [
|
2019-11-13 13:29:52 -08:00
|
|
|
|
{
|
|
|
|
|
displayName: 'Alias',
|
|
|
|
|
name: 'alias',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
2022-08-17 08:50:24 -07:00
|
|
|
|
description:
|
|
|
|
|
'This will cause the message’s name to appear as the given alias, but your username will still display',
|
2019-11-13 13:29:52 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Avatar',
|
|
|
|
|
name: 'avatar',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
2022-06-03 10:23:49 -07:00
|
|
|
|
description: 'If provided, this will make the avatar use the provided image URL',
|
2019-11-13 13:29:52 -08:00
|
|
|
|
},
|
2019-11-10 21:00:24 -08:00
|
|
|
|
{
|
|
|
|
|
displayName: 'Emoji',
|
|
|
|
|
name: 'emoji',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
2022-08-17 08:50:24 -07:00
|
|
|
|
description:
|
|
|
|
|
'This will cause the message’s name to appear as the given alias, but your username will still display',
|
2020-10-22 06:46:03 -07:00
|
|
|
|
},
|
|
|
|
|
],
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-11-09 08:57:22 -08:00
|
|
|
|
displayName: 'Attachments',
|
|
|
|
|
name: 'attachments',
|
|
|
|
|
type: 'collection',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
default: {},
|
|
|
|
|
placeholder: 'Add Attachment Item',
|
|
|
|
|
typeOptions: {
|
|
|
|
|
multipleValues: true,
|
|
|
|
|
multipleValueButtonText: 'Add Attachment',
|
2019-11-09 08:57:22 -08:00
|
|
|
|
},
|
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
resource: ['chat'],
|
|
|
|
|
operation: ['postMessage'],
|
|
|
|
|
jsonParameters: [false],
|
2019-11-09 08:57:22 -08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
options: [
|
2019-11-10 21:00:24 -08:00
|
|
|
|
{
|
|
|
|
|
displayName: 'Color',
|
|
|
|
|
name: 'color',
|
2019-11-13 13:29:52 -08:00
|
|
|
|
type: 'color',
|
|
|
|
|
default: '#ff0000',
|
2022-08-17 08:50:24 -07:00
|
|
|
|
description:
|
|
|
|
|
'The color you want the order on the left side to be, any value background-css supports',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Text',
|
|
|
|
|
name: 'text',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
2022-08-17 08:50:24 -07:00
|
|
|
|
description:
|
|
|
|
|
'The text to display for this attachment, it is different than the message’s text',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Timestamp',
|
|
|
|
|
name: 'ts',
|
|
|
|
|
type: 'dateTime',
|
|
|
|
|
default: '',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Displays the time next to the text portion',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Thumb URL',
|
|
|
|
|
name: 'thumbUrl',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
2022-08-17 08:50:24 -07:00
|
|
|
|
description:
|
|
|
|
|
'An image that displays to the left of the text, looks better when this is relatively small',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Message Link',
|
|
|
|
|
name: 'messageLink',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
2022-08-17 08:50:24 -07:00
|
|
|
|
description:
|
|
|
|
|
'Only applicable if the timestamp is provided, as it makes the time clickable to this link',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Collapsed',
|
|
|
|
|
name: 'collapsed',
|
|
|
|
|
type: 'boolean',
|
|
|
|
|
default: false,
|
2022-06-20 07:54:01 -07:00
|
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
|
2022-08-17 08:50:24 -07:00
|
|
|
|
description:
|
|
|
|
|
'Causes the image, audio, and video sections to be hiding when collapsed is true',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Author Name',
|
|
|
|
|
name: 'authorName',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Name of the author',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Author Link',
|
|
|
|
|
name: 'authorLink',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Providing this makes the author name clickable and points to this link',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Author Icon',
|
|
|
|
|
name: 'authorIcon',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
|
|
|
|
placeholder: 'https://site.com/img.png',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Displays a tiny icon to the left of the Author’s name',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Title',
|
|
|
|
|
name: 'title',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Title to display for this attachment, displays under the author',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Title Link',
|
|
|
|
|
name: 'titleLink',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Providing this makes the title clickable, pointing to this link',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Title Link Download',
|
|
|
|
|
name: 'titleLinkDownload',
|
|
|
|
|
type: 'boolean',
|
|
|
|
|
default: false,
|
2022-06-20 07:54:01 -07:00
|
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
|
2022-08-17 08:50:24 -07:00
|
|
|
|
description:
|
|
|
|
|
'When this is true, a download icon appears and clicking this saves the link to file',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Image URL',
|
|
|
|
|
name: 'imageUrl',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'The image to display, will be “big” and easy to see',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Audio URL',
|
|
|
|
|
name: 'audioUrl',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
|
|
|
|
placeholder: 'https://site.com/aud.mp3',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Audio file to play, only supports what html audio does',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
2022-06-03 10:23:49 -07:00
|
|
|
|
displayName: 'Video URL',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
name: 'videoUrl',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
|
|
|
|
placeholder: 'https://site.com/vid.mp4',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Video file to play, only supports what html video does',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Fields',
|
|
|
|
|
name: 'fields',
|
|
|
|
|
type: 'fixedCollection',
|
|
|
|
|
placeholder: 'Add Field Item',
|
|
|
|
|
typeOptions: {
|
|
|
|
|
multipleValues: true,
|
|
|
|
|
},
|
2022-04-22 09:29:51 -07:00
|
|
|
|
default: {},
|
2019-11-10 21:00:24 -08:00
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
name: 'fieldsValues',
|
|
|
|
|
displayName: 'Fields',
|
|
|
|
|
values: [
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Short',
|
|
|
|
|
name: 'short',
|
|
|
|
|
type: 'boolean',
|
|
|
|
|
default: false,
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Whether this field should be a short field',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Title',
|
|
|
|
|
name: 'title',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'The title of this field',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Value',
|
|
|
|
|
name: 'value',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'The value of this field, displayed underneath the title value',
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2020-10-22 06:46:03 -07:00
|
|
|
|
],
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Attachments',
|
|
|
|
|
name: 'attachmentsJson',
|
|
|
|
|
type: 'json',
|
|
|
|
|
typeOptions: {
|
|
|
|
|
alwaysOpenEditWindow: true,
|
|
|
|
|
},
|
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
resource: ['chat'],
|
|
|
|
|
operation: ['postMessage'],
|
|
|
|
|
jsonParameters: [true],
|
2019-11-10 21:00:24 -08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
default: '',
|
2020-10-22 06:46:03 -07:00
|
|
|
|
},
|
|
|
|
|
],
|
2019-11-08 20:11:01 -08:00
|
|
|
|
};
|
|
|
|
|
|
2021-01-22 07:17:12 -08:00
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
|
const items = this.getInputData();
|
2022-04-22 09:29:51 -07:00
|
|
|
|
const length = items.length;
|
2021-01-22 07:17:12 -08:00
|
|
|
|
let responseData;
|
2023-01-31 11:39:20 -08:00
|
|
|
|
const returnData: INodeExecutionData[] = [];
|
2022-12-02 03:53:59 -08:00
|
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
|
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2021-01-22 07:17:12 -08:00
|
|
|
|
for (let i = 0; i < length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
|
try {
|
|
|
|
|
if (resource === 'chat') {
|
|
|
|
|
//https://rocket.chat/docs/developer-guides/rest-api/chat/postmessage
|
|
|
|
|
if (operation === 'postMessage') {
|
|
|
|
|
const channel = this.getNodeParameter('channel', i) as string;
|
|
|
|
|
const text = this.getNodeParameter('text', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
|
const options = this.getNodeParameter('options', i);
|
2022-11-18 05:31:38 -08:00
|
|
|
|
const jsonActive = this.getNodeParameter('jsonParameters', i);
|
2021-01-24 11:38:16 -08:00
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
|
const body: IPostMessageBody = {
|
|
|
|
|
channel,
|
|
|
|
|
text,
|
|
|
|
|
};
|
2021-01-24 11:38:16 -08:00
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
|
if (options.alias) {
|
|
|
|
|
body.alias = options.alias as string;
|
|
|
|
|
}
|
|
|
|
|
if (options.avatar) {
|
|
|
|
|
body.avatar = options.avatar as string;
|
|
|
|
|
}
|
|
|
|
|
if (options.emoji) {
|
|
|
|
|
body.emoji = options.emoji as string;
|
|
|
|
|
}
|
2021-01-24 11:38:16 -08:00
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
|
if (!jsonActive) {
|
|
|
|
|
const optionsAttachments = this.getNodeParameter('attachments', i) as IDataObject[];
|
|
|
|
|
if (optionsAttachments.length > 0) {
|
|
|
|
|
const attachments: IAttachment[] = [];
|
2022-12-02 12:54:28 -08:00
|
|
|
|
for (let index = 0; index < optionsAttachments.length; index++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
|
const attachment: IAttachment = {};
|
2022-12-02 12:54:28 -08:00
|
|
|
|
for (const option of Object.keys(optionsAttachments[index])) {
|
2021-07-19 23:58:54 -07:00
|
|
|
|
if (option === 'color') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.color = optionsAttachments[index][option] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'text') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.text = optionsAttachments[index][option] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'ts') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.ts = optionsAttachments[index][option] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'messageLinks') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.message_link = optionsAttachments[index][option] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'thumbUrl') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.thumb_url = optionsAttachments[index][option] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'collapsed') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.collapsed = optionsAttachments[index][option] as boolean;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'authorName') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.author_name = optionsAttachments[index][option] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'authorLink') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.author_link = optionsAttachments[index][option] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'authorIcon') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.author_icon = optionsAttachments[index][option] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'title') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.title = optionsAttachments[index][option] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'titleLink') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.title_link = optionsAttachments[index][option] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'titleLinkDownload') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.title_link_download = optionsAttachments[index][option] as boolean;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'imageUrl') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.image_url = optionsAttachments[index][option] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'audioUrl') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.audio_url = optionsAttachments[index][option] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'videoUrl') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
attachment.video_url = optionsAttachments[index][option] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (option === 'fields') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
const fieldsValues = (optionsAttachments[index][option] as IDataObject)
|
2022-08-17 08:50:24 -07:00
|
|
|
|
.fieldsValues as IDataObject[];
|
2021-07-19 23:58:54 -07:00
|
|
|
|
if (fieldsValues.length > 0) {
|
|
|
|
|
const fields: IField[] = [];
|
2022-12-02 12:54:28 -08:00
|
|
|
|
for (let j = 0; j < fieldsValues.length; j++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
|
const field: IField = {};
|
2022-12-02 12:54:28 -08:00
|
|
|
|
for (const key of Object.keys(fieldsValues[j])) {
|
2021-07-19 23:58:54 -07:00
|
|
|
|
if (key === 'short') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
field.short = fieldsValues[j][key] as boolean;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (key === 'title') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
field.title = fieldsValues[j][key] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else if (key === 'value') {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
field.value = fieldsValues[j][key] as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
}
|
2021-01-22 07:17:12 -08:00
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
|
fields.push(field);
|
|
|
|
|
attachment.fields = fields;
|
2019-11-10 21:00:24 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
|
attachments.push(attachment);
|
2019-11-10 21:00:24 -08:00
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
|
body.attachments = attachments;
|
2019-11-10 21:00:24 -08:00
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
body.attachments = validateJSON(
|
|
|
|
|
this.getNodeParameter('attachmentsJson', i) as string,
|
|
|
|
|
);
|
2019-11-10 21:00:24 -08:00
|
|
|
|
}
|
2021-01-24 11:38:16 -08:00
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
|
responseData = await rocketchatApiRequest.call(
|
|
|
|
|
this,
|
|
|
|
|
'/chat',
|
|
|
|
|
'POST',
|
|
|
|
|
'postMessage',
|
|
|
|
|
body,
|
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
}
|
2019-11-10 21:00:24 -08:00
|
|
|
|
}
|
2023-01-31 11:39:20 -08:00
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
2023-01-31 11:39:20 -08:00
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
|
);
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} catch (error) {
|
2024-06-19 22:45:00 -07:00
|
|
|
|
if (this.continueOnFail(error)) {
|
2023-01-31 11:39:20 -08:00
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
|
this.helpers.returnJsonArray({ error: error.message }),
|
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
|
);
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
throw error;
|
2019-11-10 21:00:24 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-13 13:29:52 -08:00
|
|
|
|
|
2023-09-05 03:59:02 -07:00
|
|
|
|
return [returnData];
|
2019-11-10 21:00:24 -08:00
|
|
|
|
}
|
2019-11-08 20:11:01 -08:00
|
|
|
|
}
|