From e94ae92a9634b7cbb3cc846773e8953570bd5f35 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Mon, 17 Feb 2020 19:56:04 +0900 Subject: [PATCH 1/3] Add checkboxes action payload --- src/types/actions/block-action.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/types/actions/block-action.ts b/src/types/actions/block-action.ts index 4e56b23fc..511cb67d1 100644 --- a/src/types/actions/block-action.ts +++ b/src/types/actions/block-action.ts @@ -20,7 +20,8 @@ export type BlockElementAction = | MultiExternalSelectAction | OverflowAction | DatepickerAction - | RadioButtonsAction; + | RadioButtonsAction + | CheckboxesAction; /** * Any action from Slack's interactive elements @@ -185,6 +186,15 @@ export interface RadioButtonsAction extends BasicElementAction<'radio_buttons'> confirm?: Confirmation; } +/** + * An action from a checkboxes element + */ +export interface CheckboxesAction extends BasicElementAction<'checkboxes'> { + selected_options: Option[]; + initial_options?: Option[]; + confirm?: Confirmation; +} + /** * A Slack Block Kit element action wrapped in the standard metadata. * From 4c10928afb60916e275ce7dc3001405ed6600750 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Mon, 17 Feb 2020 21:24:20 +0900 Subject: [PATCH 2/3] Fix #348 app.view() is not described in the README --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ab529bc99..24134744f 100644 --- a/README.md +++ b/README.md @@ -36,14 +36,19 @@ event, there's a method to attach a listener function. // Listen for an event from the Events API app.event(eventType, fn); -// Listen for an action from a block element (buttons, menus, etc), dialog submission, message action, or legacy action +// Listen for an action from a block element (buttons, menus, etc) app.action(actionId, fn); +// Listen for dialog submission, message action, or legacy action +app.action({ callback_id: callbackId }, fn); // Listen for a slash command app.command(commandName, fn); // Listen for options requests (from menus with an external data source) app.options(actionId, fn); + +// Listen for modal view requests +app.view(callbackId, fn); ``` There's a special method that's provided as a convenience to handle Events API events with the type `message`. Also, you From 9c63395dcaed64f9336b7eab0a69bb7ae4eaeb45 Mon Sep 17 00:00:00 2001 From: Ankur Oberoi Date: Mon, 17 Feb 2020 04:50:50 -0800 Subject: [PATCH 3/3] Specifies view submission response action types (#404) * specifies view submission response action types for use in .view() listener acks * fixes view submission state by adding values property --- src/types/view/index.ts | 47 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/src/types/view/index.ts b/src/types/view/index.ts index 411df4d51..af86548db 100644 --- a/src/types/view/index.ts +++ b/src/types/view/index.ts @@ -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 @@ -13,7 +14,7 @@ export interface SlackViewMiddlewareArgs; + ack: ViewAckFn; } interface PlainTextElementOutput { @@ -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: { + values: { + [blockId: string]: { + [actionId: string]: any; // TODO: a union of all the input elements' output payload + }; + }; + }; hash: string; private_metadata: string; root_view_id: string | null; @@ -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 ViewSubmitAction ? AckFn : + // ViewClosedActions can only be acknowledged, there are no arguments + AckFn;