コンテンツにスキップ

Slack

Slack provider は digital worker を Slack workspace に統合します。次をサポートします:

  • ダイレクトメッセージ(DM)
  • channel message
  • app mention
  • interactive component(button、menu)
  • Block Kit rich messaging
  • slash command
  • thread reply
  • Slack workspace
  • Slack app を作成できる admin 権限
  1. Slack 設定トークンのペアを作成する

    api.slack.com/apps に移動し、app configuration token pair を作成します。次の 2 つの値をコピーします:

    • Configuration access token (xoxe.xoxp-...)
    • Configuration refresh token (xoxe-1-...)
  2. provider を設定する

    answers.json
    {
    "setup_answers": {
    "messaging-slack": {
    "slack_configuration_access_token": "xoxe.xoxp-xxx",
    "slack_configuration_refresh_token": "xoxe-1-xxx"
    }
    }
    }
  3. setup を実行する

    Terminal window
    gtc setup --answers answers.json ./my-bundle
  4. Add to Slack をクリックする

    setup は Slack app を登録または更新し、Add to Slack アクションを表示します。生成された Slack authorization URL を開き、workspace を選択し、要求された scopes を確認して install を承認します。

    OAuth redirect が setup に戻ると、Greentic は tenant 用に Slack app id、client id、client secret、runtime OAuth answers を保存します。callback が自動処理されなかった場合は、install 承認後に gtc setup --answers answers.json ./my-bundle をもう一度実行します。

  5. Slack で app を追加する

    Slack を開き、app が workspace にインストールされていることを確認します。channel の会話では、worker が応答する channel に app を追加します。channel の integration settings から、または channel で app を mention/invite して追加できます。

  6. runtime を開始または再起動する

    Terminal window
    gtc start ./my-bundle

    起動時には、保存済みの slack_app_id と設定トークンペアを使って、現在の webhook URL で Slack app manifest を更新します。

  7. channel をテストする

    app に direct message を送るか、追加した Slack channel で app を mention します。channel events は、app がメンバーであり、インストール済み scopes がその event を許可している channel でのみ届きます。

オプション必須説明
slack_configuration_access_tokenはいapp manifest の更新に使う短命の Slack configuration token
slack_configuration_refresh_tokenはいconfiguration access token をローテーションするための refresh token
slack_app_id生成setup が作成または返す Slack app id
slack_client_id生成app registration が返す Slack OAuth client id
client_secret生成された secretapp registration が返す Slack OAuth client secret
- id: reply
type: reply
config:
message: "Hello! How can I help you?"

Slack は mrkdwn format を使います:

- id: formatted
type: reply
config:
message: |
*Bold* _Italic_ `code`
>Blockquote
• Bullet point

rich layout には Slack の Block Kit を使います:

- id: rich_message
type: reply
config:
blocks:
- type: section
text:
type: mrkdwn
text: "*Welcome!*\nHow can I assist you today?"
- type: divider
- type: actions
elements:
- type: button
text:
type: plain_text
text: "Get Help"
action_id: "help_clicked"
value: "help"
- type: button
text:
type: plain_text
text: "View Status"
action_id: "status_clicked"
value: "status"
- id: ask_action
type: reply
config:
message: "What would you like to do?"
blocks:
- type: actions
elements:
- type: button
text:
type: plain_text
text: "Create Ticket"
style: primary
action_id: "create_ticket"
- type: button
text:
type: plain_text
text: "Cancel"
style: danger
action_id: "cancel"
- id: select_option
type: reply
config:
blocks:
- type: section
text:
type: mrkdwn
text: "Select a category:"
accessory:
type: static_select
action_id: "category_select"
options:
- text:
type: plain_text
text: "Technical Support"
value: "technical"
- text:
type: plain_text
text: "Billing"
value: "billing"
- text:
type: plain_text
text: "General"
value: "general"

thread に返信します:

- id: thread_reply
type: reply
config:
message: "This replies in the thread"
thread_ts: "{{original_message.thread_ts}}"

Slack の file API は時間とともに変わります。インストール済みの messaging-slack pack が対象バージョンの file support を公開している場合にのみ使用してください。それ以外の場合はリンクを送るか、Slack の現在の external upload flow を使用してください。

- id: upload_file
type: reply
config:
files:
- url: "https://example.com/report.pdf"
filename: "report.pdf"
title: "Monthly Report"

1人の user にだけ見えるメッセージです:

- id: ephemeral
type: reply
config:
message: "Only you can see this"
ephemeral: true
user: "{{user_id}}"
flows/on_interaction.ygtc
name: handle_interaction
version: "1.0"
nodes:
- id: route_action
type: branch
config:
conditions:
- expression: "action_id == 'help_clicked'"
to: show_help
- expression: "action_id == 'create_ticket'"
to: create_ticket
default: unknown_action
- id: show_help
type: reply
config:
message: "Here's how I can help..."
triggers:
- type: block_action
target: route_action
- id: handle_select
type: branch
config:
conditions:
- expression: "selected_value == 'technical'"
to: technical_flow
- expression: "selected_value == 'billing'"
to: billing_flow
  1. app 設定の Slash Commands に移動する
  2. command を作成する(例: /support
  3. Request URL を webhook に設定する

flow では次のように処理します:

flows/slash_command.ygtc
name: slash_command
version: "1.0"
nodes:
- id: handle_command
type: reply
config:
message: "Support bot at your service!"
response_type: in_channel # or "ephemeral"
triggers:
- type: slash_command
command: "/support"
target: handle_command
greentic.demo.yaml
tenants:
demo:
teams:
support:
channels:
slack:
provider: messaging-slack
config:
channel_id: "C1234567890"
tenants:
demo:
teams:
support:
channels:
slack-general:
provider: messaging-slack
config:
channel_id: "C1234567890"
slack-vip:
provider: messaging-slack
config:
channel_id: "C0987654321"
  1. Event Subscriptions を確認する:

    • Request URL が正しいことを確認する
    • event が有効になっていることを確認する
    • bot が正しい event を購読していることを確認する
  2. Bot の権限を確認する:

    • scope を追加した後は app を再インストールする
    • bot が channel に参加していることを確認する
  3. Webhook をテストする:

    Terminal window
    curl https://your-domain.com/v1/messaging/ingress/messaging-slack/demo/default

bot token が無効か期限切れです。OAuth & Permissions から新しい token を取得してください。

  • channel ID が正しいことを確認する
  • bot が channel に追加されていることを確認する
  • channel が archived されていないことを確認する

Slack の rate limit は method ごとに異なります。適切に処理してください:

- id: reply
type: reply
config:
message: "Response"
retry_on_rate_limit: true
max_retries: 3

Greentic は次を自動検証します:

  • Request timestamp
  • signing secret を使った signature
  • token verification