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

Shortcut v2 #428

Merged
merged 65 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
9b75fd0
Fix #382 Missing invite_requested event type
seratch Jan 30, 2020
6ea7a5a
Fix #168 Give listeners and middleware access to the logger
seratch Dec 24, 2019
628c7cf
Fix #354 Add `client` to the list of args send through to listeners
seratch Dec 24, 2019
54c15ce
Add instance pool for #359
seratch Jan 30, 2020
3d4440b
Add logger and client to Middleware args
seratch Jan 31, 2020
8c63cc7
Make invite_type in InviteRequestedEvent more specific
seratch Feb 3, 2020
e425b7a
Merge pull request #359 from seratch/issue-354
seratch Feb 4, 2020
d97d873
Merge branch 'master' into issue-382
seratch Feb 4, 2020
c963e1d
Merge pull request #387 from seratch/issue-382
seratch Feb 4, 2020
774c72a
fix #355
artgillespie Feb 4, 2020
8bfcc44
Merge remote-tracking branch 'upstream/master' into fix-#355
artgillespie Feb 4, 2020
074a0f0
fix tests after merging latest
artgillespie Feb 4, 2020
fec7647
v1.6.0
stevengill Feb 5, 2020
95d35f6
Merge pull request #396 from stevengill/master
stevengill Feb 5, 2020
7a04c34
Merge branch 'master' into fix-#355
Feb 5, 2020
a7c4db5
Merge pull request #394 from trainify-io/fix-#355
seratch Feb 7, 2020
d3ec601
Fix an error on README
seratch Feb 8, 2020
db940c5
Merge pull request #398 from seratch/readme-fix
seratch Feb 13, 2020
d45f209
Fix #405 by providing a better way to configure logger
seratch Feb 15, 2020
e94ae92
Add checkboxes action payload
seratch Feb 17, 2020
4c10928
Fix #348 app.view() is not described in the README
seratch Feb 17, 2020
9c63395
Specifies view submission response action types (#404)
aoberoi Feb 17, 2020
7989abb
Merge branch 'master' into issue-348
seratch Feb 17, 2020
a7aa414
Merge branch 'master' into checkboxes-action
seratch Feb 17, 2020
30ecca7
Merge pull request #410 from seratch/issue-348
stevengill Feb 18, 2020
a2f546d
Merge pull request #408 from seratch/checkboxes-action
stevengill Feb 18, 2020
4f3f3ea
Merge branch 'master' into issue-405
seratch Feb 19, 2020
217fe72
Merge pull request #406 from seratch/issue-405
seratch Feb 19, 2020
4592b20
Changing payload to body
greggTime Mar 4, 2020
2133625
Changing payload to body
greggTime Mar 4, 2020
e21b237
Merge pull request #417 from slackapi/gtime_sample_code_update
seratch Mar 4, 2020
9966c6a
v1.7.0
stevengill Mar 5, 2020
e2d2b88
Merge pull request #419 from stevengill/master
stevengill Mar 5, 2020
7d538b0
Fix #422 invalid fields in MultiUsersSelectAction
seratch Mar 8, 2020
0ca1d5c
Merge pull request #423 from seratch/issue-422
stevengill Mar 9, 2020
b83536d
Change Bolt to Bolt to JavaScript
Mar 11, 2020
0a59c9a
Merge branch 'master' into change-bolt-to-boltjs
seratch Mar 12, 2020
0bfd4f8
Merge pull request #425 from shaydewael/change-bolt-to-boltjs
Mar 17, 2020
0c94e88
Add shortcut documentation
Mar 17, 2020
13d68c0
Add readme
Mar 17, 2020
dbab80a
Add disclaimer
Mar 17, 2020
26fbd6d
Added support for global actions
stevengill Jan 9, 2020
02a7784
updated for new shortcut payload
stevengill Feb 14, 2020
78355bb
added new shortcut method
stevengill Mar 16, 2020
cb091a1
updated global-shortcut payload
stevengill Mar 17, 2020
fd70de4
updated global shortcut payload
stevengill Mar 17, 2020
7cf779e
Add Japanese shortcuts docs
seratch Mar 17, 2020
6b02dd9
Merge pull request #5 from slackapi/add-shortcuts-documentation-ja
Mar 17, 2020
201468c
kaz edit
Mar 17, 2020
edf7650
Merge branch 'add-shortcuts-documentation' of github.com:slackapi/bol…
Mar 17, 2020
862efb7
Merge pull request #430 from shaydewael/add-shortcuts-documentation
stevengill Mar 18, 2020
93ec1da
Merge pull request #427 from stevengill/shortcut
stevengill Mar 18, 2020
03635ef
updated shortcut payload
stevengill Mar 18, 2020
517fca4
v1.8.0
stevengill Mar 18, 2020
32dd206
Merge pull request #431 from stevengill/rel-v1.8.0
stevengill Mar 18, 2020
5cb9559
Fix a typo in shortcut Japanese document
seratch Mar 18, 2020
94244c0
Merge pull request #432 from seratch/fix-ja-doc-error
seratch Mar 18, 2020
6df7d37
Update listening_responding_shortcuts.md
Mar 18, 2020
4b7a994
moved message actions to shorcut method
stevengill Mar 17, 2020
aa6e496
Merge branch '@slack/bolt@next' into shortcutV2
stevengill Mar 23, 2020
ce8dab4
fixed related issues + linting/testing
stevengill Mar 23, 2020
535130c
updated docs
stevengill Mar 23, 2020
2cb010f
added tests for shortcuts
stevengill Mar 23, 2020
779b979
Apply suggestions from code review
stevengill Mar 24, 2020
62975af
updated based on feedback
stevengill Mar 24, 2020
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
2 changes: 2 additions & 0 deletions .github/maintainers_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ To build the docs locally, you can run `bundle exec jekyll serve`.

1. Create the commit for the release:
* Bump the version number in adherence to [Semantic Versioning](http://semver.org/) in `package.json`.
* Update any dependency versions
stevengill marked this conversation as resolved.
Show resolved Hide resolved
* Confirm tests pass by running `npm test`
* Commit with a message including the new version number. For example `v1.5.0`.
* Tag the commit with the version number. For example `@slack/[email protected]`.

Expand Down
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Slack ⚡️ Bolt
# Slack ⚡️ Bolt for JavaScript

[![Build Status](https://travis-ci.org/slackapi/bolt.svg?branch=master)](https://travis-ci.org/slackapi/bolt)
[![codecov](https://codecov.io/gh/slackapi/bolt/branch/master/graph/badge.svg)](https://codecov.io/gh/slackapi/bolt)

A framework to build Slack apps, _fast_.
A JavaScript framework to build Slack apps _in a flash_.

## Initialization

Expand Down Expand Up @@ -36,14 +36,22 @@ 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 shortcut, or legacy action
stevengill marked this conversation as resolved.
Show resolved Hide resolved
app.action({ callback_id: callbackId }, fn);

// Listen for a global shortcut
app.shortcut(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);
stevengill marked this conversation as resolved.
Show resolved Hide resolved
```

There's a special method that's provided as a convenience to handle Events API events with the type `message`. Also, you
Expand Down Expand Up @@ -139,7 +147,7 @@ soon as possible.

Depending on the type of incoming event a listener is meant for, `ack()` should be called with a parameter:

* Block actions and message actions: Call `ack()` with no parameters.
* Block actions, global shortcuts, and message shortcuts: Call `ack()` with no parameters.

* Dialog submissions: Call `ack()` with no parameters when the inputs are all valid, or an object describing the
validation errors if any inputs are not valid.
Expand All @@ -150,7 +158,7 @@ Depending on the type of incoming event a listener is meant for, `ack()` should
to to update the message with a simple message, or an `object` to replace it with a complex message. Replacing the
message to remove the interactive elements is a best practice for any action that should only be performed once.

If an app does not call `ack()` within the time limit, Bolt will generate an error. See [handling
If an app does not call `ack()` within the time limit, Bolt for JavaScript will generate an error. See [handling
stevengill marked this conversation as resolved.
Show resolved Hide resolved
errors](#handling-errors) for more details.

The following is an example of acknowledging a dialog submission:
Expand Down Expand Up @@ -296,7 +304,7 @@ app.message(noBotMessages, ({ message }) => console.log(
));
```

Message subtype matching is common, so Bolt ships with a builtin listener middleware that filters all messages that
Message subtype matching is common, so Bolt for JavaScript ships with a builtin listener middleware that filters all messages that
match a given subtype. The following is an example of the opposite of the one above - the listener only sees messages
that _are_ `bot_message`s.

Expand Down
2 changes: 1 addition & 1 deletion docs/_advanced/conversation_store.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ order: 3
---

<div class="section-content">
Bolt includes support for a store, which sets and retrieves state related to a conversation. Conversation stores have two methods:
Bolt for JavaScript includes support for a store, which sets and retrieves state related to a conversation. Conversation stores have two methods:
* `set()` modifies conversation state. `set()` requires a `conversationId` of type string, `value` of any type, and an optional `expiresAt` of type number. `set()` returns a `Promise`.
* `get()` fetches conversation state from the store. `get()` requires a `conversationId` of type string and returns a Promise with the conversation’s state.

Expand Down
2 changes: 1 addition & 1 deletion docs/_advanced/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ order: 7
---

<div class="section-content">
By default, Bolt will log information from your app to the console. You can customize how much logging occurs by passing a `logLevel` in the constructor. The available log levels in order of most to least logs are `DEBUG`, `INFO`, `WARN`, and `ERROR`.
By default, Bolt for JavaScript will log information from your app to the console. You can customize how much logging occurs by passing a `logLevel` in the constructor. The available log levels in order of most to least logs are `DEBUG`, `INFO`, `WARN`, and `ERROR`.
</div>

```javascript
Expand Down
6 changes: 3 additions & 3 deletions docs/_advanced/receiver.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ order: 8
---

<div class="section-content">
A receiver is responsible for handling and parsing any incoming events from Slack, then sending the event to the Bolt app so it can add context and pass it to your app’s listeners. Receivers must conform to the Receiver interface:
A receiver is responsible for handling and parsing any incoming events from Slack, then emitting the event so the Bolt for JavaScript app can add context and pass it to your app’s listeners. Receivers must conform to the Receiver interface:
stevengill marked this conversation as resolved.
Show resolved Hide resolved
stevengill marked this conversation as resolved.
Show resolved Hide resolved

| Method | Parameters | Return type |
|--------------|----------------------------------|-------------|
| `init()` | `app: App` | `unknown` |
| `start()` | None | `Promise` |
| `stop()` | None | `Promise` |

`init()` is called after it's been passed to a created Bolt app, it's purpose is to give you an instance of bolt so that you can call:
`init()` is called after it's been passed to a created Bolt for JavaScript app, it's purpose is to give you an instance of bolt so that you can call:
stevengill marked this conversation as resolved.
Show resolved Hide resolved
* `await app.processEvent(event)` whenever your app receives an event from Slack. It will reject if there is an unhandled error.
* `await app.handleError` whenever you need to route errors to the global error handler. This gives the developer a chance to handle it.
stevengill marked this conversation as resolved.
Show resolved Hide resolved

To use a custom receiver, you can pass it into the constructor when initializing your Bolt app. Here is what a basic custom receiver might look like.
To use a custom receiver, you can pass it into the constructor when initializing your Bolt for JavaScript app. Here is what a basic custom receiver might look like.

For a more in-depth look at a receiver, [read the source code for the built-in Express receiver](https://github.com/slackapi/bolt/blob/master/src/ExpressReceiver.ts)
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/_basic/acknowledging_requests.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Acknowledging events
title: Acknowledging incoming events
stevengill marked this conversation as resolved.
Show resolved Hide resolved
lang: en
slug: acknowledge
order: 7
Expand Down
65 changes: 65 additions & 0 deletions docs/_basic/ja_ listening_responding_shortcuts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
stevengill marked this conversation as resolved.
Show resolved Hide resolved
title: グローバルショートカットのリスニング
lang: ja-jp
slug: shortcuts
order: 8
---

<div class="section-content">
[グローバルショートカット](https://api.slack.com/interactivity/shortcuts/using#global_shortcuts)は、テキスト入力エリアや検索バーから起動できる Slack クライアント内の UI エレメントです。`shortcut()` メソッドを使って、グローバルショートカットのイベントをリスニングすることができます。このメソッドには `callback_id` を文字列または正規表現のデータ型で設定します。

グローバルショートカットのイベントは Slack へイベントを受信したことを知らせるために `ack()` メソッドで確認する必要があります。

グローバルショートカットのペイロードは、ユーザーの実行アクションの確認のために[モーダルを開く](#creating-modals)などの用途に使用できる `trigger_id` を含んでいます。グローバルショートカットのペイロードは **チャンネル ID は含んでいない** ことに注意してください。もしあなたのアプリがチャンネル ID を知る必要があれば、モーダル内で [`conversations_select`](https://api.slack.com/reference/block-kit/block-elements#conversation_select) エレメントを使用できます。

⚠️ [メッセージショートカット](https://api.slack.com/interactivity/shortcuts/using#message_shortcuts)は引き続き[`action()` メソッド](#action-listening)を使用するので注意してください。**Bolt の次のメジャーバージョンからはグローバルショートカットもメッセージショートカットも両方とも `shortcut()` メソッドを使用します。**
</div>

```javascript
// open_modal というグローバルショートカットはシンプルなモーダルを開く
app.shortcut('open_modal', async ({ payload, ack, context }) => {
// グローバルショートカットリクエストの確認
ack();
try {
// 組み込みの WebClient を使って views.open API メソッドを呼び出す
const result = await app.client.views.open({
// `context` オブジェクトに保持されたトークンを使用
token: context.botToken,
trigger_id: payload.trigger_id,
view: {
"type": "modal",
"title": {
"type": "plain_text",
"text": "My App"
},
"close": {
"type": "plain_text",
"text": "Close"
},
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "About the simplest modal you could conceive of :smile:\n\nMaybe <https://api.slack.com/reference/block-kit/interactive-components|*make the modal interactive*> or <https://api.slack.com/surfaces/modals/using#modifying|*learn more advanced modal use cases*>."
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "Psssst this modal was designed using <https://api.slack.com/tools/block-kit-builder|*Block Kit Builder*>"
}
]
}
]
}
});
console.log(result);
}
catch (error) {
console.error(error);
}
});
```
2 changes: 1 addition & 1 deletion docs/_basic/ja_listening_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ order: 5
---

<div class="section-content">
アプリでは、ボタンのクリック、メニューの選択、メッセージアクションなどのユーザーアクションを、 `action` メソッドを使用してリスニングすることができます。
アプリでは、ボタンのクリック、メニューの選択、メッセージショートカットなどのユーザーアクションを、 `action` メソッドを使用してリスニングすることができます。

アクションは文字列型の `action_id` または RegExp オブジェクトでフィルタリングできます。 `action_id` は、Slack プラットフォーム上のインタラクティブコンポーネントの一意の識別子として機能します。

Expand Down
2 changes: 1 addition & 1 deletion docs/_basic/ja_listening_modals.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: モーダルビューでの送信のリスニング
lang: ja-jp
slug: view_submissions
order: 11
order: 12
---

<div class="section-content">
Expand Down
2 changes: 1 addition & 1 deletion docs/_basic/ja_listening_responding_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: コマンドのリスニングと応答
lang: ja-jp
slug: commands
order: 8
order: 9
---

<div class="section-content">
Expand Down
2 changes: 1 addition & 1 deletion docs/_basic/ja_listening_responding_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: オプションのリスニングと応答
lang: ja-jp
slug: options
order: 12
order: 13
---

<div class="section-content">
Expand Down
4 changes: 2 additions & 2 deletions docs/_basic/ja_opening_modals.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: モーダルビューのオープン
title: views.open を使ったモーダルビューのオープン
lang: ja-jp
slug: creating-modals
order: 9
order: 10
---

<div class="section-content">
Expand Down
2 changes: 1 addition & 1 deletion docs/_basic/ja_updating_pushing_modals.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: モーダルビューの更新と多重表示
lang: ja-jp
slug: updating-pushing-views
order: 10
order: 11
---

<div class="section-content">
Expand Down
2 changes: 1 addition & 1 deletion docs/_basic/listening_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ order: 5
---

<div class="section-content">
Your app can listen to user actions like button clicks, menu selects, and message actions using the `action` method.
stevengill marked this conversation as resolved.
Show resolved Hide resolved
Your app can listen to user actions like button clicks, menu selects, and message shortcuts using the `action` method.
stevengill marked this conversation as resolved.
Show resolved Hide resolved
aoberoi marked this conversation as resolved.
Show resolved Hide resolved

Actions can be filtered on an `action_id` of type string or RegExp object. `action_id`s act as unique identifiers for interactive components on the Slack platform.

Expand Down
2 changes: 1 addition & 1 deletion docs/_basic/listening_modals.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Listening for view submissions
lang: en
slug: view_submissions
order: 11
order: 12
---

<div class="section-content">
Expand Down
2 changes: 1 addition & 1 deletion docs/_basic/listening_responding_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Listening and responding to commands
lang: en
slug: commands
order: 8
order: 9
---

<div class="section-content">
Expand Down
2 changes: 1 addition & 1 deletion docs/_basic/listening_responding_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Listening and responding to options
lang: en
slug: options
order: 12
order: 13
---

<div class="section-content">
Expand Down
67 changes: 67 additions & 0 deletions docs/_basic/listening_responding_shortcuts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: Listening and responding to global shortcuts
lang: en
slug: shortcuts
order: 8
---

<div class="section-content">
[Global shortcuts](https://api.slack.com/interactivity/shortcuts/using#global_shortcuts) are invokable UI elements within Slack clients, available in the composer and search menus. Your app can use the `shortcut()` method to listen to incoming global shortcut events. The method requires a `callback_id` parameter of type `string` or `RegExp`.

Global shortcuts must be acknowledged with `ack()` to inform Slack that your app has received the event.

Global shortcut payloads include a `trigger_id` which an app can use to [open a modal](#creating-modals) that confirms the action the user is taking. Note that global shortcut payloads do **not** include a channel ID. If your app needs access to a channel ID, you may use a [`conversations_select`](https://api.slack.com/reference/block-kit/block-elements#conversation_select) element within a modal.
stevengill marked this conversation as resolved.
Show resolved Hide resolved

⚠️ Note that [message shortcuts](https://api.slack.com/interactivity/shortcuts/using#message_shortcuts) still require apps to use the [`action()` method](#action-listening). **In the next major version of Bolt, both global and message shortcuts will use the `shortcut()` method.**
stevengill marked this conversation as resolved.
Show resolved Hide resolved
stevengill marked this conversation as resolved.
Show resolved Hide resolved
</div>

```javascript
// The open_modal shortcut opens a plain old modal
app.shortcut('open_modal', async ({ payload, ack, context }) => {
stevengill marked this conversation as resolved.
Show resolved Hide resolved
// Acknowledge global shortcut request
ack();

try {
// Call the views.open method using the built-in WebClient
const result = await app.client.views.open({
stevengill marked this conversation as resolved.
Show resolved Hide resolved
// The token you used to initialize your app is stored in the `context` object
token: context.botToken,
trigger_id: payload.trigger_id,
stevengill marked this conversation as resolved.
Show resolved Hide resolved
view: {
"type": "modal",
stevengill marked this conversation as resolved.
Show resolved Hide resolved
"title": {
"type": "plain_text",
"text": "My App"
},
"close": {
"type": "plain_text",
"text": "Close"
},
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "About the simplest modal you could conceive of :smile:\n\nMaybe <https://api.slack.com/reference/block-kit/interactive-components|*make the modal interactive*> or <https://api.slack.com/surfaces/modals/using#modifying|*learn more advanced modal use cases*>."
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "Psssst this modal was designed using <https://api.slack.com/tools/block-kit-builder|*Block Kit Builder*>"
}
]
}
]
}
});

console.log(result);
}
catch (error) {
console.error(error);
}
});
```
stevengill marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions docs/_basic/opening_modals.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Opening modals
title: Opening modals using views.open
stevengill marked this conversation as resolved.
Show resolved Hide resolved
lang: en
slug: creating-modals
order: 9
order: 10
---

<div class="section-content">
Expand Down
2 changes: 1 addition & 1 deletion docs/_basic/updating_pushing_modals.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Updating and pushing views
lang: en
slug: updating-pushing-views
order: 10
order: 11
---

<div class="section-content">
Expand Down
Loading