From e3a5d34a7563b9dd8c7c84aac00383651a612c02 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Mon, 23 Dec 2019 10:26:49 +0900 Subject: [PATCH 1/2] Improve code format consistency in docs --- README.md | 13 ++++----- docs/_advanced/authorization.md | 2 +- docs/_advanced/context.md | 4 +-- docs/_advanced/error_handling.md | 4 +-- docs/_advanced/ja_authorization.md | 2 +- docs/_advanced/ja_context.md | 2 +- docs/_advanced/ja_error_handling.md | 4 +-- docs/_advanced/ja_middleware_listener.md | 2 +- docs/_advanced/ja_receiver.md | 2 +- docs/_advanced/middleware_listener.md | 2 +- docs/_advanced/receiver.md | 2 +- docs/_basic/acknowledging_requests.md | 14 ++++----- docs/_basic/ja_acknowledging_requests.md | 14 ++++----- docs/_basic/ja_listening_actions.md | 2 +- docs/_basic/ja_listening_messages.md | 4 +-- .../ja_listening_responding_commands.md | 2 +- .../_basic/ja_listening_responding_options.md | 2 +- docs/_basic/ja_responding_actions.md | 6 ++-- docs/_basic/ja_sending_messages.md | 29 ++++++++++--------- docs/_basic/listening_actions.md | 2 +- docs/_basic/listening_messages.md | 4 +-- docs/_basic/listening_modals.md | 4 +-- docs/_basic/listening_responding_commands.md | 2 +- docs/_basic/listening_responding_options.md | 2 +- docs/_basic/responding_actions.md | 4 +-- docs/_basic/sending_messages.md | 29 ++++++++++--------- 26 files changed, 80 insertions(+), 79 deletions(-) diff --git a/README.md b/README.md index bdb6bcdb0..aebe46245 100644 --- a/README.md +++ b/README.md @@ -259,7 +259,7 @@ 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 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 @@ -267,7 +267,6 @@ function authWithAcme({ payload, context, say, next }) { next(error); }); } - ``` ### Listener middleware @@ -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}` )); ``` @@ -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}` )); ``` diff --git a/docs/_advanced/authorization.md b/docs/_advanced/authorization.md index aa2b3548d..080817d1a 100644 --- a/docs/_advanced/authorization.md +++ b/docs/_advanced/authorization.md @@ -54,7 +54,7 @@ const authorizeFn = async ({ teamId, enterpriseId }) => { }; } } - + throw new Error('No matching authorizations'); } ``` diff --git a/docs/_advanced/context.md b/docs/_advanced/context.md index 6d19fcec3..1251a30c0 100644 --- a/docs/_advanced/context.md +++ b/docs/_advanced/context.md @@ -12,7 +12,7 @@ All listeners have access to a `context` object, which can be used to enrich eve ```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, @@ -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(); } diff --git a/docs/_advanced/error_handling.md b/docs/_advanced/error_handling.md index 2286bcff8..b2e989ae3 100644 --- a/docs/_advanced/error_handling.md +++ b/docs/_advanced/error_handling.md @@ -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); }); ``` \ No newline at end of file diff --git a/docs/_advanced/ja_authorization.md b/docs/_advanced/ja_authorization.md index 5f418b223..cc2b9fcc5 100644 --- a/docs/_advanced/ja_authorization.md +++ b/docs/_advanced/ja_authorization.md @@ -54,7 +54,7 @@ const authorizeFn = async ({ teamId, enterpriseId }) => { }; } } - + throw new Error('No matching authorizations'); // 認証エラー } ``` diff --git a/docs/_advanced/ja_context.md b/docs/_advanced/ja_context.md index a17b38036..2597e5de5 100644 --- a/docs/_advanced/ja_context.md +++ b/docs/_advanced/ja_context.md @@ -12,7 +12,7 @@ order: 6 ```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, diff --git a/docs/_advanced/ja_error_handling.md b/docs/_advanced/ja_error_handling.md index cc36439d4..c602e0912 100644 --- a/docs/_advanced/ja_error_handling.md +++ b/docs/_advanced/ja_error_handling.md @@ -13,7 +13,7 @@ order: 1 ```javascript app.error((error) => { - // メッセージ再送信もしくはアプリを停止するかの決定をくだすために、エラーの詳細をチェック - console.error(error); + // メッセージ再送信もしくはアプリを停止するかの判断をするためにエラーの詳細を出力して確認 + console.error(error); }); ``` \ No newline at end of file diff --git a/docs/_advanced/ja_middleware_listener.md b/docs/_advanced/ja_middleware_listener.md index dc9413761..b6fbc2d99 100644 --- a/docs/_advanced/ja_middleware_listener.md +++ b/docs/_advanced/ja_middleware_listener.md @@ -19,7 +19,7 @@ order: 5 // 'bot_message' サブタイプを持つメッセージをフィルタリングするリスナーミドルウェア function noBotMessages({ message, next }) { if (!message.subtype || message.subtype !== 'bot_message') { - next(); + next(); } } diff --git a/docs/_advanced/ja_receiver.md b/docs/_advanced/ja_receiver.md index 4b397e354..b2210fe96 100644 --- a/docs/_advanced/ja_receiver.md +++ b/docs/_advanced/ja_receiver.md @@ -47,7 +47,7 @@ class simpleReceiver extends EventEmitter { this.server.listen(port, () => { resolve(this.server); }); - } catch(error) { + } catch (error) { reject(error); } }); diff --git a/docs/_advanced/middleware_listener.md b/docs/_advanced/middleware_listener.md index 99e0a6e11..c65470e39 100644 --- a/docs/_advanced/middleware_listener.md +++ b/docs/_advanced/middleware_listener.md @@ -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(); } } diff --git a/docs/_advanced/receiver.md b/docs/_advanced/receiver.md index 506ded182..4363b400b 100644 --- a/docs/_advanced/receiver.md +++ b/docs/_advanced/receiver.md @@ -47,7 +47,7 @@ class simpleReceiver extends EventEmitter { this.server.listen(port, () => { resolve(this.server); }); - } catch(error) { + } catch (error) { reject(error); } }); diff --git a/docs/_basic/acknowledging_requests.md b/docs/_basic/acknowledging_requests.md index 7358e75b1..2464e86c0 100644 --- a/docs/_basic/acknowledging_requests.md +++ b/docs/_basic/acknowledging_requests.md @@ -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" }] }); } diff --git a/docs/_basic/ja_acknowledging_requests.md b/docs/_basic/ja_acknowledging_requests.md index 44b8efeda..fad09fc05 100644 --- a/docs/_basic/ja_acknowledging_requests.md +++ b/docs/_basic/ja_acknowledging_requests.md @@ -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" }] }); } diff --git a/docs/_basic/ja_listening_actions.md b/docs/_basic/ja_listening_actions.md index e13e1b7b6..5fc3b50af 100644 --- a/docs/_basic/ja_listening_actions.md +++ b/docs/_basic/ja_listening_actions.md @@ -47,7 +47,7 @@ app.action({ action_id: 'select_user', block_id: 'assign_ticket' }, catch (error) { console.error(error); } -}); + }); ``` diff --git a/docs/_basic/ja_listening_messages.md b/docs/_basic/ja_listening_messages.md index fb47b24c4..a81f983f2 100644 --- a/docs/_basic/ja_listening_messages.md +++ b/docs/_basic/ja_listening_messages.md @@ -13,7 +13,7 @@ order: 1 ```javascript // 特定の文字列、この場合 👋絵文字を含むメッセージと一致 -app.message(':wave:', async ({ message, say}) => { +app.message(':wave:', async ({ message, say }) => { say(`Hello, <@${message.user}>`); }); ``` @@ -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?`); }); ``` diff --git a/docs/_basic/ja_listening_responding_commands.md b/docs/_basic/ja_listening_responding_commands.md index 6f1dd509e..5cde858c5 100644 --- a/docs/_basic/ja_listening_responding_commands.md +++ b/docs/_basic/ja_listening_responding_commands.md @@ -18,7 +18,7 @@ order: 8 app.command('/echo', async ({ command, ack, say }) => { // コマンドリクエストを確認 ack(); - + say(`${command.text}`); }); ``` diff --git a/docs/_basic/ja_listening_responding_options.md b/docs/_basic/ja_listening_responding_options.md index c67c292a5..14844abb8 100644 --- a/docs/_basic/ja_listening_responding_options.md +++ b/docs/_basic/ja_listening_responding_options.md @@ -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 配列に情報をプッシュ diff --git a/docs/_basic/ja_responding_actions.md b/docs/_basic/ja_responding_actions.md index 4a9196dad..54ce9d525 100644 --- a/docs/_basic/ja_responding_actions.md +++ b/docs/_basic/ja_responding_actions.md @@ -30,10 +30,10 @@ app.action('approve_button', ({ ack, say }) => { ```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}>`); }); ``` diff --git a/docs/_basic/ja_sending_messages.md b/docs/_basic/ja_sending_messages.md index e6ce45fef..4190acb26 100644 --- a/docs/_basic/ja_sending_messages.md +++ b/docs/_basic/ja_sending_messages.md @@ -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" } - }]}); + } + }] + }); } }); ``` diff --git a/docs/_basic/listening_actions.md b/docs/_basic/listening_actions.md index e592d9b16..b77bee62f 100644 --- a/docs/_basic/listening_actions.md +++ b/docs/_basic/listening_actions.md @@ -47,7 +47,7 @@ app.action({ action_id: 'select_user', block_id: 'assign_ticket' }, catch (error) { console.error(error); } -}); + }); ``` diff --git a/docs/_basic/listening_messages.md b/docs/_basic/listening_messages.md index 6b025fe73..94f2d5884 100644 --- a/docs/_basic/listening_messages.md +++ b/docs/_basic/listening_messages.md @@ -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}>`); }); ``` @@ -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?`); }); ``` diff --git a/docs/_basic/listening_modals.md b/docs/_basic/listening_modals.md index a32898825..46cbbdcf2 100644 --- a/docs/_basic/listening_modals.md +++ b/docs/_basic/listening_modals.md @@ -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'; @@ -50,6 +50,6 @@ app.view('view_b', async ({ ack, body, view, context }) => { catch (error) { console.error(error); } - + }); ``` diff --git a/docs/_basic/listening_responding_commands.md b/docs/_basic/listening_responding_commands.md index 778f84e67..9fccd3b18 100644 --- a/docs/_basic/listening_responding_commands.md +++ b/docs/_basic/listening_responding_commands.md @@ -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}`); }); ``` diff --git a/docs/_basic/listening_responding_options.md b/docs/_basic/listening_responding_options.md index 0099bae6d..0f5e10418 100644 --- a/docs/_basic/listening_responding_options.md +++ b/docs/_basic/listening_responding_options.md @@ -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 diff --git a/docs/_basic/responding_actions.md b/docs/_basic/responding_actions.md index 907390a9c..0f84b6d87 100644 --- a/docs/_basic/responding_actions.md +++ b/docs/_basic/responding_actions.md @@ -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}>`); }); ``` diff --git a/docs/_basic/sending_messages.md b/docs/_basic/sending_messages.md index bb33e4aa6..f0863e204 100644 --- a/docs/_basic/sending_messages.md +++ b/docs/_basic/sending_messages.md @@ -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" } - }]}); + } + }] + }); } }); ``` From c82ffd3eb140a69ebdb7315d8b675be0dea47aa3 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Wed, 25 Dec 2019 18:33:20 +0900 Subject: [PATCH 2/2] Tweak a sentence in Japanese documentation --- docs/_advanced/ja_authorization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_advanced/ja_authorization.md b/docs/_advanced/ja_authorization.md index 5f418b223..e65dd4382 100644 --- a/docs/_advanced/ja_authorization.md +++ b/docs/_advanced/ja_authorization.md @@ -47,7 +47,7 @@ const authorizeFn = async ({ teamId, enterpriseId }) => { if ((team.teamId === teamId) && (team.enterpriseId === enterpriseId)) { // 一致したワークスペースの認証情報を使用 return { - // かわりに userToken を使用 + // 代わりに userToken をセットしても OK botToken: team.botToken, botId: team.botId, botUserId: team.botUserId