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

Improve code format consistency in docs #356

Merged
merged 2 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,14 @@ function authWithAcme({ payload, context, say, next }) {
// In the real world, you would need to check if the say function was defined, falling back to the respond
// function if not, and then falling back to only logging the error as a last resort.
say(`I'm sorry <@${slackUserId}, you aren't registered with Acme. Please use <https://acme.com/register> to use this app.`);
return;
return;
}

// This middleware doesn't know how to handle any other errors. Pass control to the previous middleware (if there
// are any) or the global error handler.
next(error);
});
}

```

### Listener middleware
Expand All @@ -285,14 +284,14 @@ before the listener attached to `message` events:
// Listener middleware - filters out messages that have subtype 'bot_message'
function noBotMessages({ message, next }) {
if (!message.subtype || message.subtype !== 'bot_message') {
next();
next();
}
}

// The listener only sees messages from human users
app.message(noBotMessages, ({ message }) => console.log(
`(MSG) User: ${message.user}
Message: ${message.text}`
`(MSG) User: ${message.user}
Message: ${message.text}`
));
```

Expand All @@ -307,8 +306,8 @@ const { App, subtype } = require('@slack/bolt');

// The listener only sees messages from bot users (apps)
app.message(subtype('bot_message'), ({ message }) => console.log(
`(MSG) Bot: ${message.bot_id}
Message: ${message.text}`
`(MSG) Bot: ${message.bot_id}
Message: ${message.text}`
));
```

Expand Down
2 changes: 1 addition & 1 deletion docs/_advanced/authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const authorizeFn = async ({ teamId, enterpriseId }) => {
};
}
}

throw new Error('No matching authorizations');
}
```
4 changes: 2 additions & 2 deletions docs/_advanced/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ All listeners have access to a `context` object, which can be used to enrich eve
</div>

```javascript
async function addTimezoneContext ({ payload, context, next }) {
async function addTimezoneContext({ payload, context, next }) {
const user = await app.client.users.info({
token: context.botToken,
user: payload.user_id,
Expand All @@ -21,7 +21,7 @@ async function addTimezoneContext ({ payload, context, next }) {

// Add user's timezone context
context.tz_offset = user.tz_offset;

// Pass control to the next middleware function
next();
}
Expand Down
4 changes: 2 additions & 2 deletions docs/_advanced/error_handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you want more control over errors, it’s advised to use the [`chat.postMessa

```javascript
app.error((error) => {
// Check the details of the error to handle cases where you should retry sending a message or stop the app
console.error(error);
// Check the details of the error to handle cases where you should retry sending a message or stop the app
console.error(error);
});
```
2 changes: 1 addition & 1 deletion docs/_advanced/ja_authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const authorizeFn = async ({ teamId, enterpriseId }) => {
};
}
}

