MinAI - Về trang chủ
Hướng dẫn
7/1335 phút
Đang tải...

Slack & Discord Automation

Tự động hóa team communication với Slack và Discord bots

Slack & Discord Automation

Slack và Discord là communication hubs. Bài này dạy bạn build bots và automations cho team communication.

0

🎯 Mục tiêu bài học

TB5 min

🎯 Mục tiêu

  • Send messages, replies, reactions
  • Build Slack slash commands
  • Discord webhook notifications
  • Team communication workflows

Checkpoint

Tại sao automation cho Slack và Discord lại quan trọng trong làm việc nhóm?

1

💬 Slack Integration

TB5 min

1. Slack Integration

1.1 Setup Slack App

  1. Go to api.slack.com/apps → Create New App
  2. From scratch → Name: "n8n Bot", Workspace: [select]
  3. OAuth & Permissions → Add scopes:
    • chat:write — Send messages
    • chat:write.public — Post to any channel
    • channels:history — Read messages
    • users:read — Get user info
    • reactions:write — Add reactions
  4. Install to workspace → Copy Bot User OAuth Token
  5. In n8n: Add Slack credentials with token

1.2 Send Messages

Ví dụ
1Slack node:
2- Operation: Send Message
3- Channel: #general (or channel ID)
4- Text: "Hello from n8n! 🤖"

Rich message with blocks:

JSON
1{
2 "blocks": [
3 {
4 "type": "header",
5 "text": {"type": "plain_text", "text": "📊 Daily Report"}
6 },
7 {
8 "type": "section",
9 "fields": [
10 {"type": "mrkdwn", "text": "*Revenue:* $12,345"},
11 {"type": "mrkdwn", "text": "*Orders:* 156"},
12 {"type": "mrkdwn", "text": "*Conversion:* 3.2%"},
13 {"type": "mrkdwn", "text": "*Status:* ✅ On track"}
14 ]
15 },
16 {
17 "type": "actions",
18 "elements": [
19 {
20 "type": "button",
21 "text": {"type": "plain_text", "text": "View Dashboard"},
22 "url": "https://dashboard.example.com"
23 }
24 ]
25 }
26 ]
27}

1.3 Reply to Thread

Ví dụ
1Slack node:
2- Operation: Send Message
3- Channel: {{ $json.channel }}
4- Thread TS: {{ $json.ts }} ← Reply in thread!
5- Text: "Thanks! Working on it."

1.4 React to Messages

Ví dụ
1Slack node:
2- Operation: Add Reaction
3- Channel: {{ $json.channel }}
4- Timestamp: {{ $json.ts }}
5- Emoji: "white_check_mark" ← ✅

1.5 Slash Commands

Setup /report command:

  1. Slack App → Slash Commands → Create New
  2. Command: /report
  3. Request URL: https://your-n8n.com/webhook/slack-report
  4. Description: "Generate team report"
Ví dụ
1Webhook (/webhook/slack-report)
2→ Parse slash command data
3→ Generate report (AI/DB)
4→ Slack Send Message (respond)

Slash command data:

JSON
1{
2 "command": "/report",
3 "text": "weekly sales",
4 "user_id": "U12345",
5 "channel_id": "C12345"
6}

Checkpoint

Slash command trong Slack cần setup những gì? Webhook URL đóng vai trò gì?

2

🎮 Discord Integration

TB5 min

2. Discord Integration

2.1 Setup Discord Bot

  1. Go to discord.com/developers → New Application
  2. Bot tab → Add Bot → Copy Token
  3. OAuth2 → URL Generator:
    • Scopes: bot
    • Permissions: Send Messages, Read Message History
  4. Copy invite URL → add bot to server

2.2 Discord via Webhook (Simpler)

  1. Server Settings → Integrations → Webhooks
  2. New Webhook → Copy URL
  3. No bot needed! Direct HTTP POST
Ví dụ
1HTTP Request node:
2- Method: POST
3- URL: https://discord.com/api/webhooks/xxx/yyy
4- Body:
5{
6 "content": "🚀 New deployment: v2.1.0",
7 "embeds": [
8 {
9 "title": "Deployment Details",
10 "color": 5763719,
11 "fields": [
12 {"name": "Version", "value": "2.1.0", "inline": true},
13 {"name": "Environment", "value": "Production", "inline": true},
14 {"name": "Status", "value": "✅ Success", "inline": true}
15 ]
16 }
17 ]
18}

2.3 Discord Embeds

JSON
1{
2 "embeds": [{
3 "title": "📊 Weekly Report",
4 "description": "Summary for week 3, Jan 2026",
5 "color": 3447003,
6 "fields": [
7 {"name": "Revenue", "value": "$45,678", "inline": true},
8 {"name": "Users", "value": "1,234", "inline": true}
9 ],
10 "footer": {"text": "Generated by n8n Bot"},
11 "timestamp": "2026-01-20T09:00:00.000Z"
12 }]
13}

