forked from slackapi/bolt-js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
title: オプションのリスニングと応答 | ||
lang: ja-jp | ||
slug: options | ||
order: 13 | ||
order: 14 | ||
--- | ||
|
||
<div class="section-content"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
title: ホームタブの更新 | ||
lang: ja-jp | ||
slug: publishing-views | ||
order: 13 | ||
--- | ||
|
||
<div class="section-content"> | ||
<a href="https://api.slack.com/surfaces/tabs/using">ホームタブ</a>は、サイドバーや検索画面からアクセス可能なサーフェスエリアです。アプリはこのエリアを使ってユーザーごとのビューを表示することができます。アプリ設定ページで App Home の機能を有効にすると、<a href="https://api.slack.com/methods/views.publish">`views.publish`</a> API メソッドの呼び出しで `user_id` と<a href="https://api.slack.com/reference/block-kit/views">ビューのペイロード</a>を指定して、ホームタブを公開・更新することができるようになります。 | ||
|
||
エンドユーザーが App Home(ホームタブやアプリとの DM など)にアクセスしたことを知るために、<a href="https://api.slack.com/events/app_home_opened">`app_home_opened`</a> イベントをサブスクライブすることができます。 | ||
</div> | ||
|
||
```javascript | ||
// ユーザーが App Home にアクセスしたことを伝えるイベントをリッスン | ||
app.event('app_home_opened', async ({ event, client }) => { | ||
try { | ||
// 組み込みの API クライアントを使って views.publish を呼び出す | ||
const result = await client.views.publish({ | ||
// イベントに紐づけられたユーザー ID を指定 | ||
user_id: event.user, | ||
view: { | ||
// ホームタブはあらかじめアプリ設定ページで有効にしておく必要があります | ||
"type": "home", | ||
"blocks": [ | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": "*Welcome home, <@" + event.user + "> :house:*" | ||
} | ||
}, | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": "Learn how home tabs can be more useful and interactive <https://api.slack.com/surfaces/tabs/using|*in the documentation*>." | ||
} | ||
} | ||
] | ||
} | ||
}); | ||
|
||
console.log(result); | ||
} | ||
catch (error) { | ||
console.error(error); | ||
} | ||
}); | ||
``` |