From 26fbd6dec7b1d09b05e7598edd96bc66d20a62fa Mon Sep 17 00:00:00 2001 From: Steve Gill Date: Wed, 8 Jan 2020 20:10:30 -0800 Subject: [PATCH 1/5] Added support for global actions --- src/helpers.ts | 2 +- src/middleware/builtin.ts | 2 ++ src/types/actions/global-action.ts | 27 +++++++++++++++++++++++++++ src/types/actions/index.ts | 4 +++- 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/types/actions/global-action.ts diff --git a/src/helpers.ts b/src/helpers.ts index b7d8aa312..997bd56ca 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -47,7 +47,7 @@ export function getTypeAndConversation(body: any): { type?: IncomingEventType, c conversationId: optionsBody.channel !== undefined ? optionsBody.channel.id : undefined, }; } - if (body.actions !== undefined || body.type === 'dialog_submission' || body.type === 'message_action') { + if (body.actions !== undefined || body.type === 'dialog_submission' || body.type === 'message_action' || body.type === 'global_action') { const actionBody = (body as SlackActionMiddlewareArgs['body']); return { type: IncomingEventType.Action, diff --git a/src/middleware/builtin.ts b/src/middleware/builtin.ts index 8054191b6..f4fcddc81 100644 --- a/src/middleware/builtin.ts +++ b/src/middleware/builtin.ts @@ -14,6 +14,7 @@ import { OptionsRequest, InteractiveMessage, DialogSubmitAction, + GlobalAction, MessageAction, BlockElementAction, ContextMissingPropertyError, @@ -338,6 +339,7 @@ type CallbackIdentifiedBody = | InteractiveMessage | DialogSubmitAction | MessageAction + | GlobalAction | OptionsRequest<'interactive_message' | 'dialog_suggestion'>; function isCallbackIdentifiedBody( diff --git a/src/types/actions/global-action.ts b/src/types/actions/global-action.ts new file mode 100644 index 000000000..a14165893 --- /dev/null +++ b/src/types/actions/global-action.ts @@ -0,0 +1,27 @@ +/** + * A Slack global action wrapped in the standard metadata. + * + * This describes the entire JSON-encoded body of a request from Slack global actions. + */ +export interface GlobalAction { + type: 'global_action'; + callback_id: string; + trigger_id: string; + user: { + id: string; + name: string; + team_id?: string; // undocumented + }; + channel: { + id: string; + name: string; + }; + team: { + id: string; + domain: string; + enterprise_id?: string; // undocumented + enterprise_name?: string; // undocumented + }; + token: string; + action_ts: string; +} diff --git a/src/types/actions/index.ts b/src/types/actions/index.ts index 0af300fc8..0582e2ee3 100644 --- a/src/types/actions/index.ts +++ b/src/types/actions/index.ts @@ -2,11 +2,13 @@ export * from './block-action'; export * from './interactive-message'; export * from './dialog-action'; export * from './message-action'; +export * from './global-action'; import { BlockAction } from './block-action'; import { InteractiveMessage } from './interactive-message'; import { DialogSubmitAction, DialogValidation } from './dialog-action'; import { MessageAction } from './message-action'; +import { GlobalAction } from './global-action'; import { SayFn, SayArguments, RespondFn, AckFn } from '../utilities'; /** @@ -23,7 +25,7 @@ import { SayFn, SayArguments, RespondFn, AckFn } from '../utilities'; * offered when no generic parameter is bound would be limited to BasicElementAction rather than the union of known * actions - ElementAction. */ -export type SlackAction = BlockAction | InteractiveMessage | DialogSubmitAction | MessageAction; +export type SlackAction = BlockAction | InteractiveMessage | DialogSubmitAction | MessageAction | GlobalAction; /** * Arguments which listeners and middleware receive to process an action from Slack's Block Kit interactive components, From 02a7784b92d89386a08183e3eb01cde2a44b24f9 Mon Sep 17 00:00:00 2001 From: Steve Gill Date: Fri, 14 Feb 2020 11:16:14 -0800 Subject: [PATCH 2/5] updated for new shortcut payload --- src/helpers.ts | 2 +- src/middleware/builtin.ts | 4 ++-- src/types/actions/index.ts | 6 +++--- .../actions/{global-action.ts => shortcut.ts} | 17 ++++++++--------- 4 files changed, 14 insertions(+), 15 deletions(-) rename src/types/actions/{global-action.ts => shortcut.ts} (54%) diff --git a/src/helpers.ts b/src/helpers.ts index 997bd56ca..e52ce5405 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -47,7 +47,7 @@ export function getTypeAndConversation(body: any): { type?: IncomingEventType, c conversationId: optionsBody.channel !== undefined ? optionsBody.channel.id : undefined, }; } - if (body.actions !== undefined || body.type === 'dialog_submission' || body.type === 'message_action' || body.type === 'global_action') { + if (body.actions !== undefined || body.type === 'dialog_submission' || body.type === 'message_action' || body.type === 'shortcut') { const actionBody = (body as SlackActionMiddlewareArgs['body']); return { type: IncomingEventType.Action, diff --git a/src/middleware/builtin.ts b/src/middleware/builtin.ts index f4fcddc81..a309a57fb 100644 --- a/src/middleware/builtin.ts +++ b/src/middleware/builtin.ts @@ -14,7 +14,7 @@ import { OptionsRequest, InteractiveMessage, DialogSubmitAction, - GlobalAction, + Shortcut, MessageAction, BlockElementAction, ContextMissingPropertyError, @@ -339,7 +339,7 @@ type CallbackIdentifiedBody = | InteractiveMessage | DialogSubmitAction | MessageAction - | GlobalAction + | Shortcut | OptionsRequest<'interactive_message' | 'dialog_suggestion'>; function isCallbackIdentifiedBody( diff --git a/src/types/actions/index.ts b/src/types/actions/index.ts index 0582e2ee3..4d1fc694f 100644 --- a/src/types/actions/index.ts +++ b/src/types/actions/index.ts @@ -2,13 +2,13 @@ export * from './block-action'; export * from './interactive-message'; export * from './dialog-action'; export * from './message-action'; -export * from './global-action'; +export * from './shortcut'; import { BlockAction } from './block-action'; import { InteractiveMessage } from './interactive-message'; import { DialogSubmitAction, DialogValidation } from './dialog-action'; import { MessageAction } from './message-action'; -import { GlobalAction } from './global-action'; +import { Shortcut } from './shortcut'; import { SayFn, SayArguments, RespondFn, AckFn } from '../utilities'; /** @@ -25,7 +25,7 @@ import { SayFn, SayArguments, RespondFn, AckFn } from '../utilities'; * offered when no generic parameter is bound would be limited to BasicElementAction rather than the union of known * actions - ElementAction. */ -export type SlackAction = BlockAction | InteractiveMessage | DialogSubmitAction | MessageAction | GlobalAction; +export type SlackAction = BlockAction | InteractiveMessage | DialogSubmitAction | MessageAction | Shortcut; /** * Arguments which listeners and middleware receive to process an action from Slack's Block Kit interactive components, diff --git a/src/types/actions/global-action.ts b/src/types/actions/shortcut.ts similarity index 54% rename from src/types/actions/global-action.ts rename to src/types/actions/shortcut.ts index a14165893..957678a16 100644 --- a/src/types/actions/global-action.ts +++ b/src/types/actions/shortcut.ts @@ -3,24 +3,23 @@ * * This describes the entire JSON-encoded body of a request from Slack global actions. */ -export interface GlobalAction { - type: 'global_action'; +export interface Shortcut { + type: 'shortcut'; callback_id: string; trigger_id: string; user: { id: string; name: string; - team_id?: string; // undocumented - }; - channel: { - id: string; - name: string; }; + // remove this once we move to shortcut method + // needed because of line 54 in helpers.ts + channel?: undefined; team: { id: string; domain: string; - enterprise_id?: string; // undocumented - enterprise_name?: string; // undocumented + // remove this once we move to shortcut + // needed because of line 540 in App.ts + enterprise_id?: string; }; token: string; action_ts: string; From 78355bb5248f1c1917b33d6d2bd2f1634a991d27 Mon Sep 17 00:00:00 2001 From: Steve Gill Date: Mon, 16 Mar 2020 10:34:21 -0700 Subject: [PATCH 3/5] added new shortcut method --- src/App.ts | 55 +++++++++++++++---- src/helpers.ts | 8 ++- src/middleware/builtin.ts | 25 +++++++-- src/types/actions/index.ts | 4 +- src/types/index.ts | 1 + src/types/middleware.ts | 3 +- .../global-shortcut.ts} | 5 +- src/types/shortcuts/index.ts | 38 +++++++++++++ 8 files changed, 115 insertions(+), 24 deletions(-) rename src/types/{actions/shortcut.ts => shortcuts/global-shortcut.ts} (76%) create mode 100644 src/types/shortcuts/index.ts diff --git a/src/App.ts b/src/App.ts index 27b9a123d..8aa82f9a4 100644 --- a/src/App.ts +++ b/src/App.ts @@ -9,6 +9,7 @@ import { onlyCommands, matchCommandName, onlyOptions, + onlyShortcuts, onlyEvents, matchEventType, matchMessage, @@ -23,8 +24,10 @@ import { SlackCommandMiddlewareArgs, SlackEventMiddlewareArgs, SlackOptionsMiddlewareArgs, + SlackShortcutMiddlewareArgs, SlackViewMiddlewareArgs, SlackAction, + SlackShortcut, Context, SayFn, AckFn, @@ -93,6 +96,11 @@ export interface ActionConstraints { callback_id?: Extract extends any ? (string | RegExp) : never; } +export interface ShortcutConstraints { + type?: S['type']; + callback_id?: string | RegExp; +} + export interface ViewConstraints { callback_id?: string | RegExp; type?: 'view_closed' | 'view_submission'; @@ -296,6 +304,27 @@ export default class App { ); } + public shortcut( + callbackId: string | RegExp, + ...listeners: Middleware>[] + ): void; + public shortcut( + constraints: ShortcutConstraints, + ...listeners: Middleware>[] + ): void; + public shortcut( + callbackIdOrConstraints: string | RegExp | ShortcutConstraints, + ...listeners: Middleware>[] + ): void { + const constraints: ShortcutConstraints = + (typeof callbackIdOrConstraints === 'string' || util.types.isRegExp(callbackIdOrConstraints)) ? + { callback_id: callbackIdOrConstraints } : callbackIdOrConstraints; + + this.listeners.push( + [onlyShortcuts, matchConstraints(constraints), ...listeners] as Middleware[], + ); + } + // NOTE: this is what's called a convenience generic, so that types flow more easily without casting. // https://basarat.gitbooks.io/typescript/docs/types/generics.html#design-pattern-convenience-generic public action( @@ -405,6 +434,7 @@ export default class App { * Handles events from the receiver */ private async onIncomingEvent({ body, ack, respond }: ReceiverEvent): Promise { + // TODO: when generating errors (such as in the say utility) it may become useful to capture the current context, // or even all of the args, as properties of the error. This would give error handling code some ability to deal // with "finally" type error situations. @@ -474,13 +504,15 @@ export default class App { (bodyArg as SlackEventMiddlewareArgs['body']).event : (type === IncomingEventType.ViewAction) ? (bodyArg as SlackViewMiddlewareArgs['body']).view : - (type === IncomingEventType.Action && - isBlockActionOrInteractiveMessageBody(bodyArg as SlackActionMiddlewareArgs['body'])) ? - (bodyArg as SlackActionMiddlewareArgs['body']).actions[0] : - (bodyArg as ( - Exclude | SlackActionMiddlewareArgs> + (type === IncomingEventType.Shortcut) ? + (bodyArg as SlackShortcutMiddlewareArgs['body']) : + (type === IncomingEventType.Action && + isBlockActionOrInteractiveMessageBody(bodyArg as SlackActionMiddlewareArgs['body'])) ? + (bodyArg as SlackActionMiddlewareArgs['body']).actions[0] : + (bodyArg as ( + Exclude | SlackActionMiddlewareArgs> )['body']), }; @@ -504,6 +536,9 @@ export default class App { } else if (type === IncomingEventType.ViewAction) { const viewListenerArgs = listenerArgs as SlackViewMiddlewareArgs; viewListenerArgs.view = viewListenerArgs.payload; + } else if (type === IncomingEventType.Shortcut) { + const shortcutListenerArgs = listenerArgs as SlackShortcutMiddlewareArgs; + shortcutListenerArgs.shortcut = shortcutListenerArgs.payload; } // Set say() utility @@ -586,11 +621,11 @@ function buildSource( const source: AuthorizeSourceData = { teamId: ((type === IncomingEventType.Event || type === IncomingEventType.Command) ? (body as (SlackEventMiddlewareArgs | SlackCommandMiddlewareArgs)['body']).team_id as string : - (type === IncomingEventType.Action || type === IncomingEventType.Options || type === IncomingEventType.ViewAction) ? (body as (SlackActionMiddlewareArgs | SlackOptionsMiddlewareArgs | SlackViewMiddlewareArgs)['body']).team.id as string : + (type === IncomingEventType.Action || type === IncomingEventType.Options || type === IncomingEventType.ViewAction || type === IncomingEventType.Shortcut) ? (body as (SlackActionMiddlewareArgs | SlackOptionsMiddlewareArgs | SlackViewMiddlewareArgs | SlackShortcutMiddlewareArgs)['body']).team.id as string : assertNever(type)), enterpriseId: ((type === IncomingEventType.Event || type === IncomingEventType.Command) ? (body as (SlackEventMiddlewareArgs | SlackCommandMiddlewareArgs)['body']).enterprise_id as string : - (type === IncomingEventType.Action || type === IncomingEventType.Options || type === IncomingEventType.ViewAction) ? (body as (SlackActionMiddlewareArgs | SlackOptionsMiddlewareArgs | SlackViewMiddlewareArgs)['body']).team.enterprise_id as string : + (type === IncomingEventType.Action || type === IncomingEventType.Options || type === IncomingEventType.ViewAction || type === IncomingEventType.Shortcut) ? (body as (SlackActionMiddlewareArgs | SlackOptionsMiddlewareArgs | SlackViewMiddlewareArgs | SlackShortcutMiddlewareArgs)['body']).team.enterprise_id as string : undefined), userId: ((type === IncomingEventType.Event) ? @@ -599,7 +634,7 @@ function buildSource( ((body as SlackEventMiddlewareArgs['body']).event.channel !== undefined && (body as SlackEventMiddlewareArgs['body']).event.channel.creator !== undefined) ? (body as SlackEventMiddlewareArgs['body']).event.channel.creator as string : ((body as SlackEventMiddlewareArgs['body']).event.subteam !== undefined && (body as SlackEventMiddlewareArgs['body']).event.subteam.created_by !== undefined) ? (body as SlackEventMiddlewareArgs['body']).event.subteam.created_by as string : undefined) : - (type === IncomingEventType.Action || type === IncomingEventType.Options || type === IncomingEventType.ViewAction) ? (body as (SlackActionMiddlewareArgs | SlackOptionsMiddlewareArgs | SlackViewMiddlewareArgs)['body']).user.id as string : + (type === IncomingEventType.Action || type === IncomingEventType.Options || type === IncomingEventType.ViewAction || type === IncomingEventType.Shortcut) ? (body as (SlackActionMiddlewareArgs | SlackOptionsMiddlewareArgs | SlackViewMiddlewareArgs)['body']).user.id as string : (type === IncomingEventType.Command) ? (body as SlackCommandMiddlewareArgs['body']).user_id as string : undefined), conversationId: channelId, diff --git a/src/helpers.ts b/src/helpers.ts index e52ce5405..24b77edc6 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -16,6 +16,7 @@ export enum IncomingEventType { Command, Options, ViewAction, + Shortcut, } /** @@ -47,13 +48,18 @@ export function getTypeAndConversation(body: any): { type?: IncomingEventType, c conversationId: optionsBody.channel !== undefined ? optionsBody.channel.id : undefined, }; } - if (body.actions !== undefined || body.type === 'dialog_submission' || body.type === 'message_action' || body.type === 'shortcut') { + if (body.actions !== undefined || body.type === 'dialog_submission' || body.type === 'message_action') { const actionBody = (body as SlackActionMiddlewareArgs['body']); return { type: IncomingEventType.Action, conversationId: actionBody.channel !== undefined ? actionBody.channel.id : undefined, }; } + if (body.type === 'shortcut') { + return { + type: IncomingEventType.Shortcut, + }; + } if (body.type === 'view_submission' || body.type === 'view_closed') { return { type: IncomingEventType.ViewAction, diff --git a/src/middleware/builtin.ts b/src/middleware/builtin.ts index a309a57fb..c3980db9e 100644 --- a/src/middleware/builtin.ts +++ b/src/middleware/builtin.ts @@ -5,22 +5,24 @@ import { SlackCommandMiddlewareArgs, SlackEventMiddlewareArgs, SlackOptionsMiddlewareArgs, + SlackShortcutMiddlewareArgs, SlackViewMiddlewareArgs, SlackEvent, SlackAction, + SlackShortcut, SlashCommand, ViewSubmitAction, ViewClosedAction, OptionsRequest, InteractiveMessage, DialogSubmitAction, - Shortcut, + GlobalShortcut, MessageAction, BlockElementAction, ContextMissingPropertyError, SlackViewAction, } from '../types'; -import { ActionConstraints, ViewConstraints } from '../App'; +import { ActionConstraints, ViewConstraints, ShortcutConstraints } from '../App'; import { ErrorCode, errorWithCode } from '../errors'; /** @@ -36,6 +38,19 @@ export const onlyActions: Middleware = ({ shortcut, next }) => { + // Filter out any non-actions + if (shortcut === undefined) { + return; + } + + // It matches so we should continue down this middleware listener chain + next(); +}; + /** * Middleware that filters out any event that isn't a command */ @@ -93,7 +108,7 @@ export const onlyViewActions: Middleware { return ({ payload, body, next, context }) => { // TODO: is putting matches in an array actually helpful? there's no way to know which of the regexps contributed @@ -339,11 +354,11 @@ type CallbackIdentifiedBody = | InteractiveMessage | DialogSubmitAction | MessageAction - | Shortcut + | GlobalShortcut | OptionsRequest<'interactive_message' | 'dialog_suggestion'>; function isCallbackIdentifiedBody( - body: SlackActionMiddlewareArgs['body'] | SlackOptionsMiddlewareArgs['body'], + body: SlackActionMiddlewareArgs['body'] | SlackOptionsMiddlewareArgs['body'] | SlackShortcutMiddlewareArgs['body'], ): body is CallbackIdentifiedBody { return (body as CallbackIdentifiedBody).callback_id !== undefined; } diff --git a/src/types/actions/index.ts b/src/types/actions/index.ts index 4d1fc694f..0af300fc8 100644 --- a/src/types/actions/index.ts +++ b/src/types/actions/index.ts @@ -2,13 +2,11 @@ export * from './block-action'; export * from './interactive-message'; export * from './dialog-action'; export * from './message-action'; -export * from './shortcut'; import { BlockAction } from './block-action'; import { InteractiveMessage } from './interactive-message'; import { DialogSubmitAction, DialogValidation } from './dialog-action'; import { MessageAction } from './message-action'; -import { Shortcut } from './shortcut'; import { SayFn, SayArguments, RespondFn, AckFn } from '../utilities'; /** @@ -25,7 +23,7 @@ import { SayFn, SayArguments, RespondFn, AckFn } from '../utilities'; * offered when no generic parameter is bound would be limited to BasicElementAction rather than the union of known * actions - ElementAction. */ -export type SlackAction = BlockAction | InteractiveMessage | DialogSubmitAction | MessageAction | Shortcut; +export type SlackAction = BlockAction | InteractiveMessage | DialogSubmitAction | MessageAction; /** * Arguments which listeners and middleware receive to process an action from Slack's Block Kit interactive components, diff --git a/src/types/index.ts b/src/types/index.ts index 2d05a8ded..4d3c2d92b 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,3 +6,4 @@ export * from './events'; export * from './options'; export * from './view'; export * from './receiver'; +export * from './shortcuts'; diff --git a/src/types/middleware.ts b/src/types/middleware.ts index ff7954f38..df4554aa0 100644 --- a/src/types/middleware.ts +++ b/src/types/middleware.ts @@ -3,6 +3,7 @@ import { SlackEventMiddlewareArgs } from './events'; import { SlackActionMiddlewareArgs } from './actions'; import { SlackCommandMiddlewareArgs } from './command'; import { SlackOptionsMiddlewareArgs } from './options'; +import { SlackShortcutMiddlewareArgs } from './shortcuts'; import { SlackViewMiddlewareArgs } from './view'; import { CodedError, ErrorCode } from '../errors'; import { WebClient } from '@slack/web-api'; @@ -10,7 +11,7 @@ import { Logger } from '@slack/logger'; export type AnyMiddlewareArgs = SlackEventMiddlewareArgs | SlackActionMiddlewareArgs | SlackCommandMiddlewareArgs | - SlackOptionsMiddlewareArgs | SlackViewMiddlewareArgs; + SlackOptionsMiddlewareArgs | SlackViewMiddlewareArgs | SlackShortcutMiddlewareArgs; export interface PostProcessFn { (error: Error | undefined, done: (error?: Error) => void): unknown; diff --git a/src/types/actions/shortcut.ts b/src/types/shortcuts/global-shortcut.ts similarity index 76% rename from src/types/actions/shortcut.ts rename to src/types/shortcuts/global-shortcut.ts index 957678a16..8be32c326 100644 --- a/src/types/actions/shortcut.ts +++ b/src/types/shortcuts/global-shortcut.ts @@ -3,7 +3,7 @@ * * This describes the entire JSON-encoded body of a request from Slack global actions. */ -export interface Shortcut { +export interface GlobalShortcut { type: 'shortcut'; callback_id: string; trigger_id: string; @@ -11,9 +11,6 @@ export interface Shortcut { id: string; name: string; }; - // remove this once we move to shortcut method - // needed because of line 54 in helpers.ts - channel?: undefined; team: { id: string; domain: string; diff --git a/src/types/shortcuts/index.ts b/src/types/shortcuts/index.ts new file mode 100644 index 000000000..80d2ac6fa --- /dev/null +++ b/src/types/shortcuts/index.ts @@ -0,0 +1,38 @@ +// export * from './message-action'; +export * from '../shortcuts/global-shortcut'; + +// import { MessageAction } from './message-action'; +import { GlobalShortcut } from '../shortcuts/global-shortcut'; +import { SayFn, RespondFn, AckFn } from '../utilities'; + +/** + * All known actions from Slack's Block Kit interactive components, message actions, dialogs, and legacy interactive + * messages. + * + */ +export type SlackShortcut = GlobalShortcut; + +/** + * Arguments which listeners and middleware receive to process an action from Slack's Block Kit interactive components, + * message actions, dialogs, or legacy interactive messages. + * + * The type parameter `Action` represents the entire JSON-encoded request body from Slack. The generic type + * `BlockAction` can be used to create a type for this parameter based on an element's action type. In + * this case `ElementAction` must extend `BasicElementAction`. + */ +export interface SlackShortcutMiddlewareArgs { + payload: Shortcut; + shortcut: this['payload']; + body: this['payload']; + say: SayFn; + respond: RespondFn; + // ack: ShortcutAckFn; + ack: AckFn; +} + +/** + * Type function which given an action `A` returns a corresponding type for the `ack()` function. The function is used + * to acknowledge the receipt (and possibly signal failure) of an action from a listener or middleware. + */ +// type ShortcutAckFn = + // AckFn; From cb091a11d8ea394d4826682aec014039bcd828c7 Mon Sep 17 00:00:00 2001 From: Steve Gill Date: Tue, 17 Mar 2020 12:24:24 -0700 Subject: [PATCH 4/5] updated global-shortcut payload --- src/middleware/builtin.ts | 2 +- src/types/shortcuts/global-shortcut.ts | 10 +++++----- src/types/shortcuts/index.ts | 20 ++------------------ 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/middleware/builtin.ts b/src/middleware/builtin.ts index c3980db9e..6a3eec55c 100644 --- a/src/middleware/builtin.ts +++ b/src/middleware/builtin.ts @@ -42,7 +42,7 @@ export const onlyActions: Middleware = ({ shortcut, next }) => { - // Filter out any non-actions + // Filter out any non-shortcuts if (shortcut === undefined) { return; } diff --git a/src/types/shortcuts/global-shortcut.ts b/src/types/shortcuts/global-shortcut.ts index 8be32c326..73437d109 100644 --- a/src/types/shortcuts/global-shortcut.ts +++ b/src/types/shortcuts/global-shortcut.ts @@ -1,7 +1,7 @@ /** - * A Slack global action wrapped in the standard metadata. + * A Slack global shortcut wrapped in the standard metadata. * - * This describes the entire JSON-encoded body of a request from Slack global actions. + * This describes the entire JSON-encoded body of a request from Slack global shortcuts. */ export interface GlobalShortcut { type: 'shortcut'; @@ -9,14 +9,14 @@ export interface GlobalShortcut { trigger_id: string; user: { id: string; - name: string; + username: string; + team_id: string; }; team: { id: string; domain: string; - // remove this once we move to shortcut - // needed because of line 540 in App.ts enterprise_id?: string; + enterprise_name?: string; }; token: string; action_ts: string; diff --git a/src/types/shortcuts/index.ts b/src/types/shortcuts/index.ts index 80d2ac6fa..2c31101a9 100644 --- a/src/types/shortcuts/index.ts +++ b/src/types/shortcuts/index.ts @@ -1,24 +1,16 @@ -// export * from './message-action'; export * from '../shortcuts/global-shortcut'; -// import { MessageAction } from './message-action'; import { GlobalShortcut } from '../shortcuts/global-shortcut'; import { SayFn, RespondFn, AckFn } from '../utilities'; /** - * All known actions from Slack's Block Kit interactive components, message actions, dialogs, and legacy interactive - * messages. + * All known shortcuts from Slack. * */ export type SlackShortcut = GlobalShortcut; /** - * Arguments which listeners and middleware receive to process an action from Slack's Block Kit interactive components, - * message actions, dialogs, or legacy interactive messages. - * - * The type parameter `Action` represents the entire JSON-encoded request body from Slack. The generic type - * `BlockAction` can be used to create a type for this parameter based on an element's action type. In - * this case `ElementAction` must extend `BasicElementAction`. + * Arguments which listeners and middleware receive to process an shorcut from Slack. */ export interface SlackShortcutMiddlewareArgs { payload: Shortcut; @@ -26,13 +18,5 @@ export interface SlackShortcutMiddlewareArgs; ack: AckFn; } - -/** - * Type function which given an action `A` returns a corresponding type for the `ack()` function. The function is used - * to acknowledge the receipt (and possibly signal failure) of an action from a listener or middleware. - */ -// type ShortcutAckFn = - // AckFn; From fd70de4cbe9fb1666160e69ecc86371bb388e140 Mon Sep 17 00:00:00 2001 From: Steve Gill Date: Tue, 17 Mar 2020 13:27:35 -0700 Subject: [PATCH 5/5] updated global shortcut payload --- src/types/shortcuts/global-shortcut.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types/shortcuts/global-shortcut.ts b/src/types/shortcuts/global-shortcut.ts index 73437d109..5bd95a6e4 100644 --- a/src/types/shortcuts/global-shortcut.ts +++ b/src/types/shortcuts/global-shortcut.ts @@ -11,6 +11,7 @@ export interface GlobalShortcut { id: string; username: string; team_id: string; + name: string; }; team: { id: string;