Skip to content

Commit

Permalink
Merge pull request #1 from slackapi/master
Browse files Browse the repository at this point in the history
Bring my fork up to date with upstream
  • Loading branch information
marks authored Dec 22, 2019
2 parents 2bfc688 + 449b880 commit e8bb742
Show file tree
Hide file tree
Showing 29 changed files with 484 additions and 146 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ called with arguments that make it easy to build a rich app.
types of data are only available outside the event payload itself, such as `api_app_id`, `authed_users`, etc. This
argument should rarely be needed, but for completeness it is provided here.

The arguments are grouped into properties of one object, so that its easier to pick just the ones your listener needs
The arguments are grouped into properties of one object, so that it's easier to pick just the ones your listener needs
(using
[object destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Unpacking_fields_from_objects_passed_as_function_parameter)).
Here is an example where the app sends a simple response, so there's no need for most of these arguments:
Expand Down Expand Up @@ -173,7 +173,7 @@ app.action({ callbackId: 'my_dialog_callback' }, async ({ action, ack }) => {

## Handling errors

If an error occurs in a listener function, its strongly recommended to handle it directly. There are a few cases where
If an error occurs in a listener function, it's strongly recommended to handle it directly. There are a few cases where
those errors may occur after your listener function has returned (such as when calling `say()` or `respond()`, or
forgetting to call `ack()`). In these cases, your app will be notified about the error in an error handler function.
Your app should register an error handler using the `App#error(fn)` method.
Expand Down Expand Up @@ -239,7 +239,7 @@ app.message('whoami', ({ say, context }) => { say(`User Details: ${JSON.stringif
})();

// Authentication middleware - Calls Acme identity provider to associate the incoming event with the user who sent it
// Its a function just like listeners, but it also uses the next argument
// It's a function just like listeners, but it also uses the next argument
function authWithAcme({ payload, context, say, next }) {
const slackUserId = payload.user;

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 @@ -12,7 +12,7 @@ order: 11

<code>input</code> ブロックの値は <code>state</code> オブジェクトを参照することで取得できます。<code>state</code> 内には <code>values</code> というオブジェクトがあり、これは <code>block_id</code> と一意な <code>action_id</code> に紐づける形で入力値を保持しています。

より詳細な情報は <a href="https://api.slack.com/block-kit/surfaces/modals#handling_submissions">API ドキュメント</a>を参照してください。
より詳細な情報は <a href="https://api.slack.com/surfaces/modals/using#interactions">API ドキュメント</a>を参照してください。
</div>

```javascript
Expand Down
6 changes: 3 additions & 3 deletions docs/_basic/ja_opening_modals.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ order: 9

<code>trigger_id</code> はコマンド、ボタンの押下、メニューの選択などによって Request URL に送信されたペイロードの項目として入手することができます。

モーダルビューの作成についてのより詳細な情報は <a href="https://api.slack.com/block-kit/surfaces/modals#composing_modal">API ドキュメント</a>を参照してください。
モーダルビューの作成についてのより詳細な情報は <a href="https://api.slack.com/surfaces/modals/using#composing_views">API ドキュメント</a>を参照してください。
</div>

```javascript
Expand All @@ -23,11 +23,11 @@ app.command('/ticket', ({ ack, payload, context }) => {
try {
const result = app.client.views.open({
token: context.botToken,
type: 'modal',
// 適切な trigger_id を受け取ってから 3 秒以内に渡す
trigger_id: payload.trigger_id,
// view の値をペイロードに含む
view: {
type: 'modal',
// callback_id が view を特定するための識別子
callback_id: 'view_1',
title: {
Expand Down Expand Up @@ -76,4 +76,4 @@ app.command('/ticket', ({ ack, payload, context }) => {
console.error(error);
}
});
```
```
3 changes: 2 additions & 1 deletion docs/_basic/ja_updating_pushing_modals.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ order: 10
<strong><code>views.push</code></strong><br>
ビューのスタックに新しいビューを積み重ねるには、組み込みの API クライアントを使って <code>views.push</code> を呼び出します。この API 呼び出しには、適切な <code>trigger_id</code> と新しく生成する <a href="https://api.slack.com/reference/block-kit/views">ビュー部分のペイロード</a>を渡します。`views.push` の引数は <a href="#creating-modals">ビューをオープンするとき</a>と同様です。最初のモーダルビューをオープンした後、その上にさらに二つまで追加のビューをスタックに積み重ねることができます。

より詳細な情報は <a href="https://api.slack.com/block-kit/surfaces/modals#updating_views">API ドキュメント</a>を参照してください。
より詳細な情報は <a href="https://slack.dev/bolt/concepts#view_submissions">API ドキュメント</a>を参照してください。
</div>

```javascript
Expand All @@ -31,6 +31,7 @@ app.action('button_abc', ({ ack, body, context }) => {
view_id: body.view.id,
// 更新された view の値をペイロードに含む
view: {
type: 'modal',
// callback_id が view を特定するための識別子
callback_id: 'view_1',
title: {
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 @@ -12,7 +12,7 @@ If a <a href="https://api.slack.com/reference/block-kit/views">view payload</a>

You can access the value of the <code>input</code> blocks by accessing the <code>state</code> object. <code>state</code> contains a <code>values</code> object that uses the <code>block_id</code> and unique <code>action_id</code> to store the input values.

Read more about view submissions in our <a href="https://api.slack.com/block-kit/surfaces/modals#handling_submissions">API documentation</a>.
Read more about view submissions in our <a href="https://api.slack.com/surfaces/modals/using#interactions">API documentation</a>.
</div>

```javascript
Expand Down
6 changes: 3 additions & 3 deletions docs/_basic/opening_modals.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ order: 9

Your app receives <code>trigger_id</code>s in payloads sent to your Request URL triggered user invocation like a slash command, button press, or interaction with a select menu.

Read more about modal composition in the <a href="https://api.slack.com/block-kit/surfaces/modals#composing_modal">API documentation</a>.
Read more about modal composition in the <a href="https://api.slack.com/surfaces/modals/using#composing_views">API documentation</a>.
</div>

```javascript
Expand All @@ -22,11 +22,11 @@ app.command('/ticket', ({ ack, payload, context }) => {
try {
const result = app.client.views.open({
token: context.botToken,
type: 'modal',
// Pass a valid trigger_id within 3 seconds of receiving it
trigger_id: payload.trigger_id,
// View payload
view: {
type: 'modal',
// View identifier
callback_id: 'view_1',
title: {
Expand Down Expand Up @@ -75,4 +75,4 @@ app.command('/ticket', ({ ack, payload, context }) => {
console.error(error);
}
});
```
```
3 changes: 2 additions & 1 deletion docs/_basic/updating_pushing_modals.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To update a view, you can use the built-in client to call <code>views.update</co
<strong><code>views.push</code></strong><br>
To push a new view onto the view stack, you can use the built-in client to call <code>views.push</code> with a valid <code>trigger_id</code> a new <a href="https://api.slack.com/reference/block-kit/views">view payload</a>. The arguments for `views.push` is the same as <a href="#creating-modals">opening modals</a>. After you open a modal, you may only push two additional views onto the view stack.

Learn more about updating and pushing views in our <a href="https://api.slack.com/block-kit/surfaces/modals#updating_views">API documentation</a>.
Learn more about updating and pushing views in our <a href="https://api.slack.com/surfaces/modals/using#modifying">API documentation</a>.
</div>

```javascript
Expand All @@ -30,6 +30,7 @@ app.action('button_abc', ({ ack, body, context }) => {
view_id: body.view.id,
// View payload with updated blocks
view: {
type: 'modal',
// View identifier
callback_id: 'view_1',
title: {
Expand Down
4 changes: 2 additions & 2 deletions docs/_tutorials/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ app.message('hello', ({ message, say }) => {
say({
blocks: [
{
"type": "section",
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Hey there <@${message.user}>!`
Expand All @@ -231,7 +231,7 @@ app.message('hello', ({ message, say }) => {
},
"action_id": "button_click"
}
}
}
]
});
});
Expand Down
4 changes: 2 additions & 2 deletions docs/_tutorials/ja_getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ app.message('hello', ({ message, say }) => {
say({
blocks: [
{
"type": "section",
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Hey there <@${message.user}>!`
Expand All @@ -234,7 +234,7 @@ app.message('hello', ({ message, say }) => {
},
"action_id": "button_click"
}
}
}
]
});
});
Expand Down
Binary file modified docs/assets/request-url-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions integration-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# node / npm stuff
/node_modules
/package-lock.json
53 changes: 53 additions & 0 deletions integration-tests/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Integration Type Checker",
"program": "${workspaceFolder}/node_modules/dtslint/bin/index.js",
"args": [
"types"
],
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": [
"<node_internals>/**"
],
"cwd": "${workspaceFolder}"
},
{
"type": "node",
"request": "launch",
"name": "npm test",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script", "test"
],
"port": 9229

},
]
}

/*
[
{
"type": "node",
"request": "launch",
"name": "Integration Type Checker",
"program": "${workspaceFolder}/node_modules/dtslint/bin/index.js",
"args": [
"types"
],
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": [
"<node_internals>/**"
],
"cwd": "${workspaceFolder}"
},
]
*/
22 changes: 22 additions & 0 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Integration tests

This directory contains a minimal project used as an environment in which to run integration tests.

It's important to isolate this test project from the overall project where the package is built in order to eliminate
assumptions. Specifically, the `package.json` and other configuration files in this directory are meant to include
the minimum requirements and nothing more. Here are a few ways this is set up:

* The `@types/node` dependency is set to a version that corresponds to the lowest supported node version. This enforces
that the distribution should work in projects who have chosen that particular version, since its the most likely to
not have types that we accidentally depend on but shouldn't.

* The `typescript` development dependency is set to the most modern version of typescript. It's not important to use the
oldest supported version because the `dtslint` tool will run the typechecker result integration tests on each
supported version of TypeScript. It reads the oldest supported version from `types/index.d.ts`.

* The `tsconfig.json` file is specifically set to the most strict settings as well as the most minimal requirements.
This is specifically chosen to verify that the requirements expressed in the documentation are sufficient and
represent the least amount of configuration needed to get the package working.

* In `package.json`, the `"private"` key must remain set to `true`. This enforces that this project doesn't get
accidentally published.
19 changes: 19 additions & 0 deletions integration-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@slack/bolt-integration-tests",
"private": true,
"description": "Integration tests for Bolt",
"author": "Slack Technologies, Inc.",
"license": "MIT",
"scripts": {
"test": "npm run test:typechecker",
"test:typechecker": "dtslint types"
},
"dependencies": {
"@slack/bolt": "file:..",
"@types/node": "^10.0.0"
},
"devDependencies": {
"dtslint": "^0.5.4",
"typescript": "^3.7.3"
}
}
64 changes: 64 additions & 0 deletions integration-tests/types/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// import App, { ActionConstraints } from '../../src/App';
import { App, MessageAction } from '@slack/bolt';

const app = new App({ token: 'TOKEN', signingSecret: 'Signing Secret' });

// calling action method with incorrect an type constraint value should not work
// $ExpectError
app.action({ type: 'Something wrong' }, ({ action }) => {
return action;
});

/* Not working
// Should error because message_action doesn't have type action_id
// $ Expect Error
app.action({ type: 'message_action', action_id: 'dafasf' }, ({ action }) => {
return action;
});
*/

// Action in listner should be - MessageAction
// $ExpectType void
app.action({ type: 'message_action' }, ({
action, // $ExpectType MessageAction
}) => {
return action;
});

// $ExpectType void
app.action({ type: 'block_actions' }, ({
action, // $ExpectType BlockElementAction
}) => {
return action;
});

// $ExpectType void
app.action({ type: 'interactive_message' }, ({
action, // $ExpectType InteractiveAction
}) => {
return action;
});

// $ExpectType void
app.action({ type: 'dialog_submission' }, ({
action, // $ExpectType DialogSubmitAction
}) => {
return action;
});

// If action is parameterized with MessageAction, action argument in callback should be type MessageAction
// $ExpectType void
app.action<MessageAction>({}, ({
action // $ExpectType MessageAction
}) => {
return action;
});

/* Not working
// Should error because MessageAction doesn't have an action_id
// $ Expect Error
app.actiong<MessageAction>({ action_id: 'dafasf' }, ({ action }) => {
// NOT WORKING
return action;
});
*/
2 changes: 2 additions & 0 deletions integration-tests/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// tslint:disable:no-useless-files
// TypeScript Version: 3.3
12 changes: 12 additions & 0 deletions integration-tests/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"lib": ["es5"]
}
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slack/bolt",
"version": "1.4.0",
"version": "1.5.0",
"description": "A framework for building Slack apps, fast.",
"author": "Slack Technologies, Inc.",
"license": "MIT",
Expand Down Expand Up @@ -29,7 +29,9 @@
"build": "tsc",
"build:clean": "shx rm -rf ./dist ./coverage ./.nyc_output",
"lint": "tslint --project .",
"test": "nyc mocha --config .mocharc.json \"src/**/*.spec.ts\"",
"mocha": "nyc mocha --config .mocharc.json \"src/**/*.spec.ts\"",
"test": "npm run lint && npm run mocha && npm run test:integration",
"test:integration": "cd integration-tests && npm install && npm test",
"coverage": "codecov"
},
"repository": "slackapi/bolt",
Expand All @@ -39,8 +41,8 @@
},
"dependencies": {
"@slack/logger": ">=1.0.0 <3.0.0",
"@slack/types": "^1.0.0",
"@slack/web-api": "^5.0.0",
"@slack/types": "^1.2.1",
"@slack/web-api": "^5.6.0",
"@types/express": "^4.16.1",
"@types/node": ">=10",
"axios": "^0.18.1",
Expand Down
Loading

0 comments on commit e8bb742

Please sign in to comment.