Slack & Discord Automation
Slack và Discord là communication hubs. Bài này dạy bạn build bots và automations cho team communication.
🎯 Mục tiêu bài học
🎯 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?
💬 Slack Integration
1. Slack Integration
1.1 Setup Slack App
- Go to api.slack.com/apps → Create New App
- From scratch → Name: "n8n Bot", Workspace: [select]
- OAuth & Permissions → Add scopes:
chat:write— Send messageschat:write.public— Post to any channelchannels:history— Read messagesusers:read— Get user inforeactions:write— Add reactions
- Install to workspace → Copy Bot User OAuth Token
- In n8n: Add Slack credentials with token
1.2 Send Messages
1Slack node:2- Operation: Send Message3- Channel: #general (or channel ID)4- Text: "Hello from n8n! 🤖"Rich message with blocks:
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
1Slack node:2- Operation: Send Message3- Channel: {{ $json.channel }}4- Thread TS: {{ $json.ts }} ← Reply in thread!5- Text: "Thanks! Working on it."1.4 React to Messages
1Slack node:2- Operation: Add Reaction3- Channel: {{ $json.channel }}4- Timestamp: {{ $json.ts }}5- Emoji: "white_check_mark" ← ✅1.5 Slash Commands
Setup /report command:
- Slack App → Slash Commands → Create New
- Command:
/report - Request URL:
https://your-n8n.com/webhook/slack-report - Description: "Generate team report"
1Webhook (/webhook/slack-report)2→ Parse slash command data3→ Generate report (AI/DB)4→ Slack Send Message (respond)Slash command data:
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ì?
🎮 Discord Integration
2. Discord Integration
2.1 Setup Discord Bot
- Go to discord.com/developers → New Application
- Bot tab → Add Bot → Copy Token
- OAuth2 → URL Generator:
- Scopes:
bot - Permissions: Send Messages, Read Message History
- Scopes:
- Copy invite URL → add bot to server
2.2 Discord via Webhook (Simpler)
- Server Settings → Integrations → Webhooks
- New Webhook → Copy URL
- No bot needed! Direct HTTP POST
1HTTP Request node:2- Method: POST3- URL: https://discord.com/api/webhooks/xxx/yyy4- 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
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?
📡 Communication Workflow Patterns
3. Communication Workflow Patterns
3.1 Daily Standup Bot
1Schedule (9 AM, Mon-Fri)2→ Slack: Post to #standup3 "Good morning! 🌅 What are you working on today?"4→ Wait 2 hours5→ Slack: Get replies6→ AI: Summarize standups7→ Slack: Post summary to #team-leads3.2 Incident Alert System
1Webhook (monitoring alert)2→ Classify severity (IF)3 → P0 (critical):4 → Slack #incidents (with @channel)5 → Discord #alerts6 → PagerDuty (if integrated)7 → P1 (high):8 → Slack #incidents (no @channel)9 → P2 (medium):10 → Slack #monitoring (threaded)3.3 Welcome New Members
1Slack Trigger (new member joins #general)2→ Slack DM to new member:3 "Welcome! 👋 Here's what you need to know:4 📚 #handbook — Company docs5 💬 #random — General chat6 🆘 #help — Get help"7→ Slack #team: "Welcome {name}! 🎉"3.4 Meeting Notes Distribution
1Webhook (meeting notes from Otter.ai / Notion)2→ AI: Extract action items3→ Loop each action item4 → Slack: DM to assigned person5→ Slack #meeting-notes: Full summary6→ Notion: Create task pages3.5 Cross-Platform Sync
1Slack message in #updates2→ Format for Discord3→ Discord Webhook (post to #updates)4 5And reverse:6Discord message → Webhook → Format → Slack postCheckpoint
Mô tả workflow Daily Standup Bot: gồm những bước nào và dùng AI ở đâu?
⚡ Advanced Slack Features
4. Advanced Slack Features
4.1 Interactive Messages
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
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
1Slack node:2- Operation: Send Message3- Schedule: post_at (Unix timestamp)4 5Useful for: Reminders, scheduled announcements5. Hands-on Lab
Lab 1: Daily Report Bot
Build Slack bot gửi daily report:
- Schedule (9 AM)
- Google Sheets — Get today's data
- Format — Create Slack Block Kit message
- Slack — Post to #reports with formatting
Lab 2: Approval Workflow
- Webhook (new expense request)
- Slack — Send interactive message to manager
- Webhook (button click callback)
- IF approved → Process → Notify requester
- IF rejected → Notify requester with reason
Lab 3: Multi-Platform Alert
- Webhook (alert from monitoring)
- Classify severity
- Slack — Post with appropriate urgency
- Discord — Mirror alert
- Email — If P0, email on-call engineer
📝 Quiz
-
Slack Block Kit dùng để?
- Chặn tin nhắn spam
- Tạo rich formatted messages với buttons, fields
- Block users
- Encrypt messages
-
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
-
Slash command trong Slack cần gì?
- Chỉ cần n8n
- Premium Slack plan
- Slack App + Webhook URL trong n8n
- Discord integration
🎯 Key Takeaways
- Slack — Messages, threads, reactions, slash commands, interactive buttons
- Discord — Webhooks (simple) hoặc Bot (full-featured)
- Block Kit — Rich Slack messages với sections, fields, buttons
- Patterns — Standup bot, alert system, welcome messages, meeting notes
- 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!
