mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-04 18:08:54 +00:00
This PR adds comprehensive support for advanced interactive dialog features through the DialogRouter component, which routes between legacy InteractiveDialog and modern AppsForm implementations based on the FeatureFlagInteractiveDialogAppsForm feature flag.
72 lines
2.7 KiB
TypeScript
72 lines
2.7 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {buildQueryString} from '@utils/helpers';
|
|
|
|
import {PER_PAGE_DEFAULT} from './constants';
|
|
|
|
import type ClientBase from './base';
|
|
|
|
export interface ClientIntegrationsMix {
|
|
getCommandsList: (teamId: string) => Promise<Command[]>;
|
|
getCommandAutocompleteSuggestionsList: (userInput: string, teamId: string, channelId: string, rootId?: string) => Promise<AutocompleteSuggestion[]>;
|
|
getAutocompleteCommandsList: (teamId: string, page?: number, perPage?: number) => Promise<Command[]>;
|
|
executeCommand: (command: string, commandArgs?: CommandArgs) => Promise<CommandResponse>;
|
|
addCommand: (command: Command) => Promise<Command>;
|
|
submitInteractiveDialog: (data: DialogSubmission) => Promise<any>;
|
|
lookupInteractiveDialog: (data: DialogSubmission) => Promise<any>;
|
|
}
|
|
|
|
const ClientIntegrations = <TBase extends Constructor<ClientBase>>(superclass: TBase) => class extends superclass {
|
|
getCommandsList = async (teamId: string) => {
|
|
return this.doFetch(
|
|
`${this.getCommandsRoute()}?team_id=${teamId}`,
|
|
{method: 'get'},
|
|
);
|
|
};
|
|
|
|
getCommandAutocompleteSuggestionsList = async (userInput: string, teamId: string, channelId: string, rootId?: string) => {
|
|
return this.doFetch(
|
|
`${this.getTeamRoute(teamId)}/commands/autocomplete_suggestions${buildQueryString({user_input: userInput, team_id: teamId, channel_id: channelId, root_id: rootId})}`,
|
|
{method: 'get'},
|
|
);
|
|
};
|
|
|
|
getAutocompleteCommandsList = async (teamId: string, page = 0, perPage = PER_PAGE_DEFAULT) => {
|
|
return this.doFetch(
|
|
`${this.getTeamRoute(teamId)}/commands/autocomplete${buildQueryString({page, per_page: perPage})}`,
|
|
{method: 'get'},
|
|
);
|
|
};
|
|
|
|
executeCommand = async (command: string, commandArgs = {}) => {
|
|
return this.doFetch(
|
|
`${this.getCommandsRoute()}/execute`,
|
|
{method: 'post', body: {command, ...commandArgs}},
|
|
);
|
|
};
|
|
|
|
addCommand = async (command: Command) => {
|
|
return this.doFetch(
|
|
`${this.getCommandsRoute()}`,
|
|
{method: 'post', body: command},
|
|
);
|
|
};
|
|
|
|
submitInteractiveDialog = async (data: DialogSubmission) => {
|
|
return this.doFetch(
|
|
`${this.urlVersion}/actions/dialogs/submit`,
|
|
{method: 'post', body: data},
|
|
);
|
|
};
|
|
|
|
lookupInteractiveDialog = async (data: DialogSubmission) => {
|
|
return this.doFetch(
|
|
`${this.urlVersion}/actions/dialogs/lookup`,
|
|
{method: 'post', body: data},
|
|
);
|
|
};
|
|
};
|
|
|
|
export default ClientIntegrations;
|