YouTube新视频→自动发布链接到Slack
中级
这是一个Social Media, Multimodal AI领域的自动化工作流,包含 6 个节点。主要使用 Code, Cron, Slack, HttpRequest 等节点。 将YouTube视频通知自动化发送到Slack
前置要求
- •Slack Bot Token 或 Webhook URL
- •可能需要目标 API 的认证凭证
使用的节点 (6)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"name": "YouTube 新视频 → 自动发布链接到 Slack",
"nodes": [
{
"id": "setup-instructions",
"name": "设置说明",
"type": "n8n-nodes-base.stickyNote",
"position": [
200,
80
],
"parameters": {
"width": 280,
"height": 220,
"content": "🎬 **需要设置:**"
},
"typeVersion": 1
},
{
"id": "youtube-check-trigger",
"name": "每 30 分钟检查一次",
"type": "n8n-nodes-base.cron",
"position": [
200,
300
],
"parameters": {
"rule": {
"interval": [
{
"field": "cronExpression",
"expression": "*/30 * * * *"
}
]
}
},
"typeVersion": 1
},
{
"id": "fetch-youtube-rss",
"name": "获取 YouTube RSS",
"type": "n8n-nodes-base.httpRequest",
"position": [
400,
300
],
"parameters": {
"url": "https://www.youtube.com/feeds/videos.xml?channel_id=YOUR_CHANNEL_ID_HERE",
"options": {}
},
"typeVersion": 4.1
},
{
"id": "parse-rss-data",
"name": "解析 RSS 并检查新视频",
"type": "n8n-nodes-base.code",
"position": [
600,
300
],
"parameters": {
"jsCode": "// Parse YouTube RSS feed and extract video data\nconst rssData = $input.first().json;\nconst xmlContent = rssData;\n\n// Simple XML parsing for YouTube RSS\nconst entries = [];\nconst entryMatches = xmlContent.matchAll(/<entry[\\s\\S]*?<\\/entry>/g);\n\nfor (const match of entryMatches) {\n const entry = match[0];\n \n // Extract video data using regex\n const titleMatch = entry.match(/<title><!\\[CDATA\\[([^\\]]+)\\]\\]><\\/title>/);\n const linkMatch = entry.match(/<link rel=\"alternate\" href=\"([^\"]+)\"\\/?>/);\n const publishedMatch = entry.match(/<published>([^<]+)<\\/published>/);\n const descriptionMatch = entry.match(/<media:description><!\\[CDATA\\[([^\\]]+)\\]\\]><\\/media:description>/);\n const videoIdMatch = entry.match(/watch\\?v=([^&]+)/);\n \n if (titleMatch && linkMatch && publishedMatch) {\n entries.push({\n title: titleMatch[1],\n link: linkMatch[1],\n published: publishedMatch[1],\n description: descriptionMatch ? descriptionMatch[1].substring(0, 200) + '...' : '',\n video_id: videoIdMatch ? videoIdMatch[1] : '',\n published_timestamp: new Date(publishedMatch[1]).getTime()\n });\n }\n}\n\n// Sort by publication date (newest first)\nentries.sort((a, b) => b.published_timestamp - a.published_timestamp);\n\n// Get the most recent video\nconst latestVideo = entries[0];\n\nif (!latestVideo) {\n console.log('No videos found in RSS feed');\n return null;\n}\n\n// Check if this video is new (published within last 2 hours)\nconst twoHoursAgo = Date.now() - (2 * 60 * 60 * 1000);\nconst isNewVideo = latestVideo.published_timestamp > twoHoursAgo;\n\nconst normalizedData = {\n ...latestVideo,\n is_new_video: isNewVideo,\n channel_name: 'Your Channel', // Will be extracted from RSS in real implementation\n formatted_date: new Date(latestVideo.published).toLocaleDateString()\n};\n\nconsole.log('Latest video data:', {\n title: normalizedData.title,\n published: normalizedData.formatted_date,\n is_new: normalizedData.is_new_video\n});\n\n// Only proceed if it's a new video\nif (!isNewVideo) {\n console.log('No new videos to announce');\n return null;\n}\n\nreturn {\n json: normalizedData\n};"
},
"typeVersion": 2
},
{
"id": "format-slack-message",
"name": "格式化Slack消息",
"type": "n8n-nodes-base.code",
"position": [
800,
300
],
"parameters": {
"jsCode": "// Format video announcement for Slack\nconst video = $input.first().json;\n\n// Create rich Slack message\nconst slackMessage = {\n text: `🎬 New Video Alert!`,\n channel: '#general', // Change to your preferred channel\n username: 'YouTube Bot',\n icon_emoji: ':tv:',\n blocks: [\n {\n \"type\": \"section\",\n \"text\": {\n \"type\": \"mrkdwn\",\n \"text\": `🎬 *New Video Published!*\\n\\n*${video.title}*\\n\\n📅 Published: ${video.formatted_date}\\n\\n${video.description}`\n }\n },\n {\n \"type\": \"actions\",\n \"elements\": [\n {\n \"type\": \"button\",\n \"text\": {\n \"type\": \"plain_text\",\n \"text\": \"🎥 Watch Now\",\n \"emoji\": true\n },\n \"url\": video.link,\n \"style\": \"primary\"\n }\n ]\n },\n {\n \"type\": \"context\",\n \"elements\": [\n {\n \"type\": \"mrkdwn\",\n \"text\": `📺 ${video.channel_name} | 🔗 <${video.link}|${video.video_id}>`\n }\n ]\n }\n ]\n};\n\nconsole.log('Formatted Slack message for video:', video.title);\n\nreturn {\n json: slackMessage\n};"
},
"typeVersion": 2
},
{
"id": "post-to-slack",
"name": "发布到 Slack",
"type": "n8n-nodes-base.slack",
"position": [
1000,
300
],
"parameters": {
"text": "={{ $json.text }}",
"channel": "={{ $json.channel }}",
"resource": "message",
"operation": "post",
"otherOptions": {
"blocks": "={{ JSON.stringify($json.blocks) }}",
"username": "={{ $json.username }}",
"icon_emoji": "={{ $json.icon_emoji }}"
},
"authentication": "oAuth2"
},
"typeVersion": 2.1
}
],
"active": true,
"settings": {
"timezone": "UTC"
},
"versionId": "1",
"connections": {
"Fetch YouTube RSS": {
"main": [
[
{
"node": "Parse RSS & Check for New Video",
"type": "main",
"index": 0
}
]
]
},
"Format Slack Message": {
"main": [
[
{
"node": "Post to Slack",
"type": "main",
"index": 0
}
]
]
},
"Check Every 30 Minutes": {
"main": [
[
{
"node": "Fetch YouTube RSS",
"type": "main",
"index": 0
}
]
]
},
"Parse RSS & Check for New Video": {
"main": [
[
{
"node": "Format Slack Message",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 社交媒体, 多模态 AI
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
每日禅语励志名言推送至Slack频道
每日从ZenQuotes获取励志名言并推送到Slack频道
Code
Cron
Slack
+2
5 节点David Olusola
个人效率
比特币和以太坊加密货币下跌警报(Telegram、Slack 和 SMS)
通过 Telegram、Slack 和 SMS 发送比特币和以太坊加密货币下跌警报
If
Code
Slack
+5
8 节点David Olusola
加密货币交易
基于SMS的天气警报(OpenWeather + Twilio)
基于SMS的天气警报(OpenWeather + Twilio)
If
Code
Cron
+3
9 节点David Olusola
个人效率
每周LinkedIn联系人同步与分析(使用Apify和Google Sheets)
每周LinkedIn联系人同步与分析(使用Apify和Google Sheets)
If
Code
Cron
+4
13 节点David Olusola
潜在客户开发
使用 Gemini AI 和 Blotato 自动发布 WordPress 文章到社交媒体
使用 Gemini AI 和 Blotato 自动发布 WordPress 文章到社交媒体
If
Code
Split Out
+6
11 节点David Olusola
社交媒体
使用Gemini从WordPress生成AI驱动的每周邮件通讯
使用Gemini从WordPress生成AI驱动的每周邮件通讯
If
Code
Email Send
+5
8 节点David Olusola
社交媒体
工作流信息
难度等级
中级
节点数量6
分类2
节点类型5
作者
David Olusola
@dae221I help ambitious businesses eliminate operational bottlenecks and scale faster with AI automation. My clients typically see 40-60% efficiency gains within 90 days. Currently accepting 3 new projects this quarter - david@daexai.com
外部链接
在 n8n.io 查看 →
分享此工作流