Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mattermost Channel Search - N8N-3129 #2687

Merged
merged 5 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -13,6 +14,7 @@ export {
restore,
addUser,
statistics,
search,
};


Expand Down Expand Up @@ -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',
Expand All @@ -69,4 +76,5 @@ export const descriptions: INodeProperties[] = [
...restore.description,
...addUser.description,
...statistics.description,
];
...search.description,
];
Original file line number Diff line number Diff line change
@@ -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,
],
},
},
},
];
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { search as execute } from './execute';
import { channelSearchDescription as description } from './description';

export {
description,
execute,
};