🔀 Merge branch 'milekz-Mattermostintegration-update'

This commit is contained in:
Jan Oberhauser 2020-04-14 18:26:11 +02:00
commit e558009588
2 changed files with 311 additions and 95 deletions

View file

@ -7,14 +7,15 @@ import {
import { OptionsWithUri } from 'request'; import { OptionsWithUri } from 'request';
import { IDataObject } from 'n8n-workflow'; import { IDataObject } from 'n8n-workflow';
export interface IAttachment { export interface IAttachment {
fields: { fields: {
item?: object[]; item?: object[];
},
actions: {
item?: object[];
}; };
} }
/** /**
* Make an API request to Telegram * Make an API request to Telegram
* *

View file

@ -448,78 +448,178 @@ export class Mattermost implements INodeType {
placeholder: 'Add attachment item', placeholder: 'Add attachment item',
options: [ options: [
{ {
displayName: 'Fallback Text', displayName: 'Actions',
name: 'fallback', name: 'actions',
type: 'string', placeholder: 'Add Actions',
description: 'Actions to add to message. More information can be found <a href="https://docs.mattermost.com/developer/interactive-messages.html" target="_blank">here</a>',
type: 'fixedCollection',
typeOptions: { typeOptions: {
alwaysOpenEditWindow: true, multipleValues: true,
}, },
default: '', default: {},
description: 'Required plain-text summary of the attachment.', options: [
{
displayName: 'Item',
name: 'item',
values: [
{
displayName: 'Type',
name: 'type',
type: 'options',
options: [
{
name: 'Button',
value: 'button',
}, },
{ {
displayName: 'Text', name: 'Select',
value: 'select',
},
],
default: 'button',
description: 'The type of the action.',
},
{
displayName: 'Data Source',
name: 'data_source',
type: 'options',
displayOptions: {
show: {
type: [
'select'
],
},
},
options: [
{
name: 'Channels',
value: 'channels',
},
{
name: 'Custom',
value: 'custom',
},
{
name: 'Users',
value: 'users',
},
],
default: 'custom',
description: 'The type of the action.',
},
{
displayName: 'Options',
name: 'options',
placeholder: 'Add Option',
description: 'Adds a new option to select field.',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
displayOptions: {
show: {
data_source: [
'custom'
],
},
},
default: {},
options: [
{
name: 'option',
displayName: 'Option',
default: {},
values: [
{
displayName: 'Option Text',
name: 'text', name: 'text',
type: 'string', type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '', default: '',
description: 'Text to send.', description: 'Text of the option.',
}, },
{ {
displayName: 'Title', displayName: 'Option Value',
name: 'title', name: 'value',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'Title of the message.',
},
{
displayName: 'Title Link',
name: 'title_link',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'Link of the title.',
},
{
displayName: 'Color',
name: 'color',
type: 'color',
default: '#ff0000',
description: 'Color of the line left of text.',
},
{
displayName: 'Pretext',
name: 'pretext',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'Text which appears before the message block.',
},
{
displayName: 'Author Name',
name: 'author_name',
type: 'string', type: 'string',
default: '', default: '',
description: 'Name that should appear.', description: 'Value of the option.',
},
]
},
],
}, },
{ {
displayName: 'Author Link', displayName: 'Name',
name: 'author_link', name: 'name',
type: 'string', type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '', default: '',
description: 'Link for the author.', description: 'Name of the Action.',
},
{
displayName: 'Integration',
name: 'integration',
placeholder: 'Add Integration',
description: 'Integration to add to message.',
type: 'fixedCollection',
typeOptions: {
multipleValues: false,
},
default: {},
options: [
{
displayName: 'Item',
name: 'item',
default: {},
values: [
{
displayName: 'URL',
name: 'url',
type: 'string',
default: '',
description: 'URL of the Integration.',
},
{
displayName: 'Context',
name: 'context',
placeholder: 'Add Context to Integration',
description: 'Adds a Context values set.',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
name: 'property',
displayName: 'Property',
default: {},
values: [
{
displayName: 'Property Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the property to set.',
},
{
displayName: 'Property Value',
name: 'value',
type: 'string',
default: '',
description: 'Value of the property to set.',
},
]
},
],
},
]
},
],
},
]
},
],
}, },
{ {
displayName: 'Author Icon', displayName: 'Author Icon',
@ -532,44 +632,38 @@ export class Mattermost implements INodeType {
description: 'Icon which should appear for the user.', description: 'Icon which should appear for the user.',
}, },
{ {
displayName: 'Image URL', displayName: 'Author Link',
name: 'image_url', name: 'author_link',
type: 'string', type: 'string',
typeOptions: { typeOptions: {
alwaysOpenEditWindow: true, alwaysOpenEditWindow: true,
}, },
default: '', default: '',
description: 'URL of image.', description: 'Link for the author.',
}, },
{ {
displayName: 'Thumbnail URL', displayName: 'Author Name',
name: 'thumb_url', name: 'author_name',
type: 'string', type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '', default: '',
description: 'URL of thumbnail.', description: 'Name that should appear.',
}, },
{ {
displayName: 'Footer', displayName: 'Color',
name: 'footer', name: 'color',
type: 'string', type: 'color',
typeOptions: { default: '#ff0000',
alwaysOpenEditWindow: true, description: 'Color of the line left of text.',
},
default: '',
description: 'Text of footer to add.',
}, },
{ {
displayName: 'Footer Icon', displayName: 'Fallback Text',
name: 'footer_icon', name: 'fallback',
type: 'string', type: 'string',
typeOptions: { typeOptions: {
alwaysOpenEditWindow: true, alwaysOpenEditWindow: true,
}, },
default: '', default: '',
description: 'Icon which should appear next to footer.', description: 'Required plain-text summary of the attachment.',
}, },
{ {
displayName: 'Fields', displayName: 'Fields',
@ -610,7 +704,87 @@ export class Mattermost implements INodeType {
] ]
}, },
], ],
} },
{
displayName: 'Footer',
name: 'footer',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'Text of footer to add.',
},
{
displayName: 'Footer Icon',
name: 'footer_icon',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'Icon which should appear next to footer.',
},
{
displayName: 'Image URL',
name: 'image_url',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'URL of image.',
},
{
displayName: 'Pretext',
name: 'pretext',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'Text which appears before the message block.',
},
{
displayName: 'Text',
name: 'text',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'Text to send.',
},
{
displayName: 'Thumbnail URL',
name: 'thumb_url',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'URL of thumbnail.',
},
{
displayName: 'Title',
name: 'title',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'Title of the message.',
},
{
displayName: 'Title Link',
name: 'title_link',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'Link of the title.',
},
], ],
}, },
{ {
@ -890,6 +1064,47 @@ export class Mattermost implements INodeType {
} }
} }
} }
for (const attachment of attachments) {
if (attachment.actions !== undefined) {
if (attachment.actions.item !== undefined) {
// Move the field-content up
// @ts-ignore
attachment.actions = attachment.actions.item;
} else {
// If it does not have any items set remove it
delete attachment.actions;
}
}
}
for (const attachment of attachments) {
if (Array.isArray(attachment.actions)) {
for (const attaction of attachment.actions) {
if (attaction.type === 'button') {
delete attaction.type;
}
if (attaction.data_source === 'custom') {
delete attaction.data_source;
}
if (attaction.options) {
attaction.options = attaction.options.option;
}
if (attaction.integration.item !== undefined) {
attaction.integration = attaction.integration.item;
if (Array.isArray(attaction.integration.context.property)) {
const tmpcontex = {};
for (const attactionintegprop of attaction.integration.context.property) {
Object.assign(tmpcontex, { [attactionintegprop.name]: attactionintegprop.value });
}
delete attaction.integration.context;
attaction.integration.context = tmpcontex;
}
}
}
}
}
body.props = { body.props = {
attachments, attachments,