mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
feat(Mattermost Node): Add support for Channel Search (#2687)
* Squashed commit of the following:
commit 9f76bdca9b4af4fd3ee429d1c381c3ed5529434c
Author: Matt Walther <matt@mashio.net>
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
* ⚡ Add pagination
Co-authored-by: Jonathan Bennetts <jonathan.bennetts@gmail.com>
Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
parent
5658593df4
commit
1b993e4022
|
@ -5,7 +5,7 @@ import {
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
type MattermostMap = {
|
type MattermostMap = {
|
||||||
channel: 'addUser' | 'create' | 'delete' | 'members' | 'restore' | 'statistics';
|
channel: 'addUser' | 'create' | 'delete' | 'members' | 'restore' | 'statistics' | 'search';
|
||||||
message: 'delete' | 'post' | 'postEphemeral';
|
message: 'delete' | 'post' | 'postEphemeral';
|
||||||
reaction: 'create' | 'delete' | 'getAll';
|
reaction: 'create' | 'delete' | 'getAll';
|
||||||
user: 'create' | 'deactive' | 'getAll' | 'getByEmail' | 'getById' | 'invite';
|
user: 'create' | 'deactive' | 'getAll' | 'getByEmail' | 'getById' | 'invite';
|
||||||
|
|
|
@ -4,6 +4,7 @@ import * as members from './members';
|
||||||
import * as restore from './restore';
|
import * as restore from './restore';
|
||||||
import * as addUser from './addUser';
|
import * as addUser from './addUser';
|
||||||
import * as statistics from './statistics';
|
import * as statistics from './statistics';
|
||||||
|
import * as search from './search';
|
||||||
import { INodeProperties } from 'n8n-workflow';
|
import { INodeProperties } from 'n8n-workflow';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -13,6 +14,7 @@ export {
|
||||||
restore,
|
restore,
|
||||||
addUser,
|
addUser,
|
||||||
statistics,
|
statistics,
|
||||||
|
search,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,6 +56,11 @@ export const descriptions: INodeProperties[] = [
|
||||||
value: 'restore',
|
value: 'restore',
|
||||||
description: 'Restores a soft deleted channel',
|
description: 'Restores a soft deleted channel',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Search',
|
||||||
|
value: 'search',
|
||||||
|
description: 'Search for a channel',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Statistics',
|
name: 'Statistics',
|
||||||
value: 'statistics',
|
value: 'statistics',
|
||||||
|
@ -69,4 +76,5 @@ export const descriptions: INodeProperties[] = [
|
||||||
...restore.description,
|
...restore.description,
|
||||||
...addUser.description,
|
...addUser.description,
|
||||||
...statistics.description,
|
...statistics.description,
|
||||||
|
...search.description,
|
||||||
];
|
];
|
|
@ -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,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
|
@ -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<INodeExecutionData[]> {
|
||||||
|
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);
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { search as execute } from './execute';
|
||||||
|
import { channelSearchDescription as description } from './description';
|
||||||
|
|
||||||
|
export {
|
||||||
|
description,
|
||||||
|
execute,
|
||||||
|
};
|
Loading…
Reference in a new issue