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
Add in blockAction handler to SlackFunction #1657
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,6 +156,9 @@ export class SlackFunction { | |
/** | ||
* Attach a block_actions interactivity handler to your SlackFunction | ||
* | ||
* NOTE: blockActions() in this file is a direct copy of this function | ||
* and any changes made here should also be made to that function. | ||
* | ||
* ``` | ||
* Example: | ||
* const actionHandler = async () => {}; | ||
|
@@ -202,9 +205,61 @@ export class SlackFunction { | |
} | ||
|
||
/** | ||
* Attach a block_suggestion interactivity handler to your SlackFunction | ||
* Attach a block_actions interactivity handler to your SlackFunction. | ||
* This function is added as an alias for the action() function to create | ||
* consistency with having a blockSuggestion() function. | ||
* | ||
* NOTE: This function is a direct copy of the action() function and | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any way to use the .action() function within blockAction instead of copying the code? If we can do this, it would probably reduce the likelihood of accidental drift between the two interfaces, since we expect them to be the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. absolutely! I'll try what you suggested above and have this updated by later today! 🙌 |
||
* any changes made there should also be made to this function. | ||
* | ||
* ``` | ||
* Example: | ||
* const actionHandler = async () => {}; | ||
* const actionHandler1 = async () => {}; | ||
* myFunc.blockAction("id", actionHandler).blockAction("id1", actionHandler1); | ||
* ``` | ||
* | ||
* @param actionIdOrConstraints Provide an action_id string | ||
* corresponding to the value supplied in your blocks or a | ||
* constraint object of type ActionConstraints<SlackAction> | ||
* | ||
* ``` | ||
* Example: | ||
* myFunc.blockAction({ type: "action_submission" }); | ||
* myFunc.blockAction({ action_id: "id" }, actionHandler); | ||
* ``` | ||
* @param handler Provide a handler function | ||
* @returns SlackFunction instance | ||
*/ | ||
public blockAction< | ||
Action extends SlackAction = SlackAction, | ||
Constraints extends ActionConstraints<Action> = ActionConstraints<Action>, | ||
>( | ||
actionIdOrConstraints: string | RegExp | Constraints, | ||
handler: Middleware<SlackActionMiddlewareArgs>, | ||
): this { | ||
// normalize constraints | ||
const constraints: ActionConstraints = ( | ||
typeof actionIdOrConstraints === 'string' || | ||
util.types.isRegExp(actionIdOrConstraints) | ||
) ? | ||
{ action_id: actionIdOrConstraints } : | ||
actionIdOrConstraints; | ||
|
||
// declare our valid constraints keys | ||
const validConstraintsKeys: ActionConstraintsKeys = ['action_id', 'block_id', 'callback_id', 'type']; | ||
// cast to string array for convenience | ||
const validConstraintsKeysAsStrings = validConstraintsKeys as string[]; | ||
|
||
errorIfInvalidConstraintKeys(constraints, validConstraintsKeysAsStrings, handler); | ||
|
||
this.interactivityHandlers.push({ constraints, handler }); | ||
return this; | ||
} | ||
|
||
/** | ||
* Attach a block_suggestion interactivity handler to your SlackFunction | ||
* | ||
* @param handler Provide a handler function | ||
* @returns SlackFunction instance | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on locating this test and the one below it within `describe('runInteractivityHandlers', ....) on ln241?