pull:初次提交
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import type { ReactionProperties } from '../../Interfaces';
|
||||
|
||||
export const reactionCreateDescription: ReactionProperties = [
|
||||
{
|
||||
displayName: 'User Name or ID',
|
||||
name: 'userId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getUsers',
|
||||
},
|
||||
options: [],
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['reaction'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the user sending the reaction. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Post ID',
|
||||
name: 'postId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: '3moacfqxmbdw38r38fjprh6zsr',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['reaction'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the post to react to. Obtainable from the post link: <code>https://mattermost.internal.n8n.io/[server]/pl/[postId]</code>',
|
||||
},
|
||||
{
|
||||
displayName: 'Emoji Name',
|
||||
name: 'emojiName',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['reaction'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description: 'Emoji to use for this reaction',
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
|
||||
|
||||
import { apiRequest } from '../../../transport';
|
||||
|
||||
export async function create(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const qs = {} as IDataObject;
|
||||
const requestMethod = 'POST';
|
||||
const endpoint = 'reactions';
|
||||
const body = {
|
||||
user_id: this.getNodeParameter('userId', index),
|
||||
post_id: this.getNodeParameter('postId', index),
|
||||
emoji_name: (this.getNodeParameter('emojiName', index) as string).replace(/:/g, ''),
|
||||
create_at: Date.now(),
|
||||
} as { user_id: string; post_id: string; emoji_name: string; create_at: number };
|
||||
|
||||
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
|
||||
|
||||
return this.helpers.returnJsonArray(responseData as IDataObject[]);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { reactionCreateDescription as description } from './description';
|
||||
import { create as execute } from './execute';
|
||||
|
||||
export { description, execute };
|
||||
@@ -0,0 +1,53 @@
|
||||
import type { ReactionProperties } from '../../Interfaces';
|
||||
|
||||
export const reactionDeleteDescription: ReactionProperties = [
|
||||
{
|
||||
displayName: 'User Name or ID',
|
||||
name: 'userId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getUsers',
|
||||
},
|
||||
options: [],
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['reaction'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the user whose reaction to delete. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Post ID',
|
||||
name: 'postId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: '3moacfqxmbdw38r38fjprh6zsr',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['reaction'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the post whose reaction to delete. Obtainable from the post link: <code>https://mattermost.internal.n8n.io/[server]/pl/[postId]</code>',
|
||||
},
|
||||
{
|
||||
displayName: 'Emoji Name',
|
||||
name: 'emojiName',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['reaction'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
description: 'Name of the emoji to delete',
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
|
||||
|
||||
import { apiRequest } from '../../../transport';
|
||||
|
||||
export async function del(this: IExecuteFunctions, index: number): Promise<INodeExecutionData[]> {
|
||||
const userId = this.getNodeParameter('userId', index) as string;
|
||||
const postId = this.getNodeParameter('postId', index) as string;
|
||||
const emojiName = (this.getNodeParameter('emojiName', index) as string).replace(/:/g, '');
|
||||
|
||||
const qs = {} as IDataObject;
|
||||
const requestMethod = 'DELETE';
|
||||
const endpoint = `users/${userId}/posts/${postId}/reactions/${emojiName}`;
|
||||
const body = {} as IDataObject;
|
||||
|
||||
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
|
||||
|
||||
return this.helpers.returnJsonArray(responseData as IDataObject[]);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { reactionDeleteDescription as description } from './description';
|
||||
import { del as execute } from './execute';
|
||||
|
||||
export { description, execute };
|
||||
@@ -0,0 +1,49 @@
|
||||
import type { ReactionProperties } from '../../Interfaces';
|
||||
|
||||
export const reactionGetAllDescription: ReactionProperties = [
|
||||
{
|
||||
displayName: 'Post ID',
|
||||
name: 'postId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['reaction'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
description: 'One or more (comma-separated) posts to retrieve reactions from',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['reaction'],
|
||||
},
|
||||
},
|
||||
default: true,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['reaction'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 100,
|
||||
},
|
||||
default: 100,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
|
||||
|
||||
import { apiRequest } from '../../../transport';
|
||||
|
||||
export async function getAll(
|
||||
this: IExecuteFunctions,
|
||||
index: number,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const postId = this.getNodeParameter('postId', index) as string;
|
||||
const limit = this.getNodeParameter('limit', 0, 0);
|
||||
|
||||
const qs = {} as IDataObject;
|
||||
const requestMethod = 'GET';
|
||||
const endpoint = `posts/${postId}/reactions`;
|
||||
const body = {} as IDataObject;
|
||||
|
||||
let responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
|
||||
if (responseData === null) {
|
||||
return [];
|
||||
}
|
||||
if (limit > 0) {
|
||||
responseData = responseData.slice(0, limit);
|
||||
}
|
||||
return this.helpers.returnJsonArray(responseData as IDataObject[]);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { reactionGetAllDescription as description } from './description';
|
||||
import { getAll as execute } from './execute';
|
||||
|
||||
export { description, execute };
|
||||
@@ -0,0 +1,45 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as create from './create';
|
||||
import * as del from './del';
|
||||
import * as getAll from './getAll';
|
||||
|
||||
export { create, del as delete, getAll };
|
||||
|
||||
export const descriptions: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['reaction'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Add a reaction to a post',
|
||||
action: 'Create a reaction',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Remove a reaction from a post',
|
||||
action: 'Delete a reaction',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many reactions to one or more posts',
|
||||
action: 'Get many reactions',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
...create.description,
|
||||
...del.description,
|
||||
...getAll.description,
|
||||
];
|
||||
Reference in New Issue
Block a user