throw new Error('No matching authorizations'); // 認証エラー
}
```
2 changes: 1 addition & 1 deletion docs/_advanced/ja_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ order: 6
</div>

```javascript
async function addTimezoneContext ({ payload, context, next }) {
async function addTimezoneContext({ payload, context, next }) {
const user = await app.client.users.info({
token: context.botToken,
user: payload.user_id,
Expand Down
4 changes: 2 additions & 2 deletions docs/_advanced/ja_error_handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ order: 1

```javascript
app.error((error) => {
// メッセージ再送信もしくはアプリを停止するかの決定をくだすために、エラーの詳細をチェック
console.error(error);
// メッセージ再送信もしくはアプリを停止するかの判断をするためにエラーの詳細を出力して確認
console.error(error);
});
```
2 changes: 1 addition & 1 deletion docs/_advanced/ja_middleware_listener.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ order: 5
// 'bot_message' サブタイプを持つメッセージをフィルタリングするリスナーミドルウェア
function noBotMessages({ message, next }) {
if (!message.subtype || message.subtype !== 'bot_message') {
next();
next();
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/_advanced/ja_receiver.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class simpleReceiver extends EventEmitter {
this.server.listen(port, () => {
resolve(this.server);
});
} catch(error) {
} catch (error) {
reject(error);
}
});
Expand Down
2 changes: 1 addition & 1 deletion docs/_advanced/middleware_listener.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ As an example, let’s say your listener should only deal with messages from hum
// Listener middleware that filters out messages with 'bot_message' subtype
function noBotMessages({ message, next }) {
if (!message.subtype || message.subtype !== 'bot_message') {
next();
next();
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/_advanced/receiver.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class simpleReceiver extends EventEmitter {
this.server.listen(port, () => {
resolve(this.server);
});
} catch(error) {
} catch (error) {
reject(error);
}
});
Expand Down
14 changes: 7 additions & 7 deletions docs/_basic/acknowledging_requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ We recommend calling `ack()` right away before sending a new message or fetching
let isEmail = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/
// This uses a constraint object to listen for dialog submissions with a callback_id of ticket_submit
app.action({ callback_id: 'ticket_submit' }, ({ action, ack }) => {
// it’s a valid email, accept the submission
// it’s a valid email, accept the submission
if (isEmail.test(action.submission.email)) {
ack();
ack();
} else {
// if it isn’t a valid email, acknowledge with an error
ack({
errors: [{
"name": "email_address",
"error": "Sorry, this isn’t a valid email"
// if it isn’t a valid email, acknowledge with an error
ack({
errors: [{
"name": "email_address",
"error": "Sorry, this isn’t a valid email"
}]
});
}
Expand Down
14 changes: 7 additions & 7 deletions docs/_basic/ja_acknowledging_requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ order: 7
let isEmail = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/
// 制約付きのオブジェクト を使用して ticket_submit という callback_id を持つダイアログ送信をリスニング
app.action({ callback_id: 'ticket_submit' }, ({ action, ack }) => {
// メールアドレスが有効。ダイアログを受信
// メールアドレスが有効。ダイアログを受信
if (isEmail.test(action.submission.email)) {
ack();
ack();
} else {
// メールアドレスが無効。エラーを確認
ack({
errors: [{
"name": "email_address",
"error": "Sorry, this isn’t a valid email"
// メールアドレスが無効。エラーを確認
ack({
errors: [{
"name": "email_address",
"error": "Sorry, this isn’t a valid email"
}]
});
}
Expand Down
2 changes: 1 addition & 1 deletion docs/_basic/ja_listening_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ app.action({ action_id: 'select_user', block_id: 'assign_ticket' },
catch (error) {
console.error(error);
}
});
});
```

</details>
4 changes: 2 additions & 2 deletions docs/_basic/ja_listening_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ order: 1

```javascript
// 特定の文字列、この場合 👋絵文字を含むメッセージと一致
app.message(':wave:', async ({ message, say}) => {
app.message(':wave:', async ({ message, say }) => {
say(`Hello, <@${message.user}>`);
});
```
Expand All @@ -33,7 +33,7 @@ RegExp の一致結果はすべて `context.matches` に格納されます。
app.message(/^(hi|hello|hey).*/, async ({ context, say }) => {
// context.matches の内容が特定の正規表現と一致
const greeting = context.matches[0];

say(`${greeting}, how are you?`);
});
```
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 @@ -18,7 +18,7 @@ order: 8
app.command('/echo', async ({ command, ack, say }) => {
// コマンドリクエストを確認
ack();

say(`${command.text}`);
});
```
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 @@ -18,7 +18,7 @@ order: 12
app.options('external_action', async ({ options, ack }) => {
// チームまたはチャンネル情報を取得
const results = await db.get(options.team.id);

if (results) {
let options = [];
// ack 応答 するために options 配列に情報をプッシュ
Expand Down
6 changes: 3 additions & 3 deletions docs/_basic/ja_responding_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ app.action('approve_button', ({ ack, say }) => {
</div>

```javascript
// user_select の action_id がトリガーされたアクションをリスニング
// "user_select" の action_id がトリガーされたアクションをリスニング
app.action('user_choice', ({ action, ack, respond }) => {
ack();
respond(`You selected <@${action.selected_user}>`);
ack();
respond(`You selected <@${action.selected_user}>`);
});
```

Expand Down
29 changes: 15 additions & 14 deletions docs/_basic/ja_sending_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,22 @@ app.event('reaction_added', ({ event, say }) => {
if (event.reaction === 'calendar') {
say({
blocks: [{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Pick a date for me to remind you"
},
"accessory": {
"type": "datepicker",
"action_id": "datepicker_remind",
"initial_date": "2019-04-28",
"placeholder": {
"type": "plain_text",
"text": "Select a date"
}
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Pick a date for me to remind you"
},
"accessory": {
"type": "datepicker",
"action_id": "datepicker_remind",
"initial_date": "2019-04-28",
"placeholder": {
"type": "plain_text",
"text": "Select a date"
}
}]});
}
}]
});
}
});
```
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 @@ -47,7 +47,7 @@ app.action({ action_id: 'select_user', block_id: 'assign_ticket' },
catch (error) {
console.error(error);
}
});
});
```

</details>
4 changes: 2 additions & 2 deletions docs/_basic/listening_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To listen to messages that [your app has access to receive](https://api.slack.co

```javascript
// This will match any message that contains 👋
app.message(':wave:', async ({ message, say}) => {
app.message(':wave:', async ({ message, say }) => {
say(`Hello, <@${message.user}>`);
});
```
Expand All @@ -33,7 +33,7 @@ All of the results of the RegExp match will be in `context.matches`.
app.message(/^(hi|hello|hey).*/, async ({ context, say }) => {
// RegExp matches are inside of context.matches
const greeting = context.matches[0];

say(`${greeting}, how are you?`);
});
```
Expand Down
4 changes: 2 additions & 2 deletions docs/_basic/listening_modals.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ app.view('view_b', async ({ ack, body, view, context }) => {
let msg = '';
// Save to DB
const results = await db.set(user.input, val);

if (results) {
// DB save was successful
msg = 'Your submission was successful';
Expand All @@ -50,6 +50,6 @@ app.view('view_b', async ({ ack, body, view, context }) => {
catch (error) {
console.error(error);
}

});
```
2 changes: 1 addition & 1 deletion docs/_basic/listening_responding_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ There are two ways to respond to slash commands. The first way is to use `say()`
app.command('/echo', async ({ command, ack, say }) => {
// Acknowledge command request
ack();

say(`${command.text}`);
});
```
2 changes: 1 addition & 1 deletion docs/_basic/listening_responding_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ To respond to options requests, you'll need to `ack()` with valid options. Both
app.options('external_action', async ({ options, ack }) => {
// Get information specific to a team or channel
const results = await db.get(options.team.id);

if (results) {
let options = [];
// Collect information in options array to send in Slack ack response
Expand Down
4 changes: 2 additions & 2 deletions docs/_basic/responding_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Since `respond()` is a utility for calling the `response_url`, it behaves in the
```javascript
// Listens to actions triggered with action_id of “user_select”
app.action('user_choice', ({ action, ack, respond }) => {
ack();
respond(`You selected <@${action.selected_user}>`);
ack();
respond(`You selected <@${action.selected_user}>`);
});
```

Expand Down
Loading