From 1b993e402297ac400c5167d1bcfa78e9a73c07df Mon Sep 17 00:00:00 2001 From: Matthew Walther Date: Sat, 19 Mar 2022 13:57:53 -0500 Subject: [PATCH] feat(Mattermost Node): Add support for Channel Search (#2687) * Squashed commit of the following: commit 9f76bdca9b4af4fd3ee429d1c381c3ed5529434c Author: Matt Walther Date: Sun Jan 16 16:40:34 2022 -0600 Mattermost Channel Search * Add more boilerplate so Search action renders * Changed order of search to make the operations alphabetical * :zap: Add pagination Co-authored-by: Jonathan Bennetts Co-authored-by: ricardo --- .../nodes/Mattermost/v1/actions/Interfaces.ts | 2 +- .../Mattermost/v1/actions/channel/index.ts | 10 ++- .../v1/actions/channel/search/description.ts | 88 +++++++++++++++++++ .../v1/actions/channel/search/execute.ts | 32 +++++++ .../v1/actions/channel/search/index.ts | 7 ++ 5 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 packages/nodes-base/nodes/Mattermost/v1/actions/channel/search/description.ts create mode 100644 packages/nodes-base/nodes/Mattermost/v1/actions/channel/search/execute.ts create mode 100644 packages/nodes-base/nodes/Mattermost/v1/actions/channel/search/index.ts diff --git a/packages/nodes-base/nodes/Mattermost/v1/actions/Interfaces.ts b/packages/nodes-base/nodes/Mattermost/v1/actions/Interfaces.ts index b9d6dd7efa..dceb5c94c4 100644 --- a/packages/nodes-base/nodes/Mattermost/v1/actions/Interfaces.ts +++ b/packages/nodes-base/nodes/Mattermost/v1/actions/Interfaces.ts @@ -5,7 +5,7 @@ import { } from 'n8n-workflow'; type MattermostMap = { - channel: 'addUser' | 'create' | 'delete' | 'members' | 'restore' | 'statistics'; + channel: 'addUser' | 'create' | 'delete' | 'members' | 'restore' | 'statistics' | 'search'; message: 'delete' | 'post' | 'postEphemeral'; reaction: 'create' | 'delete' | 'getAll'; user: 'create' | 'deactive' | 'getAll' | 'getByEmail' | 'getById' | 'invite'; diff --git a/packages/nodes-base/nodes/Mattermost/v1/actions/channel/index.ts b/packages/nodes-base/nodes/Mattermost/v1/actions/channel/index.ts index ba51251fea..ba3648ad0a 100644 --- a/packages/nodes-base/nodes/Mattermost/v1/actions/channel/index.ts +++ b/packages/nodes-base/nodes/Mattermost/v1/actions/channel/index.ts @@ -4,6 +4,7 @@ import * as members from './members'; import * as restore from './restore'; import * as addUser from './addUser'; import * as statistics from './statistics'; +import * as search from './search'; import { INodeProperties } from 'n8n-workflow'; export { @@ -13,6 +14,7 @@ export { restore, addUser, statistics, + search, }; @@ -54,6 +56,11 @@ export const descriptions: INodeProperties[] = [ value: 'restore', description: 'Restores a soft deleted channel', }, + { + name: 'Search', + value: 'search', + description: 'Search for a channel', + }, { name: 'Statistics', value: 'statistics', @@ -69,4 +76,5 @@ export const descriptions: INodeProperties[] = [ ...restore.description, ...addUser.description, ...statistics.description, -]; \ No newline at end of file + ...search.description, +]; diff --git a/packages/nodes-base/nodes/Mattermost/v1/actions/channel/search/description.ts b/packages/nodes-base/nodes/Mattermost/v1/actions/channel/search/description.ts new file mode 100644 index 0000000000..29569d9d48 --- /dev/null +++ b/packages/nodes-base/nodes/Mattermost/v1/actions/channel/search/description.ts @@ -0,0 +1,88 @@ +import { + ChannelProperties, +} from '../../Interfaces'; + +export const channelSearchDescription: ChannelProperties = [ + { + displayName: 'Team ID', + name: 'teamId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getTeams', + }, + options: [], + default: '', + required: true, + displayOptions: { + show: { + operation: [ + 'search', + ], + resource: [ + 'channel', + ], + }, + }, + description: 'The Mattermost Team.', + }, + { + displayName: 'Search Term', + name: 'term', + type: 'string', + default: '', + placeholder: 'General', + displayOptions: { + show: { + operation: [ + 'search', + ], + resource: [ + 'channel', + ], + }, + }, + required: true, + description: 'The search term for Channels in a Team', + }, + { + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + default: false, + description: 'Whether to return all results', + displayOptions: { + show: { + operation: [ + 'search', + ], + resource: [ + 'channel', + ], + }, + }, + }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + default: 100, + description: 'The number of results to return', + typeOptions: { + minValue: 1, + maxValue: 100, + }, + displayOptions: { + show: { + operation: [ + 'search', + ], + resource: [ + 'channel', + ], + returnAll: [ + false, + ], + }, + }, + }, +]; diff --git a/packages/nodes-base/nodes/Mattermost/v1/actions/channel/search/execute.ts b/packages/nodes-base/nodes/Mattermost/v1/actions/channel/search/execute.ts new file mode 100644 index 0000000000..b327cd0c0f --- /dev/null +++ b/packages/nodes-base/nodes/Mattermost/v1/actions/channel/search/execute.ts @@ -0,0 +1,32 @@ +import { + IExecuteFunctions, +} from 'n8n-core'; + +import { + IDataObject, + INodeExecutionData, +} from 'n8n-workflow'; + +import { + apiRequest, +} from '../../../transport'; + +export async function search(this: IExecuteFunctions, index: number): Promise { + const body = {} as IDataObject; + const qs = {} as IDataObject; + const requestMethod = 'POST'; + const teamId = this.getNodeParameter('teamId', index); + const returnAll = this.getNodeParameter('returnAll', 0); + const endpoint = `teams/${teamId}/channels/search`; + + body.term = this.getNodeParameter('term', index) as string; + + let responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs); + + if (!returnAll) { + const limit = this.getNodeParameter('limit', 0); + responseData = responseData.slice(0, limit); + } + + return this.helpers.returnJsonArray(responseData); +} \ No newline at end of file diff --git a/packages/nodes-base/nodes/Mattermost/v1/actions/channel/search/index.ts b/packages/nodes-base/nodes/Mattermost/v1/actions/channel/search/index.ts new file mode 100644 index 0000000000..496d57ca4b --- /dev/null +++ b/packages/nodes-base/nodes/Mattermost/v1/actions/channel/search/index.ts @@ -0,0 +1,7 @@ +import { search as execute } from './execute'; +import { channelSearchDescription as description } from './description'; + +export { + description, + execute, +};