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

Add interactivity pointer #1526

Merged
Show file tree
Hide file tree
Changes from 4 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
54 changes: 53 additions & 1 deletion docs/_packages/web_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,59 @@ pattern for people that use _functional programming_.
---

### Opening modals
[Modals](https://api.slack.com/block-kit/surfaces/modals) can be created by calling the `views.open` method. The method requires you to pass a valid [view payload](https://api.slack.com/reference/block-kit/views) in addition to a `trigger_id`, which can be obtained when a user invokes your app using a slash command, clicking a button, or using [another interactive action](https://api.slack.com/reference/messaging/interactive-components).
hello-ashleyintech marked this conversation as resolved.
Show resolved Hide resolved
[Modals](https://api.slack.com/block-kit/surfaces/modals) can be created by calling the `views.open` method. The method requires you to pass a valid [view payload](https://api.slack.com/reference/block-kit/views).

#### Handling modals during Slack Function handling (beta)
hello-ashleyintech marked this conversation as resolved.
Show resolved Hide resolved
If you are trying to open or update a modal from a Slack Function [interactivity handler](https://api.slack.com/future/view-events), pass the `interactivity_pointer` you received from your event payload in your `views.open` method.
hello-ashleyintech marked this conversation as resolved.
Show resolved Hide resolved

```javascript
const { WebClient } = require('@slack/web-api');

// interactivity_pointers can be obtained when a user invokes your app.
// They are found inside the interactivity object.
// Find more information on interactivity: https://api.slack.com/future/view-events
hello-ashleyintech marked this conversation as resolved.
Show resolved Hide resolved
const pointer = 'VALID_INTERACTIVITY_POINTER';

(async () => {

// Open a modal.
// Find more arguments and details of the response: https://api.slack.com/methods/views.open
const result = await web.views.open({
interactivity_pointer: pointer,
view: {
type: 'modal',
callback_id: 'view_identifier',
title: {
type: 'plain_text',
text: 'Modal title'
},
submit: {
type: 'plain_text',
text: 'Submit'
},
blocks: [
{
type: 'input',
label: {
type: 'plain_text',
text: 'Input label'
},
element: {
type: 'plain_text_input',
action_id: 'value_indentifier'
}
}
]
}
});

// The result contains an identifier for the root view, view.id
console.log(`Successfully opened root view ${result.view.id}`);
})();
```

#### Handling modals using interactive components
If you are launching a modal from a slash command, clicking a button, or using [another interactive action](https://api.slack.com/reference/messaging/interactive-components), pass in the `trigger_id` you received from your event payload in your `views.open` method.

```javascript
const { WebClient } = require('@slack/web-api');
Expand Down
22 changes: 20 additions & 2 deletions packages/web-api/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2103,16 +2103,34 @@ export interface UsersProfileSetArguments extends WebAPICallOptions, TokenOverri
value?: string; // usable if `profile` is not passed
}

export interface ViewsOpenArguments extends WebAPICallOptions, TokenOverridable {
interface ViewsOpenTriggerRequired extends WebAPICallOptions, TokenOverridable {
trigger_id: string;
hello-ashleyintech marked this conversation as resolved.
Show resolved Hide resolved
interactivity_pointer?: never;
view: View;
}

export interface ViewsPushArguments extends WebAPICallOptions, TokenOverridable {
interface ViewsOpenInteractivityRequired extends WebAPICallOptions, TokenOverridable {
interactivity_pointer: string;
trigger_id?: never;
view: View;
}

export type ViewsOpenArguments = ViewsOpenTriggerRequired | ViewsOpenInteractivityRequired;

interface ViewsPushTriggerRequired extends WebAPICallOptions, TokenOverridable {
trigger_id: string;
interactivity_pointer?: never;
view: View;
}

interface ViewsPushInteractivityRequired extends WebAPICallOptions, TokenOverridable {
interactivity_pointer: string;
trigger_id?: never;
view: View;
}

export type ViewsPushArguments = ViewsPushTriggerRequired | ViewsPushInteractivityRequired;
hello-ashleyintech marked this conversation as resolved.
Show resolved Hide resolved

export interface ViewsPublishArguments extends WebAPICallOptions, TokenOverridable {
user_id: string;
view: View;
Expand Down