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

Specifies view submission response action types #404

Merged
merged 3 commits into from
Feb 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 44 additions & 3 deletions src/types/view/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { StringIndexed } from '../helpers';
import { RespondArguments, AckFn } from '../utilities';
import { AckFn } from '../utilities';
import { View } from '@slack/types';

/**
* Known view action types
Expand All @@ -13,7 +14,7 @@ export interface SlackViewMiddlewareArgs<ViewActionType extends SlackViewAction
payload: ViewOutput;
view: this['payload'];
body: ViewActionType;
ack: AckFn<string | RespondArguments>;
ack: ViewAckFn<ViewActionType>;
}

interface PlainTextElementOutput {
Expand Down Expand Up @@ -80,7 +81,13 @@ export interface ViewOutput {
blocks: StringIndexed; // TODO: should this just be any?
close: PlainTextElementOutput | null;
submit: PlainTextElementOutput | null;
state: object; // TODO: this should probably be expanded in the future
state: {
aoberoi marked this conversation as resolved.
Show resolved Hide resolved
values: {
[blockId: string]: {
[actionId: string]: any; // TODO: a union of all the input elements' output payload
Copy link
Member

@seratch seratch Feb 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this any type can be improved to support all the possible types like this https://github.com/slackapi/java-slack-sdk/blob/v1.0.8/slack-api-model/src/main/java/com/slack/api/model/view/ViewState.java but I’m fine to go with any at this moment.

};
};
};
hash: string;
private_metadata: string;
root_view_id: string | null;
Expand All @@ -89,3 +96,37 @@ export interface ViewOutput {
notify_on_close: boolean;
external_id?: string;
}

export interface ViewUpdateResponseAction {
response_action: 'update';
view: View;
}

export interface ViewPushResponseAction {
response_action: 'push';
view: View;
}

export interface ViewClearResponseAction {
response_action: 'clear';
}

export interface ViewErrorsResponseAction {
response_action: 'errors';
errors: {
[blockId: string]: string;
};
}

export type ViewResponseAction =
ViewUpdateResponseAction | ViewPushResponseAction | ViewClearResponseAction | ViewErrorsResponseAction;

/**
* Type function which given a view action `VA` returns a corresponding type for the `ack()` function. The function is
* used to acknowledge the receipt (and possibly signal failure) of an view submission or closure from a listener or
* middleware.
*/
type ViewAckFn<VA extends SlackViewAction = SlackViewAction> =
VA extends ViewSubmitAction ? AckFn<ViewResponseAction> :
// ViewClosedActions can only be acknowledged, there are no arguments
AckFn<void>;