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

Fixes #1241 Replacing instances of console with logger #1242

Merged
merged 3 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions docs/_advanced/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function addTimezoneContext({ payload, client, context, next }) {
await next();
}

app.command('/request', addTimezoneContext, async ({ command, ack, client, context }) => {
app.command('/request', addTimezoneContext, async ({ command, ack, client, context, logger }) => {
// Acknowledge command request
await ack();
// Get local hour of request
Expand All @@ -50,7 +50,7 @@ app.command('/request', addTimezoneContext, async ({ command, ack, client, conte
});
}
catch (error) {
console.error(error);
logger.error(error);
}
} else {
try {
Expand All @@ -61,7 +61,7 @@ app.command('/request', addTimezoneContext, async ({ command, ack, client, conte
});
}
catch (error) {
console.error(error);
logger.error(error);
}
}
});
Expand Down
6 changes: 3 additions & 3 deletions docs/_advanced/ja_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function addTimezoneContext({ payload, client, context, next }) {
await next();
}

app.command('/request', addTimezoneContext, async ({ command, ack, client, context }) => {
app.command('/request', addTimezoneContext, async ({ command, ack, client, context, logger }) => {
// コマンドリクエストの確認
await ack();
// リクエスト時のローカル時間を取得
Expand All @@ -50,7 +50,7 @@ app.command('/request', addTimezoneContext, async ({ command, ack, client, conte
});
}
catch (error) {
console.error(error);
logger.error(error);
}
} else {
try {
Expand All @@ -61,7 +61,7 @@ app.command('/request', addTimezoneContext, async ({ command, ack, client, conte
});
}
catch (error) {
console.error(error);
logger.error(error);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion docs/_advanced/ja_middleware_listener.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function noBotMessages({ message, next }) {
}

// ボットではなく人間からのメッセージのみを受信するリスナー
app.message(noBotMessages, async ({ message }) => console.log(
app.message(noBotMessages, async ({ message, logger }) => logger.info(
`(MSG) User: ${message.user}
Message: ${message.text}`
));
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 @@ -26,7 +26,7 @@ async function noBotMessages({ message, next }) {
}

// The listener only receives messages from humans
app.message(noBotMessages, async ({ message }) => console.log(
app.message(noBotMessages, async ({ message, logger }) => logger.info(
`(MSG) User: ${message.user}
Message: ${message.text}`
));
Expand Down
6 changes: 3 additions & 3 deletions docs/_basic/ja_listening_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ app.action('approve_button', async ({ ack }) => {
```javascript
// action_id が 'select_user' と一致し、block_id が 'assign_ticket' と一致する場合のみミドルウェアが呼び出される
app.action({ action_id: 'select_user', block_id: 'assign_ticket' },
async ({ body, client, ack }) => {
async ({ body, client, ack, logger }) => {
await ack();
try {
if (body.message) {
Expand All @@ -45,11 +45,11 @@ app.action({ action_id: 'select_user', block_id: 'assign_ticket' },
channel: body.channel.id
});

console.log(result);
logger.info(result);
}
}
catch (error) {
console.error(error);
logger.error(error);
}
});
```
Expand Down
10 changes: 5 additions & 5 deletions docs/_basic/ja_listening_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ order: 3
const welcomeChannelId = 'C12345';

// 新しいユーザーがワークスペースに加入したタイミングで、指定のチャンネルにメッセージを送信して自己紹介を促す
app.event('team_join', async ({ event, client }) => {
app.event('team_join', async ({ event, client, logger }) => {
try {
const result = await client.chat.postMessage({
channel: welcomeChannelId,
text: `Welcome to the team, <@${event.user.id}>! 🎉 You can introduce yourself in this channel.`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this change is correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I think you're right, I was testing with the wrong event! I was going to check the doc but there isn't a full example there either: https://api.slack.com/events/team_join.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I just tested it again to be sure and reverted the change now.

});
console.log(result);
logger.info(result);
}
catch (error) {
console.error(error);
logger.error(error);
}
});
```
Expand All @@ -42,8 +42,8 @@ app.event('team_join', async ({ event, client }) => {

```javascript
// bot からのメッセージ全てと一致
app.message(subtype('bot_message'), ({ message }) => {
console.log(`The bot user ${message.user} said ${message.text}`);
app.message(subtype('bot_message'), ({ message, logger }) => {
logger.info(`The bot user ${message.user} said ${message.text}`);
});
```

Expand Down
4 changes: 2 additions & 2 deletions docs/_basic/ja_listening_modals.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ app.view('modal-callback-id', async ({ ack, body }) => {

```javascript
// モーダルでのデータ送信リクエストを処理します
app.view('view_b', async ({ ack, body, view, client }) => {
app.view('view_b', async ({ ack, body, view, client, logger }) => {
// モーダルでのデータ送信リクエストを確認
await ack();

Expand Down Expand Up @@ -64,7 +64,7 @@ app.view('view_b', async ({ ack, body, view, client }) => {
});
}
catch (error) {
console.error(error);
logger.error(error);
}

});
Expand Down
12 changes: 6 additions & 6 deletions docs/_basic/ja_listening_responding_shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ order: 8

```javascript
// open_modal というグローバルショートカットはシンプルなモーダルを開く
app.shortcut('open_modal', async ({ shortcut, ack, context }) => {
app.shortcut('open_modal', async ({ shortcut, ack, context, logger }) => {
// グローバルショートカットリクエストの確認
ack();

Expand Down Expand Up @@ -63,10 +63,10 @@ app.shortcut('open_modal', async ({ shortcut, ack, context }) => {
}
});

console.log(result);
logger.info(result);
}
catch (error) {
console.error(error);
logger.error(error);
}
});
```
Expand All @@ -83,7 +83,7 @@ app.shortcut('open_modal', async ({ shortcut, ack, context }) => {

```javascript
// callback_id が 'open_modal' と一致し type が 'message_action' と一致する場合のみミドルウェアが呼び出される
app.shortcut({ callback_id: 'open_modal', type: 'message_action' }, async ({ shortcut, ack, context, client }) => {
app.shortcut({ callback_id: 'open_modal', type: 'message_action' }, async ({ shortcut, ack, context, client, logger }) => {
try {
// ショートカットリクエストの確認
await ack();
Expand Down Expand Up @@ -124,10 +124,10 @@ app.shortcut('open_modal', async ({ shortcut, ack, context }) => {
}
});

console.log(result);
logger.info(result);
}
catch (error) {
console.error(error);
logger.error(error);
}
});
```
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 @@ -16,7 +16,7 @@ order: 10

```javascript
// コマンド起動をリッスン
app.command('/ticket', async ({ ack, body, client }) => {
app.command('/ticket', async ({ ack, body, client, logger }) => {
// コマンドのリクエストを確認
await ack();

Expand Down Expand Up @@ -69,10 +69,10 @@ app.command('/ticket', async ({ ack, body, client }) => {
}
}
});
console.log(result);
logger.info(result);
}
catch (error) {
console.error(error);
logger.error(error);
}
});
```
6 changes: 3 additions & 3 deletions docs/_basic/ja_publishing_views.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ order: 13

```javascript
// ユーザーが App Home にアクセスしたことを伝えるイベントをリッスン
app.event('app_home_opened', async ({ event, client }) => {
app.event('app_home_opened', async ({ event, client, logger }) => {
try {
// 組み込みの API クライアントを使って views.publish を呼び出す
const result = await client.views.publish({
Expand Down Expand Up @@ -41,10 +41,10 @@ app.event('app_home_opened', async ({ event, client }) => {
}
});

console.log(result);
logger.info(result);
}
catch (error) {
console.error(error);
logger.error(error);
}
});
```
6 changes: 3 additions & 3 deletions docs/_basic/ja_updating_pushing_modals.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ order: 11
```javascript
// action_id: button_abc のボタンを押すイベントをリッスン
// (そのボタンはモーダルの中にあるという想定)
app.action('button_abc', async ({ ack, body, client }) => {
app.action('button_abc', async ({ ack, body, client, logger }) => {
// ボタンを押したイベントを確認
await ack();

Expand Down Expand Up @@ -55,10 +55,10 @@ app.action('button_abc', async ({ ack, body, client }) => {
]
}
});
console.log(result);
logger.info(result);
}
catch (error) {
console.error(error);
logger.error(error);
}
});
```
4 changes: 2 additions & 2 deletions docs/_basic/ja_web_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Bolt アプリケーションは、トップレベルに `app.client` も持っ
// September 30, 2019 11:59:59 PM を Unix エポックタイムで表示
const whenSeptemberEnds = '1569887999';

app.message('wake me up', async ({ message, context }) => {
app.message('wake me up', async ({ message, context, logger }) => {
try {
// トークンを用いて chat.scheduleMessage 関数を呼び出す
const result = await app.client.chat.scheduleMessage({
Expand All @@ -31,7 +31,7 @@ app.message('wake me up', async ({ message, context }) => {
});
}
catch (error) {
console.error(error);
logger.error(error);
}
});
```
6 changes: 3 additions & 3 deletions docs/_basic/listening_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ You can use a constraints object to listen to `callback_id`s, `block_id`s, and `
```javascript
// Your listener function will only be called when the action_id matches 'select_user' AND the block_id matches 'assign_ticket'
app.action({ action_id: 'select_user', block_id: 'assign_ticket' },
async ({ body, client, ack }) => {
async ({ body, client, ack, logger }) => {
await ack();
try {
// Make sure the action isn't from a view (modal or app home)
Expand All @@ -46,11 +46,11 @@ app.action({ action_id: 'select_user', block_id: 'assign_ticket' },
channel: body.channel.id
});

console.log(result);
logger.info(result);
}
}
catch (error) {
console.error(error);
logger.error(error);
}
});
```
Expand Down
10 changes: 5 additions & 5 deletions docs/_basic/listening_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ The `event()` method requires an `eventType` of type string.
const welcomeChannelId = 'C12345';

// When a user joins the team, send a message in a predefined channel asking them to introduce themselves
app.event('team_join', async ({ event, client }) => {
app.event('team_join', async ({ event, client, logger }) => {
try {
// Call chat.postMessage with the built-in client
const result = await client.chat.postMessage({
channel: welcomeChannelId,
text: `Welcome to the team, <@${event.user.id}>! 🎉 You can introduce yourself in this channel.`
});
console.log(result);
logger.info(result);
}
catch (error) {
console.error(error);
logger.error(error);
}
});
```
Expand All @@ -43,8 +43,8 @@ You can filter on subtypes of events by using the built-in `subtype()` middlewar

```javascript
// Matches all messages from bot users
app.message(subtype('bot_message'), ({ message }) => {
console.log(`The bot user ${message.user} said ${message.text}`);
app.message(subtype('bot_message'), ({ message, logger }) => {
logger.info(`The bot user ${message.user} said ${message.text}`);
});
```

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 @@ -55,7 +55,7 @@ app.view({ callback_id: 'view_b', type: 'view_closed' }, async ({ ack, body, vie

```javascript
// Handle a view_submission request
app.view('view_b', async ({ ack, body, view, client }) => {
app.view('view_b', async ({ ack, body, view, client, logger }) => {
// Acknowledge the view_submission request
await ack();

Expand Down Expand Up @@ -85,7 +85,7 @@ app.view('view_b', async ({ ack, body, view, client }) => {
});
}
catch (error) {
console.error(error);
logger.error(error);
}

});
Expand Down
12 changes: 6 additions & 6 deletions docs/_basic/listening_responding_shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ When configuring shortcuts within your app configuration, you'll continue to app

```javascript
// The open_modal shortcut opens a plain old modal
app.shortcut('open_modal', async ({ shortcut, ack, client }) => {
app.shortcut('open_modal', async ({ shortcut, ack, client, logger }) => {

try {
// Acknowledge shortcut request
Expand Down Expand Up @@ -65,10 +65,10 @@ app.shortcut('open_modal', async ({ shortcut, ack, client }) => {
}
});

console.log(result);
logger.info(result);
}
catch (error) {
console.error(error);
logger.error(error);
}
});
```
Expand All @@ -84,7 +84,7 @@ app.shortcut('open_modal', async ({ shortcut, ack, client }) => {

```javascript
// Your middleware will only be called when the callback_id matches 'open_modal' AND the type matches 'message_action'
app.shortcut({ callback_id: 'open_modal', type: 'message_action' }, async ({ shortcut, ack, client }) => {
app.shortcut({ callback_id: 'open_modal', type: 'message_action' }, async ({ shortcut, ack, client, logger }) => {
try {
// Acknowledge shortcut request
await ack();
Expand Down Expand Up @@ -123,10 +123,10 @@ app.shortcut('open_modal', async ({ shortcut, ack, client }) => {
}
});

console.log(result);
logger.info(result);
}
catch (error) {
console.error(error);
logger.error(error);
}
});
```
Expand Down
Loading