Checkpoint

Discord Webhook khác Discord Bot ở điểm nào? Khi nào nên dùng Webhook và khi nào nên dùng Bot?

3

📡 Communication Workflow Patterns

TB5 min

3. Communication Workflow Patterns

3.1 Daily Standup Bot

Ví dụ
1Schedule (9 AM, Mon-Fri)
2→ Slack: Post to #standup
3 "Good morning! 🌅 What are you working on today?"
4→ Wait 2 hours
5→ Slack: Get replies
6→ AI: Summarize standups
7→ Slack: Post summary to #team-leads

3.2 Incident Alert System

Ví dụ
1Webhook (monitoring alert)
2→ Classify severity (IF)
3 → P0 (critical):
4 → Slack #incidents (with @channel)
5 → Discord #alerts
6 → PagerDuty (if integrated)
7 → P1 (high):
8 → Slack #incidents (no @channel)
9 → P2 (medium):
10 → Slack #monitoring (threaded)

3.3 Welcome New Members

Ví dụ
1Slack Trigger (new member joins #general)
2→ Slack DM to new member:
3 "Welcome! 👋 Here's what you need to know:
4 📚 #handbook — Company docs
5 💬 #random — General chat
6 🆘 #help — Get help"
7→ Slack #team: "Welcome {name}! 🎉"

3.4 Meeting Notes Distribution

Ví dụ
1Webhook (meeting notes from Otter.ai / Notion)
2→ AI: Extract action items
3→ Loop each action item
4 → Slack: DM to assigned person
5→ Slack #meeting-notes: Full summary
6→ Notion: Create task pages

3.5 Cross-Platform Sync

Ví dụ
1Slack message in #updates
2→ Format for Discord
3→ Discord Webhook (post to #updates)
4
5And reverse:
6Discord message → Webhook → Format → Slack post

Checkpoint

Mô tả workflow Daily Standup Bot: gồm những bước nào và dùng AI ở đâu?

4

⚡ Advanced Slack Features

TB5 min

4. Advanced Slack Features

4.1 Interactive Messages

JSON
1{
2 "blocks": [
3 {
4 "type": "section",
5 "text": {"type": "mrkdwn", "text": "New lead: *John Doe* from Company X"},
6 "accessory": {
7 "type": "button",
8 "text": {"type": "plain_text", "text": "Accept"},
9 "action_id": "accept_lead",
10 "value": "lead_123"
11 }
12 }
13 ]
14}

When button clicked → Slack sends payload to webhook → n8n processes action.

4.2 Conditional Formatting

Ví dụ
1Dựa vào data, thay đổi message format:
2
3IF revenue > target:
4 color = "good" (green)
5 emoji = "🟢"
6ELSE:
7 color = "danger" (red)
8 emoji = "🔴"

4.3 Scheduled Messages

Ví dụ
1Slack node:
2- Operation: Send Message
3- Schedule: post_at (Unix timestamp)
4
5Useful for: Reminders, scheduled announcements

5. Hands-on Lab

Lab 1: Daily Report Bot

Build Slack bot gửi daily report:

  1. Schedule (9 AM)
  2. Google Sheets — Get today's data
  3. Format — Create Slack Block Kit message
  4. Slack — Post to #reports with formatting

Lab 2: Approval Workflow

  1. Webhook (new expense request)
  2. Slack — Send interactive message to manager
  3. Webhook (button click callback)
  4. IF approved → Process → Notify requester
  5. IF rejected → Notify requester with reason

Lab 3: Multi-Platform Alert

  1. Webhook (alert from monitoring)
  2. Classify severity
  3. Slack — Post with appropriate urgency
  4. Discord — Mirror alert
  5. Email — If P0, email on-call engineer

📝 Quiz

  1. Slack Block Kit dùng để?

    • Chặn tin nhắn spam
    • Tạo rich formatted messages với buttons, fields
    • Block users
    • Encrypt messages
  2. Discord Webhook khác Discord Bot ở điểm?

    • Webhook đơn giản hơn, chỉ gửi messages, không cần bot setup
    • Webhook mạnh hơn
    • Bot miễn phí, Webhook trả phí
    • Không khác nhau
  3. Slash command trong Slack cần gì?

    • Chỉ cần n8n
    • Premium Slack plan
    • Slack App + Webhook URL trong n8n
    • Discord integration

🎯 Key Takeaways

  1. Slack — Messages, threads, reactions, slash commands, interactive buttons
  2. Discord — Webhooks (simple) hoặc Bot (full-featured)
  3. Block Kit — Rich Slack messages với sections, fields, buttons
  4. Patterns — Standup bot, alert system, welcome messages, meeting notes
  5. Cross-platform — Sync messages giữa Slack ↔ Discord

Checkpoint

Slack Block Kit cho phép tạo những gì? Interactive messages hoạt động ra sao với n8n?


🚀 Bài tiếp theo

HTTP Requests & APIs — Kết nối với bất kỳ API nào!