Bot Slack yang menganalisis thread dan menyimpan data ke Google Spreadsheet menggunakan Gemini AI.
- 🤖 Analisis otomatis thread Slack menggunakan Gemini AI
- 📊 Menyimpan data ke Google Spreadsheet secara otomatis
- 🔍 Mengekstrak type, description, sentiment, dan urgency dari thread
- 📝 Mendukung perintah sederhana dalam Bahasa Indonesia
- 🔗 Menyimpan permalink thread untuk referensi
# Clone atau download project
# Install dependencies
pip install -r requirements.txt- Buat aplikasi Slack di https://api.slack.com/apps
- Aktifkan Event Subscriptions dan subscribe ke event
app_mention - Tambahkan Bot Token Scopes:
app_mentions:readchat:writechannels:historygroups:historygroups:readim:historympim:historyusers:readusers:read.emailchannels:joinchannels:read
- Install aplikasi ke workspace Slack Anda
- Buat project di Google Cloud Console
- Aktifkan Google Sheets API
- Buat Service Account dan download file JSON credentials
- Buat Google Spreadsheet baru
- Share spreadsheet dengan email service account (berikan akses Edit)
- Dapatkan API key dari Google AI Studio
- Simpan API key untuk konfigurasi
Buat file .env dengan konfigurasi berikut:
# Slack Bot Configuration
SLACK_BOT_TOKEN=xoxb-your-bot-token-here
SLACK_SIGNING_SECRET=your-signing-secret-here
SLACK_APP_TOKEN=xapp-your-app-token-here
# Worker Concurrency (optional)
# - Defaults to 5 * CPU cores (min 2, max 32)
# - Override when hosting platform limits parallel threads
THREAD_POOL_MAX_WORKERS=8
# Google Sheets Configuration
# Option A (recommended for managed hosting): inline JSON credentials
# - For .env files, wrap in single quotes or escape quotes
# - Alternatively, use the Base64 variant below to avoid quoting entirely
GOOGLE_APPLICATION_CREDENTIALS_JSON='{"type":"service_account","project_id":"..."}'
# Option A2 (quote-safe): Base64-encoded JSON
# echo -n '{"type":"service_account",...}' | base64
GOOGLE_APPLICATION_CREDENTIALS_JSON_B64=eyJ0eXBlIjoic2VydmljZV9hY2NvdW50IiwiLi4u
# Option B (legacy): absolute path to a mounted credentials file
GOOGLE_SHEETS_CREDENTIALS_FILES=/path/to/your/credentials.json
SPREADSHEET_ID=your-spreadsheet-id-here
SHEET_NAME=Thread Analysis
> **Tips:** Platform seperti Railway mendukung nilai environment multiline. Gunakan menu *Bulk Edit* atau tempel langsung JSON service account ke `GOOGLE_APPLICATION_CREDENTIALS_JSON`, atau pakai `GOOGLE_APPLICATION_CREDENTIALS_JSON_B64` jika ingin paste satu baris Base64.
# Gemini AI Configuration
GEMINI_API_KEY=your-gemini-api-key-here
### 6. Konfigurasi ngrok (Opsional untuk Development)
Untuk development lokal, bot akan otomatis menggunakan ngrok:
1. Download dan install [ngrok](https://ngrok.com/download)
2. Daftar akun ngrok dan dapatkan auth token
3. Tambahkan `NGROK_AUTH_TOKEN` ke file `.env`
4. Set `USE_NGROK=true` di file `.env`
## Cara Menjalankan
### Development
```bash
# Bot akan otomatis start ngrok tunnel dan menampilkan URL
python apps.py
# Output akan menampilkan:
# 🌐 ngrok tunnel started: https://abc123.ngrok.io
# 📝 Update your Slack app Request URL to: https://abc123.ngrok.io/slack/eventsCatatan: Saat running development, copy URL ngrok yang ditampilkan dan update di Slack App settings > Event Subscriptions > Request URL
gunicorn -w 4 -b 0.0.0.0:3000 apps:app-
Analisis Thread:
@botSpread masukkan ke pqfatau
@botSpread masukkan ke spreadsheet -
Help:
@botSpread help
- Panggil bot dalam sebuah thread Slack
- Gunakan perintah
@botSpread masukkan ke pqf - Bot akan menganalisis thread dan menyimpan data ke spreadsheet
Bot akan menyimpan data berikut ke Google Spreadsheet:
- Timestamp: Waktu thread dibuat
- Type: Kategori thread (Question, Discussion, Bug Report, dll.)
- Description: Deskripsi singkat thread
- Link: Permalink ke thread Slack
- User: Pembuat thread
- Channel: Channel tempat thread berada
- Sentiment: Sentiment keseluruhan (Positive, Negative, Neutral)
- Urgency: Level urgensi (Low, Medium, High)
- Participants: Jumlah peserta dalam thread
- Summary: Ringkasan detail diskusi
- Created At: Waktu data disimpan
├── apps.py # Aplikasi utama Flask
├── slack_bot.py # Integrasi Slack API
├── gemini_hook.py # Integrasi Gemini AI
├── spreadsheet.py # Integrasi Google Sheets
├── requirements.txt # Dependencies Python
├── .env # Environment variables
└── README.md # Dokumentasi
- Pastikan file
.envada dan berisi token yang benar - Verifikasi token di Slack App settings
- Pastikan service account memiliki akses Edit ke spreadsheet
- Verifikasi file credentials JSON sudah benar
- Pastikan API key Gemini sudah benar
- Periksa quota API key di Google AI Studio
- Periksa Event Subscriptions di Slack App
- Pastikan bot sudah diinvite ke channel
- Verifikasi webhook URL sudah benar
- Deploy aplikasi ke platform pilihan
- Set environment variables
- Tempel seluruh isi file service account ke variabel
GOOGLE_APPLICATION_CREDENTIALS_JSON(gunakan single quotes saat di.envlokal) - Atau encode ke Base64 dan set
GOOGLE_APPLICATION_CREDENTIALS_JSON_B64 - (Opsional) Jika tetap memakai file, upload ke storage/volume dan set
GOOGLE_SHEETS_CREDENTIALS_FILES
- Tempel seluruh isi file service account ke variabel
- Update Request URL di Slack App settings
- Pastikan webhook endpoint dapat diakses publik
# Ngrok akan otomatis start saat menjalankan apps.py
python apps.py
# Copy URL yang ditampilkan dan update di Slack App settings
# Contoh: https://abc123.ngrok.io/slack/eventsSilakan buat issue atau pull request untuk perbaikan dan penambahan fitur.
MIT License