Lewati ke konten

Slack

Provider Slack mengintegrasikan digital worker Anda dengan workspace Slack. Provider ini mendukung:

  • Direct message (DM)
  • Pesan channel
  • Mention app
  • Komponen interaktif (tombol, menu)
  • Pesan kaya Block Kit
  • Slash command
  • Balasan thread
  • Sebuah workspace Slack
  • Akses admin untuk membuat app Slack
  1. Buat pasangan token konfigurasi Slack

    Buka api.slack.com/apps dan buat pasangan token konfigurasi app. Salin kedua nilai:

    • Token akses konfigurasi (xoxe.xoxp-...)
    • Token refresh konfigurasi (xoxe-1-...)
  2. Konfigurasikan provider

    answers.json
    {
    "setup_answers": {
    "messaging-slack": {
    "slack_configuration_access_token": "xoxe.xoxp-xxx",
    "slack_configuration_refresh_token": "xoxe-1-xxx"
    }
    }
    }
  3. Jalankan setup

    Terminal window
    gtc setup --answers answers.json ./my-bundle
  4. Klik Add to Slack

    Setup mendaftarkan atau memperbarui app Slack dan menampilkan aksi Add to Slack. Buka URL otorisasi Slack yang dibuat, pilih workspace, tinjau scope yang diminta, lalu setujui instalasi.

    Saat redirect OAuth kembali ke setup, Greentic menyimpan Slack app id, client id, client secret, dan jawaban OAuth runtime untuk tenant. Jika callback tidak ditangani otomatis, jalankan gtc setup --answers answers.json ./my-bundle lagi setelah menyetujui instalasi.

  5. Tambahkan app di Slack

    Buka Slack dan pastikan app sudah terinstal di workspace. Untuk percakapan channel, tambahkan app ke channel tempat worker harus merespons. Anda dapat melakukannya dari pengaturan integrasi channel atau dengan menyebut/mengundang app di channel.

  6. Mulai atau mulai ulang runtime

    Terminal window
    gtc start ./my-bundle

    Saat startup, slack_app_id yang tersimpan dan pasangan token konfigurasi digunakan untuk memperbarui manifest app Slack dengan URL webhook saat ini.

  7. Uji channel

    Kirim direct message ke app atau mention app di channel Slack tempat Anda menambahkannya. Event channel hanya masuk untuk channel tempat app menjadi anggota dan scope terpasang mengizinkan event tersebut.

OpsiWajibDeskripsi
slack_configuration_access_tokenYaToken konfigurasi Slack berumur pendek yang digunakan untuk pembaruan manifest app
slack_configuration_refresh_tokenYaToken refresh yang digunakan untuk merotasi token akses konfigurasi
slack_app_idDibuatSlack app id yang dibuat atau dikembalikan oleh setup
slack_client_idDibuatSlack OAuth client id yang dikembalikan oleh pendaftaran app
client_secretSecret dibuatSlack OAuth client secret yang dikembalikan oleh pendaftaran app
- id: reply
type: reply
config:
message: "Hello! How can I help you?"

Slack menggunakan format mrkdwn:

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

Gunakan Block Kit milik Slack untuk layout kaya:

- 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"

Balas dalam thread:

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

API file Slack berubah dari waktu ke waktu. Gunakan ini hanya ketika pack messaging-slack yang terpasang mengekspos dukungan file untuk versi Anda; jika tidak, kirim tautan atau gunakan alur upload eksternal Slack saat ini.

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

Pesan yang hanya terlihat oleh satu pengguna:

- 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. Buka Slash Commands di pengaturan app Anda
  2. Buat command (misalnya, /support)
  3. Atur Request URL ke webhook Anda

Tangani di flow Anda:

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. Verifikasi Event Subscriptions:

    • Periksa apakah Request URL benar
    • Pastikan event diaktifkan
    • Verifikasi bot berlangganan ke event yang benar
  2. Periksa Izin Bot:

    • Install ulang app setelah menambahkan scope
    • Pastikan bot ada di channel
  3. Uji Webhook:

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

Bot token Anda tidak valid atau sudah kedaluwarsa. Ambil token baru dari OAuth & Permissions.

  • Verifikasi channel ID sudah benar
  • Pastikan bot ditambahkan ke channel
  • Periksa apakah channel tidak diarsipkan

Rate limit Slack bervariasi per metode. Tangani dengan baik:

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

Greentic secara otomatis memvalidasi:

  • Timestamp request
  • Signature menggunakan signing secret
  • Verifikasi token