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

adding type as a valid constraint for app actions #326

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/App.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,17 @@ describe('App', () => {
respond: noop,
ack: noop,
},
{ // IncomingEventType.Action (app.action)
body: {
type: 'message_action',
callback_id: 'another_message_action_callback_id',
channel: {},
user: {},
team: {},
},
respond: noop,
ack: noop,
},
{ // IncomingEventType.Action (app.action)
body: {
type: 'interactive_message',
Expand Down Expand Up @@ -468,6 +479,8 @@ describe('App', () => {
app.use((_args) => { ackFn(); });
app.action('block_action_id', ({ }) => { actionFn(); });
app.action({ callback_id: 'message_action_callback_id' }, ({ }) => { actionFn(); });
app.action({ type: 'message_action', callback_id: 'another_message_action_callback_id' }, ({ }) => { actionFn(); });
app.action({ type: 'message_action', callback_id: 'does_not_exist' }, ({ }) => { actionFn(); });
app.action({ callback_id: 'interactive_message_callback_id' }, ({ }) => { actionFn(); });
app.action({ callback_id: 'dialog_submission_callback_id' }, ({ }) => { actionFn(); });
app.view('view_callback_id', ({ }) => { viewFn(); });
Expand All @@ -480,7 +493,7 @@ describe('App', () => {
await delay();

// Assert
assert.equal(actionFn.callCount, 4);
assert.equal(actionFn.callCount, 5);
assert.equal(viewFn.callCount, 2);
assert.equal(optionsFn.callCount, 2);
assert.equal(ackFn.callCount, dummyReceiverEvents.length);
Expand Down
3 changes: 2 additions & 1 deletion src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export interface AuthorizeResult {
}

export interface ActionConstraints {
type?: string,
block_id?: string | RegExp;
action_id?: string | RegExp;
callback_id?: string | RegExp;
Expand Down Expand Up @@ -282,7 +283,7 @@ export default class App {

// Fail early if the constraints contain invalid keys
const unknownConstraintKeys = Object.keys(constraints)
.filter(k => (k !== 'action_id' && k !== 'block_id' && k !== 'callback_id'));
.filter(k => (k !== 'action_id' && k !== 'block_id' && k !== 'callback_id' && k !== 'type'));
if (unknownConstraintKeys.length > 0) {
this.logger.error(
`Action listener cannot be attached using unknown constraint keys: ${unknownConstraintKeys.join(', ')}`,
Expand Down
2 changes: 1 addition & 1 deletion src/types/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { MessageAction } from './message-action';
import { SayFn, SayArguments, RespondFn, AckFn } from '../utilities';

/**
* All known actions from Slack's Blot Kit interactive components, message actions, dialogs, and legacy interactive
* All known actions from Slack's Block Kit interactive components, message actions, dialogs, and legacy interactive
* messages.
*
* TODO: BlockAction's default generic parameter (ElementAction) might be too specific to allow for this type to be used
Expand Down